music_today_api_wrapper 29.01 → 29.02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/music_today_api_wrapper.rb +3 -2
- data/lib/resources/address.rb +12 -0
- data/lib/resources/checkout/order.rb +2 -0
- data/lib/services/checkout_services.rb +39 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e0a8f8f34a6cd2f81a86031c20c20f77ace2795
|
4
|
+
data.tar.gz: e079d5a619926488e18b6ee275af379b2d7cef89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
data/lib/resources/address.rb
CHANGED
@@ -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 =
|
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
|
-
|
35
|
-
@common_response.data
|
36
|
-
|
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
|
41
|
-
|
39
|
+
def only_purchase(order)
|
40
|
+
purchase do
|
42
41
|
orders = [order.as_hash]
|
43
|
-
|
44
|
-
|
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.
|
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-
|
12
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|