music_today_api_wrapper 22.12.15.03 → 28.01.16.01

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: b3f1708963b1fd2219c16e832691bcc7f5752acf
4
- data.tar.gz: 36d4ba12c95ca99ea151af4d091fceb3b4b31c04
3
+ metadata.gz: a13056078b8cc16fbad4bda85904b64408bf482e
4
+ data.tar.gz: 28133c7238ed7b90e95d8d820c00a199c92a00d1
5
5
  SHA512:
6
- metadata.gz: f7a788e3fcfa0a0717f8fab2a913dfd16059db6cafdef1b783ddbc05f34883c80b5fbca7df8ee6edffd77162b7c353dad4a757ba71c22c8b5f5952097f77f112
7
- data.tar.gz: c7799a3b7a4a9d4d3fef8e1c17a834c584eb6ab9c9023400e74b6782554b9dc24a31da4755265941fbb352aa6b11be3df16cfc6e1ca28c134f7d29fddcb67adc
6
+ metadata.gz: 6ed88428f63fe91742ff8eb6622edb68167ce9461fb47c472516dd0e58555a88b012900c9f9ee49c5e16e77eb888ee335162a5c4906e4c86e719903fe214ca39
7
+ data.tar.gz: 4b2944d6e7c45feeb21c8dbfa5923bc024b149856275a776d14e4054bca2d1289fc7be0a1f319d26fc3dbd48b1b1370af6bec7de5fc8c0bf5cb0669e8055804a
@@ -13,7 +13,7 @@ module MusicTodayApiWrapper
13
13
  yield(configuration)
14
14
  end
15
15
 
16
- def self.products(per_page = nil, page_number = nil)
16
+ def self.products(per_page = 1000, page_number = nil)
17
17
  product_services = Services::ProductServices.new
18
18
  product_services.all_products(per_page, page_number)
19
19
  end
@@ -0,0 +1,48 @@
1
+ require 'resources/hash'
2
+
3
+ module MusicTodayApiWrapper
4
+ module Resources
5
+ module Checkout
6
+ module Billing
7
+ class Customer
8
+ attr_accessor :name,
9
+ :lastname,
10
+ :street,
11
+ :city,
12
+ :state,
13
+ :zip_code,
14
+ :phone,
15
+ :email,
16
+ :country
17
+
18
+ # rubocop:disable ParameterLists
19
+ def initialize(name = '', lastname = '', street = '', city = '',
20
+ state = '', zip_code = '', phone = '', email = '', country = 'US')
21
+ @name = name
22
+ @lastname = lastname
23
+ @street = street
24
+ @city = city
25
+ @state = state
26
+ @zip_code = zip_code
27
+ @phone = phone
28
+ @email = email
29
+ @country = country
30
+ end
31
+
32
+ def as_hash
33
+ { firstName: @name,
34
+ lastName: @lastname,
35
+ street: @street,
36
+ street2: '',
37
+ city: @city,
38
+ state: @state,
39
+ postalCode: @zip_code,
40
+ country: @country,
41
+ phone: @phone,
42
+ email: @email }.compact
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,54 @@
1
+ require 'resources/hash'
2
+ require 'credit_card_validator'
3
+
4
+ module MusicTodayApiWrapper
5
+ module Resources
6
+ module Checkout
7
+ module Billing
8
+ class Payment
9
+ attr_accessor :card_number,
10
+ :card_type,
11
+ :expiration_year,
12
+ :expiration_month,
13
+ :name,
14
+ :amount
15
+
16
+ def initialize(card_number, name, amount, expiration_year,
17
+ expiration_month)
18
+ @card_number = card_number
19
+ @expiration_year = expiration_year.to_i
20
+ @expiration_month = expiration_month.to_i
21
+ @name = name
22
+ @amount = amount.to_f
23
+ credit_card_type
24
+ end
25
+
26
+ def as_hash
27
+ { type: @card_type,
28
+ accountNumber: @card_number,
29
+ expYear: @expiration_year,
30
+ expMonth: @expiration_month,
31
+ nameOnCard: @name,
32
+ amount: @amount }.compact
33
+ end
34
+
35
+ private
36
+
37
+ def credit_card_type
38
+ @card_type =
39
+ case CreditCardValidator::Validator.card_type(@card_number)
40
+ when 'visa'
41
+ 'VISA'
42
+ when 'master_card'
43
+ 'MC'
44
+ when 'amex'
45
+ 'AMEX'
46
+ when 'discover'
47
+ 'DISCOVER'
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ require 'resources/hash'
2
+ require 'resources/address'
3
+
4
+ module MusicTodayApiWrapper
5
+ module Resources
6
+ module Checkout
7
+ class Destination
8
+ attr_accessor :address, :shipping_option, :shipping_cost
9
+
10
+ def initialize(address, shipping_option = '', shipping_cost = 0.0)
11
+ @address = address
12
+ @shipping_option = shipping_option
13
+ @shipping_cost = shipping_cost.to_f
14
+ end
15
+
16
+ def as_hash
17
+ { requestedShippingOption: @shipping_option,
18
+ shippingCost: @shipping_cost,
19
+ shipToBillTo: false,
20
+ address: @address.as_hash }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,49 @@
1
+ require 'support/configuration'
2
+ require 'resources/hash'
3
+ require 'date'
4
+ require 'resources/checkout/billing/customer'
5
+ require 'resources/checkout/billing/payment'
6
+
7
+ module MusicTodayApiWrapper
8
+ module Resources
9
+ module Checkout
10
+ class Order
11
+ def initialize(customer, payment, destinations = [], items = [],
12
+ promotions = [])
13
+ config = MusicTodayApiWrapper::Configuration.new
14
+
15
+ @catalog = config.catalog.to_i
16
+ @channel = config.channel
17
+ @prefix = config.order_prefix
18
+ @customer = customer
19
+ @payment = payment
20
+ @destinations = destinations
21
+ @items = items
22
+ @promotions = promotions
23
+ end
24
+
25
+ # rubocop:disable MethodLength
26
+ def as_hash
27
+ dynamic_id = @prefix + Time.now.to_i.to_s
28
+
29
+ { storeId: @catalog,
30
+ channel: @channel,
31
+ orderDate: DateTime.now.to_s,
32
+ clientOrderId: dynamic_id,
33
+ clientCustomerId: dynamic_id,
34
+ sendConfEmail: true,
35
+ sendDigitalConfEmail: true,
36
+ applyFraudCheck: true,
37
+ validateOnly: false,
38
+ taxPrepaid: false,
39
+ billing: { customer: @customer.as_hash,
40
+ payment: @payment.as_hash },
41
+ currency: 'USD',
42
+ destinations: @destinations.map(&:as_hash),
43
+ lineItems: @items.map(&:as_hash),
44
+ promotions: @promotions.map(&:as_hash) }.compact
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -8,11 +8,12 @@ module MusicTodayApiWrapper
8
8
  attr_accessor :variant, :quantity
9
9
 
10
10
  def initialize(variant = Variant.new, quantity = 1, tax = nil,
11
- total = nil)
11
+ total = nil, destination_id = nil)
12
12
  @variant = variant
13
13
  @quantity = quantity
14
14
  @tax = tax
15
15
  @total = total
16
+ @destination_id = destination_id
16
17
  end
17
18
 
18
19
  def as_hash
@@ -21,7 +22,8 @@ module MusicTodayApiWrapper
21
22
  quantity: @quantity,
22
23
  price: @variant.price,
23
24
  tax: @tax,
24
- total: @total }.compact
25
+ total: @total,
26
+ destIndex: @destination_id }.compact
25
27
  end
26
28
 
27
29
  def self.from_hash(item_hash)
@@ -13,16 +13,18 @@ module MusicTodayApiWrapper
13
13
  @user = config.user
14
14
  @api_key = config.api_key
15
15
  @catalog_number = config.catalog.to_i
16
+ @department = config.department
16
17
  @common_response = MusicTodayApiWrapper::RestClients::CommonResponse.new
17
18
  end
18
19
 
19
- def all_products(per_page = nil, page_number = nil)
20
+ def all_products(per_page = 1000, page_number = nil)
20
21
  @common_response.work do
21
22
  options = {}
22
23
  options[:size] = per_page if per_page
23
24
  options[:page] = page_number if page_number
25
+ department = @department ? "/#{@department}" : ''
24
26
 
25
- url = "#{@url}/catalog/content/#{@catalog_number}/"
27
+ url = "#{@url}/catalog/content/#{@catalog_number}#{department}/"
26
28
  @common_response.data[:products] = get(url, options)['products']
27
29
  end
28
30
  end
@@ -10,7 +10,7 @@ module MusicTodayApiWrapper
10
10
  @rest_client = MusicTodayApiWrapper::RestClient.new
11
11
  end
12
12
 
13
- def all_products(per_page = nil, page_number = nil)
13
+ def all_products(per_page = 1000, page_number = nil)
14
14
  results = @rest_client.all_products(per_page, page_number)
15
15
  return results unless results.success?
16
16
 
@@ -1,12 +1,21 @@
1
1
  module MusicTodayApiWrapper
2
2
  class Configuration
3
- attr_accessor :user, :api_key, :url, :catalog
3
+ attr_accessor :user,
4
+ :api_key,
5
+ :url,
6
+ :catalog,
7
+ :department,
8
+ :channel,
9
+ :order_prefix
4
10
 
5
11
  def initialize
6
12
  @user = ENV['MUSIC_TODAY_USER']
7
13
  @api_key = ENV['MUSIC_TODAY_API_KEY']
8
14
  @url = ENV['MUSIC_TODAY_BASE_URL']
9
15
  @catalog = ENV['MUSIC_TODAY_CATALOG_NAME']
16
+ @department = ENV['MUSIC_TODAY_DEPARTMENT_NAME'] || nil
17
+ @channel = ENV['MUSIC_TODAY_CHANNEL'] || ''
18
+ @order_prefix = ENV['MUSIC_TODAY_ORDER_PREFIX'] || 'EXA'
10
19
  end
11
20
  end
12
21
  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: 22.12.15.03
4
+ version: 28.01.16.01
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: 2015-12-22 00:00:00.000000000 Z
12
+ date: 2016-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -139,6 +139,9 @@ dependencies:
139
139
  name: bundler
140
140
  requirement: !ruby/object:Gem::Requirement
141
141
  requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '1.10'
142
145
  - - ">="
143
146
  - !ruby/object:Gem::Version
144
147
  version: 1.10.6
@@ -146,6 +149,9 @@ dependencies:
146
149
  prerelease: false
147
150
  version_requirements: !ruby/object:Gem::Requirement
148
151
  requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: '1.10'
149
155
  - - ">="
150
156
  - !ruby/object:Gem::Version
151
157
  version: 1.10.6
@@ -153,6 +159,9 @@ dependencies:
153
159
  name: rake
154
160
  requirement: !ruby/object:Gem::Requirement
155
161
  requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '10.4'
156
165
  - - ">="
157
166
  - !ruby/object:Gem::Version
158
167
  version: 10.4.2
@@ -160,6 +169,9 @@ dependencies:
160
169
  prerelease: false
161
170
  version_requirements: !ruby/object:Gem::Requirement
162
171
  requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '10.4'
163
175
  - - ">="
164
176
  - !ruby/object:Gem::Version
165
177
  version: 10.4.2
@@ -183,6 +195,20 @@ dependencies:
183
195
  - - ">="
184
196
  - !ruby/object:Gem::Version
185
197
  version: 1.8.3
198
+ - !ruby/object:Gem::Dependency
199
+ name: credit_card_validator
200
+ requirement: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - "~>"
203
+ - !ruby/object:Gem::Version
204
+ version: '1.2'
205
+ type: :runtime
206
+ prerelease: false
207
+ version_requirements: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - "~>"
210
+ - !ruby/object:Gem::Version
211
+ version: '1.2'
186
212
  description: Gem to expose music today api endpoints.
187
213
  email: pgonzaga.uy@gmail.com
188
214
  executables: []
@@ -191,6 +217,10 @@ extra_rdoc_files: []
191
217
  files:
192
218
  - lib/music_today_api_wrapper.rb
193
219
  - lib/resources/address.rb
220
+ - lib/resources/checkout/billing/customer.rb
221
+ - lib/resources/checkout/billing/payment.rb
222
+ - lib/resources/checkout/destination.rb
223
+ - lib/resources/checkout/order.rb
194
224
  - lib/resources/checkout/session.rb
195
225
  - lib/resources/hash.rb
196
226
  - lib/resources/image.rb