Class: Textmagic::REST::CustomFields

Inherits:
ListResource show all
Defined in:
lib/textmagic-ruby/rest/custom_fields.rb

Instance Method Summary collapse

Methods inherited from ListResource

#initialize, #inspect

Methods included from Utils

#key_map, #resource, #to_camel_case, #to_underscore_case

Constructor Details

This class inherits a constructor from Textmagic::REST::ListResource

Instance Method Details

#create(params = {}) ⇒ Object

Create new CustomField. Returns CustomField object contains id and link to new CustomField.

The following params keys are supported:

name

Name of custom field. Required.

Example:

@custom_field = client.custom_fields.create {:name => 'Birthday'}


31
32
33
# File 'lib/textmagic-ruby/rest/custom_fields.rb', line 31

def create(params={})
  super params
end

#delete(uid) ⇒ Object

Delete CustomField by ID. Returns true if success.

uid

CustomField ID. Required.

Example:

r = client.custom_fields.delete 987


83
84
85
# File 'lib/textmagic-ruby/rest/custom_fields.rb', line 83

def delete(uid)
  super uid
end

#get(uid) ⇒ Object

Get CustomField by ID. Returns CustomField object.

uid

Custom Field ID. Required.

Example:

@custom_field = client.custom_fields.get 987


15
16
17
# File 'lib/textmagic-ruby/rest/custom_fields.rb', line 15

def get(uid)
  super uid
end

#list(params = {}) ⇒ Object

Get all user custom fields. Returns PaginateResource object, contains array of CustomField objects.

The following params keys are supported:

page

Fetch specified results page. Defaults 1

limit

How many results on page. Defaults 10

Example:

@custom_fields = client.custom_fields.list


49
50
51
52
53
54
# File 'lib/textmagic-ruby/rest/custom_fields.rb', line 49

def list(params={})
  [:search, 'search'].each do |search|
    params.delete search
  end
  super params
end

#update(uid, params = {}) ⇒ Object

Updates the existing CustomField for the given unique id. Returns CustomField object contains id and link to updated CustomField.

uid

Custom field ID. Required.

The following params keys are supported:

name

Name of custom field. Required.

Example:

@custom_field = client.custom_fields.update 123, {:name => 'Updated'}


70
71
72
# File 'lib/textmagic-ruby/rest/custom_fields.rb', line 70

def update(uid, params={})
  super uid, params
end

#update_value(uid, params = {}) ⇒ Object

Updates contact’s custom field value. Returns Contact object contains id and link to updated Contact.

uid

Custom field ID. Required.

The following params keys are supported:

contact_id

The unique id of the Contact to update value. Required.

value

Value of CustomField. Required.

Example:

@custom_field = client.custom_fields.update 123, {:name => 'Updated'}


103
104
105
106
# File 'lib/textmagic-ruby/rest/custom_fields.rb', line 103

def update_value(uid, params={})
  response = @client.put("#{@path}/#{uid}/update", params)
  Textmagic::REST::Contact.new @client, @path, response
end