Class: ChartMogul::Contact

Inherits:
APIResource show all
Includes:
API::Actions::Create, API::Actions::Custom, API::Actions::Destroy, API::Actions::Retrieve, API::Actions::Update
Defined in:
lib/chartmogul/contact.rb

Constant Summary

Constants inherited from APIResource

APIResource::BACKOFF_FACTOR, APIResource::INTERVAL, APIResource::INTERVAL_RANDOMNESS, APIResource::MAX_INTERVAL, APIResource::RETRY_EXCEPTIONS, APIResource::RETRY_STATUSES, APIResource::THREAD_CONNECTION_KEY

Class Method Summary collapse

Instance Method Summary collapse

Methods included from API::Actions::Update

included, #update!

Methods included from API::Actions::Retrieve

included

Methods included from API::Actions::Destroy

#destroy!, included

Methods included from API::Actions::Custom

#custom!, #custom_without_assign!, included

Methods included from API::Actions::Create

#create!, included

Methods inherited from APIResource

connection, handle_other_error, handle_request_error, handling_errors, immutable_keys, set_immutable_keys, set_resource_name, set_resource_path, set_resource_root_key

Methods inherited from Object

#allowed_for_write?, #assign_all_attributes, #assign_writeable_attributes, attributes, define_private_writer, define_reader, define_writer, #initialize, #instance_attributes, new_from_json, readonly_attr, #serialized_value_for_attr, writeable_attr, writeable_attributes

Constructor Details

This class inherits a constructor from ChartMogul::Object

Class Method Details

.all(options = {}) ⇒ Object



31
32
33
# File 'lib/chartmogul/contact.rb', line 31

def self.all(options = {})
  Contacts.all(options)
end

.merge!(into_uuid:, from_uuid:) ⇒ Object



35
36
37
38
# File 'lib/chartmogul/contact.rb', line 35

def self.merge!(into_uuid:, from_uuid:)
  custom!(:post, "/v1/contacts/#{into_uuid}/merge/#{from_uuid}")
  true
end

Instance Method Details

#serialize_for_writeObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chartmogul/contact.rb', line 40

def serialize_for_write
  super.tap do |attributes|
    attributes.clone.each do |attribute_name, attribute_value|
      if attribute_name == :custom && attribute_value.is_a?(Hash)
        payload = attribute_value.each_with_object([]) do |custom_value, arr|
          key, value = custom_value
          arr << { key: key, value: value }
        end
        attributes[:custom] = payload
      else
        attributes[attribute_name] = attribute_value
      end
    end
  end
end