Class: MusicTodayApiWrapper::Services::ShippingServices

Inherits:
Object
  • Object
show all
Defined in:
lib/services/shipping_services.rb

Instance Method Summary collapse

Constructor Details

#initializeShippingServices

Returns a new instance of ShippingServices.



7
8
9
10
11
# File 'lib/services/shipping_services.rb', line 7

def initialize
  @common_response = RestClients::CommonResponse.new
  @common_response.data[:shipping_options] = []
  @rest_client = RestClient.new
end

Instance Method Details

#options(address, items) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/services/shipping_services.rb', line 13

def options(address, items)
  hash_items = []
  items.each { |item| hash_items << item.as_hash }

  params = { storeId: @rest_client.catalog_number,
             address: address.as_hash,
             lineItems: hash_items }
  @common_response.work do
    response = @rest_client.shipping_options(params)
    return response unless response.success?

    response
      .data[:shipping_options]
      .each { |option| shipping_option_mapper(option) }
  end
end