class KlaviyoAPI::Profile

Public Class Methods

collection_path(prefix_options = {}, query_options = {}) click to toggle source
Calls superclass method
# File lib/klaviyo_api/resources/profile.rb, line 13
def collection_path(prefix_options = {}, query_options = {})
  super prefix_options, query_options.deep_merge({ api_key: headers['api-key'] })
end
element_path(id, prefix_options = {}, query_options = {}) click to toggle source
Calls superclass method KlaviyoAPI::Base::element_path
# File lib/klaviyo_api/resources/profile.rb, line 17
def element_path(id, prefix_options = {}, query_options = {})
  super id, prefix_options, query_options.deep_merge({ api_key: headers['api-key'] })
end

Public Instance Methods

create() click to toggle source
# File lib/klaviyo_api/resources/profile.rb, line 26
def create
  raise KlaviyoAPI::InvalidOperation, 'Cannot create Profiles via API.'
end
destroy() click to toggle source
# File lib/klaviyo_api/resources/profile.rb, line 22
def destroy
  raise KlaviyoAPI::InvalidOperation, 'Cannot delete Profiles via API.'
end
update() click to toggle source
# File lib/klaviyo_api/resources/profile.rb, line 30
def update
  run_callbacks :update do
    # This endpoint does not accept JSON bodies. Additionally, if the API key is in the URL, the rest of the attributes
    # MUST be in the URL as well. The other option is to have the API key and all attributes in the body as `key=value` pairs.
    #
    # To reduce friction, as we already need the API key in the URL for other operations, let's just add all the attributes
    # to the URL. Unfortunately we will need to include ALL the attributes, not just the changed ones, because it seems
    # ActiveResource has no support for dirty models. https://github.com/rails/activeresource/issues/308
    path = self.class.element_path(id, prefix_options, attributes)

    connection.put(path, nil, self.class.headers).tap do |response|
      load_attributes_from_response(response)
    end
  end
end

Private Instance Methods

method_missing(method_symbol, *arguments) click to toggle source
Calls superclass method
# File lib/klaviyo_api/resources/profile.rb, line 48
def method_missing(method_symbol, *arguments)
  method_name = method_symbol.to_s

  # Some fields start with a $ (e.g., '$title'). The methods `title`, `title?`
  # and `title=` should act upon the attribute `$title` if present. Otherwise,
  # they should act upon the attribute `title`
  #
  # Not a whole lot we can do if the item contains both `title` and `$title` -
  # this will prioritize the version with the $.
  if attributes.keys.any? { |attribute| attribute == "$#{method_name.sub(/\?|=$/, '')}" }
    method_symbol = "$#{method_name}".to_sym
  end

  super
end