Class: Ubersmith::Client
- Inherits:
-
Object
- Object
- Ubersmith::Client
- Includes:
- UrlMaker
- Defined in:
- lib/ubersmith/client.rb
Constant Summary collapse
- BASE_URL =
"https://ubersmith.twistage.com/api/2.0/"
Instance Method Summary collapse
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, *args) ⇒ Object
Methods included from UrlMaker
#_escape, #append_url_param, #build_query_string, #build_url
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
26 27 28 29 |
# File 'lib/ubersmith/client.rb', line 26 def initialize() @config_file_path = [:config_file_path] @debug = [:debug] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ubersmith/client.rb', line 31 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]) = args[0] if args ||= {} cache = .delete(:cache) cache = false if cache.nil? ret = call_api(build_url(BASE_URL, { :method => components[0] + '.' + components[1], }.merge()), :cache => cache) ret = JSON.parse(ret) if !ret.respond_to?(:[]) || ret['status'] != true raise ret['error_message'] if ret['error_message'].to_s =~ /invalid method specified/ puts "Ubersmith error: #{ret['error_message']}" return {} end ret['data'] end |