module AirbnbApi::Resource

Public Class Methods

new(attributes) click to toggle source
# File lib/airbnb_api/resource.rb, line 3
def initialize(attributes)
  self.attributes = self.class.root_element ? attributes.dig(self.class.root_element) : attributes
end

Private Instance Methods

attributes=(attributes) click to toggle source
# File lib/airbnb_api/resource.rb, line 9
def attributes=(attributes)
  @attributes = attributes

  attributes.each do |attribute, value|
    if self.class.many && self.class.many.has_key?(attribute.to_sym)
      items = value.map do |data|
        self.class.many[attribute.to_sym].new(data)
      end
      send(attribute.to_s + '=', items)
    elsif respond_to?(writer = attribute.to_s + '=')
      send(writer, value)
    else
      # self.class.logger.warn "`#{attribute}' is not a listed attribute for #{self.class}"
    end
  end
end