Class: BungieClient::Wrappers::Default
- Inherits:
-
Object
- Object
- BungieClient::Wrappers::Default
- Defined in:
- lib/bungie_client/wrappers/default.rb
Direct Known Subclasses
Class Method Summary collapse
-
.services ⇒ Hash
Get list of services.
Instance Method Summary collapse
-
#call_service(service, params = {}, options = {}) ⇒ Hashie::Mash
Call needed service from services list.
-
#client ⇒ BungieClient::Client
Get wrapper client.
-
#fill_url(url, params) ⇒ String
Change all url parameters to hash value.
-
#initialize(options) ⇒ Default
constructor
Initialize wrapper with client.
- #method_missing(*args) ⇒ Object
Constructor Details
#initialize(options) ⇒ Default
Initialize wrapper with client
This initializer create wrapper object with client. If you ‘options` contain `:client` key, it will be taken as client object [BungieClient::Client]. Otherwise it will be passed in client initializer.
23 24 25 26 27 28 29 |
# File 'lib/bungie_client/wrappers/default.rb', line 23 def initialize() if [:client].nil? = elsif [:client].is_a? BungieClient::Client @client = [:client] end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
80 81 82 |
# File 'lib/bungie_client/wrappers/default.rb', line 80 def method_missing(*args) call_service args[0].to_s, args[1], args[2] end |
Class Method Details
.services ⇒ Hash
Get list of services
9 10 11 12 13 |
# File 'lib/bungie_client/wrappers/default.rb', line 9 def self.services return @services unless @services.nil? @services = YAML.load_file "#{File.dirname(__FILE__)}/../services.yml" || {} end |
Instance Method Details
#call_service(service, params = {}, options = {}) ⇒ Hashie::Mash
Call needed service from services list
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bungie_client/wrappers/default.rb', line 64 def call_service(service, params = {}, = {}) # try to fine service service = self.class.services[service] raise NoMethodError if service.nil? # init service service = BungieClient::Service.new service # change url url = self.fill_url service.endpoint, params # send request client.send "#{service.method_type}_response", url, end |
#client ⇒ BungieClient::Client
Get wrapper client
34 35 36 37 38 39 40 41 |
# File 'lib/bungie_client/wrappers/default.rb', line 34 def client return @client unless @client.nil? @client = BungieClient::Client.new = nil @client end |
#fill_url(url, params) ⇒ String
Change all url parameters to hash value
49 50 51 52 53 54 55 |
# File 'lib/bungie_client/wrappers/default.rb', line 49 def fill_url(url, params) params.each do |key, value| url = url.gsub "{#{key}}", value.to_s end url end |