Class: Adility::Client
- Inherits:
-
Object
- Object
- Adility::Client
- Defined in:
- lib/adility.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Client
constructor
Initialize the client.
- #method_missing(sym, *args, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Client
Initialize the client. TODO: Document.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/adility.rb', line 13 def initialize(*args) = args. @api_key = args[0] @conn = Faraday.new(:url => "https://testapi.offersdb.com") do |builder| builder.adapter Faraday.default_adapter builder.adapter :logger if [:debug] == true builder.use Faraday::Response::ParseJson builder.use Faraday::Response::Mashify end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/adility.rb', line 23 def method_missing(sym, *args, &block) = args. if args[0] url = "/distribution/beta/#{sym.to_s}/#{args[0]}.json" else url = "/distribution/beta/#{sym.to_s}.json" end response = conn.get(url) do |req| req.headers['X-OFFERSDB-API-KEY'] = api_key req.params = end total_pages = response.body.send :total_pages total_items = response.body.send :total_items page = response.body.send :page if args[0].nil? ret = response.body.send sym return ret, page, total_pages else ret = response.body.send sym.to_s.chop return ret end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/adility.rb', line 9 def api_key @api_key end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
9 10 11 |
# File 'lib/adility.rb', line 9 def conn @conn end |