class Brickset::Client

Attributes

token[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/brickset/client.rb, line 16
def initialize(options = {})
  @token = options[:token] if options.key?(:token)
end

Private Instance Methods

call(method, options = {}) click to toggle source
# File lib/brickset/client.rb, line 22
def call(method, options = {})
  response = self.class.post(method, { body: options.merge(default_options) })

  if response.code == 200
    response.body
  else
    raise response.body
  end
end
default_options() click to toggle source
# File lib/brickset/client.rb, line 50
def default_options
  options = { apiKey: Brickset.configuration.api_key }
  options.merge!(userHash: token) if token
  options
end
extract_attributes_from_options(options) click to toggle source
# File lib/brickset/client.rb, line 43
def extract_attributes_from_options(options)
  options.each do |key, value|
    raise KeyError, "Attribute key '#{key}' is not supported" unless respond_to?("#{key}=")
    send("#{key}=", value)
  end
end
handle_update(response) click to toggle source
# File lib/brickset/client.rb, line 32
def handle_update(response)
  content = HappyMapper.parse(response).content

  if content == 'OK'
    true
  else
    errors.add(:base, content)
    false
  end
end