Class: LomadeeApi::Base
- Inherits:
-
Object
- Object
- LomadeeApi::Base
- Includes:
- HTTParty
- Defined in:
- lib/lomadee_api/base.rb
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
- #offers(product_id) ⇒ Object
- #products(category_id) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lomadee_api/base.rb', line 5 def initialize(params = {}) raise "You need to inform your :application_id" if params[:application_id].nil? @application_id = params[:application_id] @country = params[:country] || 'BR' sandbox = params[:sandbox] || false case sandbox when false self.class.base_uri "http://bws.buscape.com" else self.class.base_uri "http://sandbox.buscape.com" end end |
Instance Method Details
#offers(product_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lomadee_api/base.rb', line 36 def offers(product_id) @page = @totalpages = 1 while @page <= @totalpages offers = self.class.get("/service/findOfferList/lomadee/#{@application_id}/#{@country}/", query: {productId: product_id, format: 'json', page: @page}) @response = JSON.parse(offers.body) @totalpages = @response['totalpages'] @page += 1 yield @response['offer'] end end |
#products(category_id) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lomadee_api/base.rb', line 22 def products(category_id) @page = @totalpages = 1 while @page <= @totalpages products = self.class.get("/service/findProductList/lomadee/#{@application_id}/#{@country}/", query: {categoryId: category_id, format: 'json', page: @page}) @response = JSON.parse(products.body) @totalpages = @response['totalpages'] @page += 1 yield @response['product'] end end |