music_today_api_wrapper 29.01 → 29.02

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15f3348fa68bdcfb1d64ae26fa0b24e04eff14c2
4
- data.tar.gz: a4a820afe3b00b3d43fee76a5cfbe3384aff69de
3
+ metadata.gz: 4e0a8f8f34a6cd2f81a86031c20c20f77ace2795
4
+ data.tar.gz: e079d5a619926488e18b6ee275af379b2d7cef89
5
5
  SHA512:
6
- metadata.gz: bf8166b72033e150240160044ba866d25952e52968c6fe9966045252646e3028611dd03b8d15096f3ec7d58e5fd92d1dea9abadda3fac7b3f73df2e0d8515873
7
- data.tar.gz: b6149c623158ba933f02c96bbf9ffa57cbe128825d8e81450e2a8f376b53505c993b41689d4b3fa4f526fb8058c8fa3ede02d01cb56e2be5ddecac59a02f712c
6
+ metadata.gz: 04f5d54127a3602a558bba4ba4fa661055b212553b8fd35a7eb709580d63f8ecd7cde29bc8d68a5e6bc950bb5419bb09ddc3e2d4ab8d291c6446fb00d4628100
7
+ data.tar.gz: 3b30b3ad17b16d0b9b36b3755876b1dadb9567c75ed2f4ff6a49f6086dc79ddf135e29a9e2c27809ac6fe94b01d570a0a39e38debc6909a753240e778089496e
@@ -33,8 +33,9 @@ module MusicTodayApiWrapper
33
33
  checkout_services.checkout(address, items)
34
34
  end
35
35
 
36
- def self.purchase(order)
36
+ def self.purchase(order, check_price = true)
37
37
  checkout_services = Services::CheckoutServices.new
38
- checkout_services.purchase(order)
38
+ return checkout_services.only_purchase(order) unless check_price
39
+ checkout_services.confirm_and_purchase(order) if check_price
39
40
  end
40
41
  end
@@ -43,6 +43,18 @@ module MusicTodayApiWrapper
43
43
  country: @country,
44
44
  shippingOptionType: @selected_shipping }.compact
45
45
  end
46
+
47
+ def self.from_destinations(destinations)
48
+ destinations.map do |destination|
49
+ customer = destination.customer
50
+ address = self.new(customer.street,
51
+ customer.state,
52
+ customer.city,
53
+ customer.zip_code)
54
+ address.selected_shipping = destination.shipping_option
55
+ address
56
+ end
57
+ end
46
58
  end
47
59
  end
48
60
  end
@@ -9,6 +9,8 @@ module MusicTodayApiWrapper
9
9
  module Resources
10
10
  module Checkout
11
11
  class Order
12
+ attr_accessor :customer, :destinations, :items
13
+
12
14
  def initialize(customer, payment, destinations = [], items = [],
13
15
  promotions = [])
14
16
  config = MusicTodayApiWrapper::Configuration.new
@@ -14,38 +14,62 @@ module MusicTodayApiWrapper
14
14
  end
15
15
 
16
16
  # rubocop:disable MethodLength
17
+ # rubocop:disable AbcSize
17
18
  def checkout(address, items)
18
- items_hash = []
19
- items.each { |item| items_hash << item.as_hash }
19
+ items_hash = items.map(&:as_hash)
20
20
  address_hash =
21
21
  address
22
22
  .as_hash
23
23
  .merge(id: 1, items: items_hash)
24
24
 
25
25
  @common_response.work do
26
- params = { storeId: @rest_client.catalog_number,
27
- currency: 'USD',
28
- priceLevel: '',
29
- addresses: [address_hash],
30
- promotions: [] }
31
-
26
+ params = checkout_params(address_hash)
32
27
  response = @rest_client.checkout(params)
33
28
 
34
- return response unless response.success?
35
- @common_response.data[:session] =
36
- Resources::Checkout::Session.from_hash(response.data[:session])
29
+ session = response.data[:session]
30
+ response_data = @common_response.data
31
+
32
+ response_data[:session] = Resources::Checkout::Session.from_hash(session)
33
+ response_data[:items] = session['items'].map do |item|
34
+ Resources::Purchase::Item.from_hash(item)
35
+ end
37
36
  end
38
37
  end
39
38
 
40
- def purchase(order)
41
- @common_response.work do
39
+ def only_purchase(order)
40
+ purchase do
42
41
  orders = [order.as_hash]
43
- response = @rest_client.purchase(orders: orders)
44
- return response unless response.success?
42
+ @rest_client.purchase(orders: orders)
43
+ end
44
+ end
45
+
46
+ def confirm_and_purchase(order)
47
+ purchase do
48
+ address_collection =
49
+ Resources::Address.from_destinations(order.destinations)
50
+ response = checkout(address_collection.first, order.items)
51
+ order.items = response.data[:items]
52
+ @rest_client.purchase(orders: [order.as_hash])
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def purchase
59
+ @common_response.work do
60
+ response = yield
45
61
  @common_response.data[:invoice] =
46
62
  Resources::Purchase::Invoice.from_hash(response.data[:order])
47
63
  end
48
64
  end
65
+
66
+ def checkout_params(address)
67
+ { storeId: @rest_client.catalog_number,
68
+ currency: 'USD',
69
+ priceLevel: '',
70
+ addresses: [address],
71
+ promotions: [] }
72
+ end
49
73
  end
50
74
  end
51
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music_today_api_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: '29.01'
4
+ version: '29.02'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Gonzaga
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-01 00:00:00.000000000 Z
12
+ date: 2016-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec