music_today_api_wrapper 29.03 → 29.04

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cccc2834691cfd4c637c5d8db5d3275c7df064f
4
- data.tar.gz: 2be6324dae2081decdf951fd5ba41e1e19a8a47f
3
+ metadata.gz: 0cfe9573dbd31542cc007a9af5c5121ffe8a6cb2
4
+ data.tar.gz: 3da6e98054316fd90b322652a29e7a8f3416f846
5
5
  SHA512:
6
- metadata.gz: 4c5cb2cd78572f94fc80eb3072e2294231645849b66af29f9c4753fbd306c6d9009404665562ef10a0459c58cd2bda620d40339c31f7160458a66405d4b19aae
7
- data.tar.gz: 6b6bf090782ced45939bc6f063387545b01f69f6dc22a41ac2b18ddb659e0ce85f54853cdf278b97c7a236341aa384234dd7d24d13c9c8a1b0375175e197e9b6
6
+ metadata.gz: efb1696a7d4a8666c38e62a302582da2ec8b76a18000eca4f015c65f94a08202c596c1b8a91bad2e3015e64cf86d92f11264dfdf9206727d2bbb882caa5b757f
7
+ data.tar.gz: 40813cb4d9927bf06d032fb874e97d7505c1cdd4af97825c3f73aab0575b9460edee83dc3ce29fa7745cc24971904bb9a5243d22d80b3c5c9a7206e857d2194e
@@ -47,10 +47,10 @@ module MusicTodayApiWrapper
47
47
  def self.from_destinations(destinations)
48
48
  destinations.map do |destination|
49
49
  customer = destination.customer
50
- address = self.new(customer.street,
51
- customer.state,
52
- customer.city,
53
- customer.zip_code)
50
+ address = new(customer.street,
51
+ customer.state,
52
+ customer.city,
53
+ customer.zip_code)
54
54
  address.selected_shipping = destination.shipping_option
55
55
  address
56
56
  end
@@ -55,8 +55,11 @@ module MusicTodayApiWrapper
55
55
  def purchase(params)
56
56
  @common_response.work do
57
57
  url = "#{@url}/order/submit"
58
+ response = post(url, {}, params)
59
+ errors = response['errors']
58
60
  @common_response.data[:order] =
59
- post(url, {}, params)['orders'].first
61
+ response['orders'].first if errors.empty?
62
+ purchase_errors(errors[0]['errorDetails']) if errors.any?
60
63
  end
61
64
  end
62
65
 
@@ -88,5 +91,16 @@ module MusicTodayApiWrapper
88
91
  response = yield
89
92
  JSON.parse(response.body)
90
93
  end
94
+
95
+ def purchase_errors(error_details)
96
+ errors = @common_response.errors
97
+ if error_details['billingErrors'].any? ||
98
+ error_details['destinationErrors'].any?
99
+ errors.push(type: :address_error)
100
+ end
101
+
102
+ return unless error_details['paymentErrors'].any?
103
+ errors.push(type: :credit_card_error)
104
+ end
91
105
  end
92
106
  end
@@ -13,14 +13,11 @@ module MusicTodayApiWrapper
13
13
  @rest_client = RestClient.new
14
14
  end
15
15
 
16
- # rubocop:disable MethodLength
17
16
  # rubocop:disable AbcSize
18
17
  def checkout(address, items)
19
18
  items_hash = items.map(&:as_hash)
20
19
  address_hash =
21
- address
22
- .as_hash
23
- .merge(id: 1, items: items_hash)
20
+ address.as_hash.merge(id: 1, items: items_hash)
24
21
 
25
22
  @common_response.work do
26
23
  params = checkout_params(address_hash)
@@ -29,7 +26,8 @@ module MusicTodayApiWrapper
29
26
  session = response.data[:session]
30
27
  response_data = @common_response.data
31
28
 
32
- response_data[:session] = Resources::Checkout::Session.from_hash(session)
29
+ response_data[:session] =
30
+ Resources::Checkout::Session.from_hash(session)
33
31
  response_data[:items] = session['items'].map do |item|
34
32
  Resources::Purchase::Item.from_hash(item)
35
33
  end
@@ -58,8 +56,13 @@ module MusicTodayApiWrapper
58
56
  def purchase
59
57
  @common_response.work do
60
58
  response = yield
61
- @common_response.data[:invoice] =
62
- Resources::Purchase::Invoice.from_hash(response.data[:order])
59
+ if response.success?
60
+ @common_response.data[:invoice] =
61
+ Resources::Purchase::Invoice.from_hash(response.data[:order])
62
+ else
63
+ @common_response.errors = response.errors
64
+ @common_response.data = {}
65
+ end
63
66
  end
64
67
  end
65
68
 
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.03'
4
+ version: '29.04'
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-11 00:00:00.000000000 Z
12
+ date: 2016-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  version: '0'
257
257
  requirements: []
258
258
  rubyforge_project:
259
- rubygems_version: 2.4.8
259
+ rubygems_version: 2.5.1
260
260
  signing_key:
261
261
  specification_version: 4
262
262
  summary: Gem to expose music today api endpoints.