Class: Ubersmith::Client

Inherits:
Object
  • Object
show all
Includes:
UrlMaker
Defined in:
lib/ubersmith/client.rb

Constant Summary collapse

BASE_URL =
"https://ubersmith.twistage.com/api/2.0/"

Instance Method Summary collapse

Methods included from UrlMaker

#_escape, #append_url_param, #build_query_string, #build_url

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



23
24
25
26
27
# File 'lib/ubersmith/client.rb', line 23

def initialize(options)
  @config_file_path = options[:config_file_path]
  @debug = options[:debug]
  puts "debug: #{@debug}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ubersmith/client.rb', line 29

def method_missing(method, *args)
  components = method.to_s.split('_', 2)
  raise "invalid method: #{method}" if components.length < 2
  raise "invalid category: #{components[0]}" unless %w(uber client device order sales support).include?(components[0])
  options = args[0] if args
  options ||= {}
  cache = options.delete(:cache)
  cache = true if cache.nil?
  ret = do_get(build_url(BASE_URL, { 
                           :method => components[0] + '.' + components[1],
                         }.merge(options)), :cache => cache)
  JSON.parse(ret)['data']
end