module VLC360::APIResource::ClassMethods

Attributes

rekey_attributes[RW]

Public Instance Methods

client() click to toggle source
# File lib/vlc360/api_resource.rb, line 18
def client
  VLC360.client
end
rekey_attribute(attr, callable) click to toggle source
# File lib/vlc360/api_resource.rb, line 24
def rekey_attribute(attr, callable)
  (@rekey_attributes ||= {})[attr] = callable
end

Private Instance Methods

initialize_from_response(response) click to toggle source
# File lib/vlc360/api_resource.rb, line 30
def initialize_from_response(response)
  data = response.parsed_response

  # List and Search always return an Array even though it may be empty.
  if data.is_a? Array
    data.map { |element| new(element.deep_rekey { |k| k.underscore.to_sym }) }

  # Find and Save returns a Hash with a status associated
  elsif data.is_a? Hash
    resource = new(data['data'].deep_rekey { |k| k.underscore.to_sym })
    if data['status'] == 'error'
      resource.errors << data['message']
    end
    resource
  end
end