Module: IContact::Model::ClassMethods
- Defined in:
- lib/i_contact/model.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #deserialize_attributes(attribute_hash) ⇒ Object
- #get(additional_args = {}) ⇒ Object
- #key_attribute(key, type = Integer) ⇒ Object
- #parse(resp) ⇒ Object
- #path(suffix) ⇒ Object
- #resource_name ⇒ Object
Instance Method Details
#connection ⇒ Object
34 35 36 |
# File 'lib/i_contact/model.rb', line 34 def connection IContact.connection end |
#deserialize_attributes(attribute_hash) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/i_contact/model.rb', line 62 def deserialize_attributes(attribute_hash) attribute_hash.inject({}) do |hsh, key_pair| hsh[key_pair[0].underscore] = key_pair[1] hsh end end |
#get(additional_args = {}) ⇒ Object
42 43 44 45 |
# File 'lib/i_contact/model.rb', line 42 def get(additional_args = {}) connection.get path(self.resource_name.pluralize), additional_args end |
#key_attribute(key, type = Integer) ⇒ Object
21 22 23 24 |
# File 'lib/i_contact/model.rb', line 21 def key_attribute(key, type = Integer) self.key_attr = key attribute key, :type => type end |
#parse(resp) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/i_contact/model.rb', line 47 def parse(resp) resp = IContact::Response.new(resp) if !resp.valid? else if resource_resp = resp.parsed_response[resource_name.pluralize] if resource_resp.kind_of?(Array) resource_resp.inject([]) do |arr, attribute_hash| arr << new(deserialize_attributes(attribute_hash)) arr end end end end end |
#path(suffix) ⇒ Object
38 39 40 |
# File 'lib/i_contact/model.rb', line 38 def path(suffix) "#{IContact.url}#{suffix}" end |
#resource_name ⇒ Object
26 27 28 |
# File 'lib/i_contact/model.rb', line 26 def resource_name(name) self.resource_name_attr = name end |