Class: MusicTodayApiWrapper::RestClient
- Inherits:
-
Object
- Object
- MusicTodayApiWrapper::RestClient
- Defined in:
- lib/rest_clients/music_today_rest_client.rb
Instance Attribute Summary collapse
-
#catalog_number ⇒ Object
Returns the value of attribute catalog_number.
Instance Method Summary collapse
- #all_products(per_page = 1000, page_number = nil) ⇒ Object
- #checkout(params) ⇒ Object
- #find_product(product_id) ⇒ Object
-
#initialize ⇒ RestClient
constructor
A new instance of RestClient.
- #purchase(params) ⇒ Object
- #shipping_options(params) ⇒ Object
Constructor Details
#initialize ⇒ RestClient
Returns a new instance of RestClient.
10 11 12 13 14 15 16 17 18 |
# File 'lib/rest_clients/music_today_rest_client.rb', line 10 def initialize config = MusicTodayApiWrapper::Configuration.new @url = config.url @user = config.user @api_key = config.api_key @catalog_number = config.catalog.to_i @department = config.department @common_response = MusicTodayApiWrapper::RestClients::CommonResponse.new end |
Instance Attribute Details
#catalog_number ⇒ Object
Returns the value of attribute catalog_number.
8 9 10 |
# File 'lib/rest_clients/music_today_rest_client.rb', line 8 def catalog_number @catalog_number end |
Instance Method Details
#all_products(per_page = 1000, page_number = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rest_clients/music_today_rest_client.rb', line 20 def all_products(per_page = 1000, page_number = nil) @common_response.work do = {} [:size] = per_page if per_page [:page] = page_number if page_number department = @department ? "/#{@department}" : '' url = "#{@url}/catalog/content/#{@catalog_number}#{department}/" @common_response.data[:products] = get(url, )['products'] end end |
#checkout(params) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rest_clients/music_today_rest_client.rb', line 47 def checkout(params) @common_response.work do url = "#{@url}/cart/pricing" @common_response.data[:session] = post(url, {}, params)['addresses'].first end end |
#find_product(product_id) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/rest_clients/music_today_rest_client.rb', line 32 def find_product(product_id) @common_response.work do url = "#{@url}/catalog/product/#{@catalog_number}/#{product_id}" @common_response.data[:product] = get(url)['product'] end end |
#purchase(params) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rest_clients/music_today_rest_client.rb', line 55 def purchase(params) @common_response.work do url = "#{@url}/order/submit" response = post(url, {}, params) errors = response['errors'] @common_response.data[:order] = response['orders'].first if errors.empty? purchase_errors(errors[0]['errorDetails']) if errors.any? end end |
#shipping_options(params) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/rest_clients/music_today_rest_client.rb', line 39 def (params) @common_response.work do url = "#{@url}/order/shippingOptionsGet" @common_response.data[:shipping_options] = post(url, {}, params)['shippingOptions'] end end |