class MyVR::Client

Attributes

access_key[RW]
last_response[RW]

Public Class Methods

new(options = {}) { |self| ... } click to toggle source
# File lib/myvr/client.rb, line 14
def initialize(options = {})
  @last_response = nil
  options.each do |key, value|
    instance_variable_set("@#{ key }", value)
  end
  yield(self) if block_given?
end

Public Instance Methods

base_url(path, params={}) click to toggle source
# File lib/myvr/client.rb, line 48
def base_url(path, params={})
  if ENV["MYVR_TEST"]
    Addressable::URI.new(
      host: 'api.local.myvr.com',
      port: 8000,
      scheme: 'http',
      path: path,
      query_values: params
    )
  else
    Addressable::URI.new(
      host: 'api.myvr.com',
      port: 80,
      scheme: 'https',
      path: path,
      query_values: params
    )
  end
end
get_object(path, params={}) click to toggle source
# File lib/myvr/client.rb, line 31
def get_object(path, params={})
  request(:get, path, params.dup)
end
get_objects(path, params={}) click to toggle source
# File lib/myvr/client.rb, line 26
def get_objects(path, params={})
  response = request(:get, path, params.dup)
  response['results']
end
request(http_method, path, params={}) click to toggle source
# File lib/myvr/client.rb, line 35
def request(http_method, path, params={})
  url = base_url(path, params.dup)
  c = Curl::Easy.new(url)
  c.http_auth_types = :basic
  c.username = access_key
  c.send(http_method)
  if ENV["MYVR_TEST"]
    p JSON.parse(c.body_str)
  else
    JSON.parse(c.body_str)
  end
end
user_agent() click to toggle source
# File lib/myvr/client.rb, line 22
def user_agent
  @user_agent ||= "MyVRRubyGem/#{ MyVR::Version }"
end

Private Instance Methods

assert_class_type(klass) click to toggle source
# File lib/myvr/client.rb, line 70
def assert_class_type(klass)
  unless klass.is_a?(String) || klass.is_a?(Class)
    raise 'Class of object(s) to return must be string or class'
  end
end