music_today_api_wrapper 18.12.15.02 → 21.12.15.01

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: 33e302c3601ae670ac2b19fc9484df2488f1db77
4
- data.tar.gz: d4b0f4c782846d4f3405fbe9cd073acc6e236384
3
+ metadata.gz: 436e40cd69c01b51589fd255bfa98de8f0eae9eb
4
+ data.tar.gz: fa26c05c6513d2c945e6153c53201f6de3ce5712
5
5
  SHA512:
6
- metadata.gz: 223bdfee025c9293848969153f7fbfeb3735ea375fa8088fc61c499458c60231d31689865fbd179fb10b6536fd9d1053309a66f1db851962e64b67ba309b9d23
7
- data.tar.gz: fc1c6956178a2c46f5fc207c650ff4fc61bdfd6061939d3af5014f43d2831a044efaa6914b24cf9131dc2c3d65c801451c8ee501367531565531efcba161a730
6
+ metadata.gz: 15de1268c030520ad96119c68be3973d61301c95d1e4bdef6df1fd5f8287068bef156eec620574257b7c655d1807231307c5927682c6fc913ab8e2658425436b
7
+ data.tar.gz: 67bcc64e2808a708ae7f746a0b8c2f1a3fc0c0c8b1f471cab5fa0b4178996ef3db6ffd8e2c94ab018bfd5d767a12b8ee6da71018cb50d54b2077fb818c3b8577
@@ -17,9 +17,9 @@ module MusicTodayApiWrapper
17
17
  product_services.all_products
18
18
  end
19
19
 
20
- def self.find_product(parent_id, id)
20
+ def self.find_product(id)
21
21
  product_services = Services::ProductServices.new
22
- product_services.find_product(parent_id, id)
22
+ product_services.find_product(id)
23
23
  end
24
24
 
25
25
  def self.shipping_options(address, items)
@@ -1,47 +1,46 @@
1
1
  require 'resources/image'
2
+ require 'resources/variant'
2
3
 
3
4
  module MusicTodayApiWrapper
4
5
  module Resources
5
6
  class Product
6
7
  attr_accessor :uid,
7
- :parent_id,
8
8
  :name,
9
9
  :description,
10
10
  :category,
11
11
  :image,
12
- :price
12
+ :price,
13
+ :variants
13
14
 
14
15
  # rubocop:disable ParameterLists
15
- def initialize(uid, parent_id, name, description, category, price,
16
- image = MusicTodayApiWrapper::Resources::Image.new)
16
+ def initialize(uid, name, description, category, price,
17
+ image = MusicTodayApiWrapper::Resources::Image.new, variants = [])
17
18
  @uid = uid
18
- @parent_id = parent_id
19
19
  @name = name
20
20
  @description = description
21
21
  @category = category
22
22
  @price = price
23
23
  @image = image
24
+ @variants = variants
24
25
  end
25
26
 
26
- def self.from_hash(product)
27
- image = Image.new(product['imageUrlSmall'],
28
- product['imageUrlMedium'],
29
- product['imageUrlLarge'])
30
- variants = []
31
- product['variants'].each do |variant|
32
- variants << variant_from_hash(product, variant, image)
33
- end
34
- variants
35
- end
27
+ # rubocop:disable AbcSize
28
+ def self.from_hash(hash)
29
+ image = Image.new(hash['imageUrlSmall'],
30
+ hash['imageUrlMedium'],
31
+ hash['imageUrlLarge'])
36
32
 
37
- def self.variant_from_hash(product_hash, variant_hash, image)
38
- Product.new(variant_hash['sku'],
39
- product_hash['id'],
40
- product_hash['name'],
41
- product_hash['lang']['en']['textDesc'],
42
- product_hash['categoryName'],
43
- variant_hash['listPrice'],
44
- image)
33
+ product = Product.new(hash['id'],
34
+ hash['name'],
35
+ hash['lang']['en']['textDesc'],
36
+ hash['categoryName'],
37
+ hash['listPrice'],
38
+ image)
39
+
40
+ hash['variants'].each do |variant|
41
+ product.variants << Variant.from_hash(variant)
42
+ end
43
+ product
45
44
  end
46
45
  end
47
46
  end
@@ -1,19 +1,19 @@
1
- require 'resources/product'
1
+ require 'resources/variant'
2
2
  module MusicTodayApiWrapper
3
3
  module Resources
4
4
  module Purchase
5
5
  class Item
6
- attr_accessor :product, :quantity
6
+ attr_accessor :variant, :quantity
7
7
 
8
- def initialize(product = Product.new, quantity = 1)
9
- @product = product
8
+ def initialize(variant = Variant.new, quantity = 1)
9
+ @variant = variant
10
10
  @quantity = quantity
11
11
  end
12
12
 
13
13
  def as_hash
14
- { sku: @product.uid,
14
+ { sku: @variant.sku,
15
15
  qty: @quantity,
16
- price: @product.price }
16
+ price: @variant.price }
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,35 @@
1
+ require 'facets'
2
+ module MusicTodayApiWrapper
3
+ module Resources
4
+ class Variant
5
+ attr_accessor :sku,
6
+ :price,
7
+ :quantity_available,
8
+ :variant_names
9
+
10
+ # rubocop:disable ParameterLists
11
+ def initialize(sku, price, quantity_available, variant_names = [])
12
+ @sku = sku
13
+ @price = price
14
+ @quantity_available = quantity_available
15
+ @variant_names = variant_names
16
+ end
17
+
18
+ def self.from_hash(variant_hash)
19
+ size, format, bitrate = nil
20
+ variant_names = []
21
+
22
+ variant_hash['variantNames'].each do |variant|
23
+ variant_name = {}
24
+ variant_name[variant.keys[0].snakecase.to_sym] = variant.values[0]
25
+ variant_names << variant_name
26
+ end
27
+
28
+ Variant.new(variant_hash['sku'],
29
+ variant_hash['listPrice'],
30
+ variant_hash['qtyAvailable'],
31
+ variant_names)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -20,26 +20,23 @@ module MusicTodayApiWrapper
20
20
  end
21
21
  end
22
22
 
23
- def find_product(parent_id, id)
24
- results = @rest_client.find_product(parent_id)
23
+ def find_product(id)
24
+ results = @rest_client.find_product(id)
25
25
  return results unless results.success?
26
26
 
27
27
  @common_response.work do
28
- find_variant(id, results.data[:product])
28
+ @common_response.data[:product] =
29
+ MusicTodayApiWrapper::Resources::Product
30
+ .from_hash(results.data[:product])
29
31
  end
30
32
  end
31
33
 
32
34
  private
33
35
 
34
36
  def product_mapper(product)
35
- @common_response.data[:products] +=
36
- Resources::Product.from_hash(product)
37
- end
38
-
39
- def find_variant(id, product_and_variants)
40
- products = Resources::Product.from_hash(product_and_variants)
41
- @common_response.data[:product] =
42
- products.find { |product| product.uid == id }
37
+ product_obj =
38
+ MusicTodayApiWrapper::Resources::Product.from_hash(product)
39
+ @common_response.data[:products] << product_obj
43
40
  end
44
41
  end
45
42
  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: 18.12.15.02
4
+ version: 21.12.15.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-18 00:00:00.000000000 Z
12
+ date: 2015-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -183,6 +183,20 @@ dependencies:
183
183
  - - ">="
184
184
  - !ruby/object:Gem::Version
185
185
  version: 1.8.3
186
+ - !ruby/object:Gem::Dependency
187
+ name: facets
188
+ requirement: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - "~>"
191
+ - !ruby/object:Gem::Version
192
+ version: '3.0'
193
+ type: :runtime
194
+ prerelease: false
195
+ version_requirements: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '3.0'
186
200
  description: Gem to expose music today api endpoints.
187
201
  email: pgonzaga.uy@gmail.com
188
202
  executables: []
@@ -195,6 +209,7 @@ files:
195
209
  - lib/resources/product.rb
196
210
  - lib/resources/purchase/item.rb
197
211
  - lib/resources/purchase/shipping_option.rb
212
+ - lib/resources/variant.rb
198
213
  - lib/rest_clients/common_response.rb
199
214
  - lib/rest_clients/music_today_rest_client.rb
200
215
  - lib/services/product_services.rb