Module: CloudConnect::Client::Fields

Included in:
CloudConnect::Client
Defined in:
lib/cloud_connect/client/fields.rb

Defined Under Namespace

Modules: FieldMethods

Instance Method Summary collapse

Instance Method Details

#create_field(name, options = {}) ⇒ Field

Create a field

Examples:

Create a new Field

@client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
@client.create_field("CUSTOM_SENSOR_TEMP", :field_type => 'integer', :size => 1, :description => "Custom sensor temp in Celsius")

Parameters:

  • name (String)

    Name of the field

  • options (Hash) (defaults to: {})

    A customizable set of options

Returns:

  • (Field)

    Your newly created field

See Also:



55
56
57
# File 'lib/cloud_connect/client/fields.rb', line 55

def create_field(name, options={})
  enhance( post("fields", options.merge({:name => name})), with: FieldMethods )
end

#delete_field(name, options = {}) ⇒ Response

Delete a single field

Examples:

Delete the CUSTOM_SENSOR_TEMP field

@client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
@client.delete_field("CUSTOM_SENSOR_TEMP")

Parameters:

  • name (String)

    Name fo the field

Returns:

  • (Response)

    A response object with status

See Also:



85
86
87
# File 'lib/cloud_connect/client/fields.rb', line 85

def delete_field(name, options={})
  delete("fields/#{name}", options, true)
end

#field(name, options = {}) ⇒ Field

Get a field

Examples:

Get field 0123456789012345

@client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
@client.field("0123456789012345")

Parameters:

  • name (String)

    Name of the field

Returns:

  • (Field)

    The field you requested, if it exists

See Also:



13
14
15
# File 'lib/cloud_connect/client/fields.rb', line 13

def field(name, options={})
  enhance( get("fields/#{name}", options), with: FieldMethods )
end

#fields(options = {}) ⇒ Array Also known as: list_fields

Get fields

Examples:

List all fields

@client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
@client.fields

Returns:

  • (Array)

    A list of all fields

See Also:



36
37
38
# File 'lib/cloud_connect/client/fields.rb', line 36

def fields(options={})
  enhance( get("fields", options), with: FieldMethods )
end

#search_fields(search_term, options = {}) ⇒ Array

Search fields

Examples:

Search for ‘TEMPERATURE’ in the fields

@client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
@client.search_fields

Parameters:

  • search_term (String)

    The term to search for

Returns:

  • (Array)

    A list of fields matching the search term

See Also:



25
26
27
# File 'lib/cloud_connect/client/fields.rb', line 25

def search_fields(search_term, options={})
  enhance( get("fields?q=#{search_term}", options), with: FieldMethods )
end

#update_field(name, options = {}) ⇒ Field

Update an field

Examples:

Update a Field

@client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
@client.update_field("CUSTOM_SENSOR_TEMP", :field_type => 'integer', :size => 1, :description => "Custom sensor temp in Celsius")

Parameters:

  • name (String)

    Name of the field

  • options (Hash) (defaults to: {})

    A customizable set of options

Returns:

  • (Field)

    Your newly updated field

See Also:



73
74
75
# File 'lib/cloud_connect/client/fields.rb', line 73

def update_field(name, options={})
  enhance( put("/fields/#{name}", options.merge({:name => name})), with: FieldMethods )
end