music_today_api_wrapper 16.12.15.02 → 16.12.15.03

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: effc5bf9a3a58bcc1f5007ef6c7e2a77e880f644
4
- data.tar.gz: 6696f8fd1e8acf1ca717c88f0fc894f0c234e8dc
3
+ metadata.gz: 5257b1448b701bcfbbda6c1c88a866d1ffeed5f7
4
+ data.tar.gz: 231cffef87679a3827e7c992298a3ff831caf0af
5
5
  SHA512:
6
- metadata.gz: 7df24654c72e4d2987007cfa02e4ef508ca4e586d64194f1ebb4146eb74a67d522fe6c2006e083cca701074a25c9e8ce0e608071e8619b8b61e8204189791591
7
- data.tar.gz: 826067c3af04fcfb1138cbd8864348cd09023646e74aae9420a84ee618919e81458a3b57b0b1fdd93ee135a9fd320ee575d1acf2cb1ac357e33606353bde1aff
6
+ metadata.gz: 63729e32b5b07c461e3f09adef9ea84c2b1268522d4a9c68842ad218a477bb4138dd677edcdc67c451f37abee0684dc7b7ef6d302bea683b47a0d32da68e3e08
7
+ data.tar.gz: dd3e6a5d12b15b73b8ca428dff2b25e1d4b1dca44a90ee9499d10bd808b818020ea3e14e14bc2dfc6840d118a14698e2e91118a6a454337e54a37768d433afca
@@ -1,5 +1,5 @@
1
1
  require 'support/configuration'
2
- require 'domain/product_services'
2
+ require 'services/product_services'
3
3
 
4
4
  module MusicTodayApiWrapper
5
5
  class << self
@@ -12,7 +12,12 @@ module MusicTodayApiWrapper
12
12
  end
13
13
 
14
14
  def self.products
15
- product_services = Domain::ProductServices.new
15
+ product_services = Services::ProductServices.new
16
16
  product_services.all_products
17
17
  end
18
+
19
+ def self.find_product(id)
20
+ product_services = Services::ProductServices.new
21
+ product_services.find_product(id)
22
+ end
18
23
  end
@@ -1,11 +1,13 @@
1
- module MusicTodayApiWrapper::Resources
2
- class Image
3
- attr_accessor :short, :medium, :large
1
+ module MusicTodayApiWrapper
2
+ module Resources
3
+ class Image
4
+ attr_accessor :short, :medium, :large
4
5
 
5
- def initialize(short = nil, medium = nil, large = nil)
6
- @short = short
7
- @medium = medium
8
- @large = large
6
+ def initialize(short = nil, medium = nil, large = nil)
7
+ @short = short
8
+ @medium = medium
9
+ @large = large
10
+ end
9
11
  end
10
12
  end
11
13
  end
@@ -1,24 +1,33 @@
1
1
  require 'resources/image'
2
2
 
3
- module MusicTodayApiWrapper::Resources
4
- class Product
5
- attr_accessor :name, :description, :category, :image
3
+ module MusicTodayApiWrapper
4
+ module Resources
5
+ class Product
6
+ attr_accessor :uid, :name, :description, :category, :image, :price
6
7
 
7
- def initialize(name, description, category,
8
- image = MusicTodayApiWrapper::Resources::Image.new)
9
- @name = name
10
- @description = description
11
- @category = category
12
- @image = image
13
- end
8
+ # rubocop:disable ParameterLists
9
+ def initialize(uid, name, description, category, price,
10
+ image = MusicTodayApiWrapper::Resources::Image.new)
11
+ @uid = uid
12
+ @name = name
13
+ @description = description
14
+ @category = category
15
+ @price = price
16
+ @image = image
17
+ end
14
18
 
15
- def self.from_hash(product_hash)
16
- image = Image.new(product_hash['imageUrlSmall'],
17
- product_hash['imageUrlMedium'],
18
- product_hash['imageUrlLarge'])
19
+ def self.from_hash(product_hash)
20
+ image = Image.new(product_hash['imageUrlSmall'],
21
+ product_hash['imageUrlMedium'],
22
+ product_hash['imageUrlLarge'])
19
23
 
20
- Product.new(product_hash['name'], product_hash['lang']['en']['textDesc'],
21
- product_hash['categoryName'], image)
24
+ Product.new(product_hash['id'],
25
+ product_hash['name'],
26
+ product_hash['lang']['en']['textDesc'],
27
+ product_hash['categoryName'],
28
+ product_hash['listPrice'],
29
+ image)
30
+ end
22
31
  end
23
32
  end
24
33
  end
@@ -1,22 +1,24 @@
1
- module MusicTodayApiWrapper::RestClients
2
- class CommonResponse
3
- attr_accessor :data, :errors
1
+ module MusicTodayApiWrapper
2
+ module RestClients
3
+ class CommonResponse
4
+ attr_accessor :data, :errors
4
5
 
5
- def initialize(data = {}, errors = [])
6
- @data = data
7
- @errors = errors
8
- end
6
+ def initialize(data = {}, errors = [])
7
+ @data = data
8
+ @errors = errors
9
+ end
9
10
 
10
- def work
11
- yield
12
- self
13
- rescue StandardError => error
14
- @errors.push(error.message)
15
- self
16
- end
11
+ def work
12
+ yield
13
+ self
14
+ rescue StandardError => error
15
+ @errors.push(error.message)
16
+ self
17
+ end
17
18
 
18
- def success?
19
- @errors.empty?
19
+ def success?
20
+ @errors.empty?
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -10,16 +10,28 @@ module MusicTodayApiWrapper
10
10
  @url = config.url
11
11
  @user = config.user
12
12
  @api_key = config.api_key
13
+ @catalog_number = config.catalog
13
14
  @common_response = MusicTodayApiWrapper::RestClients::CommonResponse.new
14
15
  end
15
16
 
16
17
  def all_products
17
18
  @common_response.work do
18
19
  uri =
19
- URI("#{@url}/catalog/content/1/?apiuser=#{@user}&apikey=#{@api_key}")
20
+ URI("#{@url}/catalog/content/#{@catalog_number}/?apiuser=#{@user}&"\
21
+ "apikey=#{@api_key}")
20
22
  res = Net::HTTP.get_response(uri)
21
23
  @common_response.data[:products] = JSON.parse(res.body)['products']
22
24
  end
23
25
  end
26
+
27
+ def find_product(product_id)
28
+ @common_response.work do
29
+ uri =
30
+ URI("#{@url}/catalog/product/#{@catalog_number}/#{product_id}?"\
31
+ "apiuser=#{@user}&apikey=#{@api_key}")
32
+ res = Net::HTTP.get_response(uri)
33
+ @common_response.data[:product] = JSON.parse(res.body)['product']
34
+ end
35
+ end
24
36
  end
25
37
  end
@@ -0,0 +1,43 @@
1
+ require 'rest_clients/music_today_rest_client'
2
+ require 'resources/product'
3
+
4
+ module MusicTodayApiWrapper
5
+ module Services
6
+ class ProductServices
7
+ def initialize
8
+ @common_response =
9
+ MusicTodayApiWrapper::RestClients::CommonResponse.new
10
+ @rest_client = MusicTodayApiWrapper::RestClient.new
11
+ end
12
+
13
+ def all_products
14
+ results = @rest_client.all_products
15
+ return results unless results.success?
16
+
17
+ @common_response.data[:products] = []
18
+ @common_response.work do
19
+ results.data[:products].each { |product| product_mapper(product) }
20
+ end
21
+ end
22
+
23
+ def find_product(id)
24
+ results = @rest_client.find_product(id)
25
+ return results unless results.success?
26
+
27
+ @common_response.work do
28
+ @common_response.data[:product] =
29
+ MusicTodayApiWrapper::Resources::Product
30
+ .from_hash(results.data[:product])
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def product_mapper(product)
37
+ product_obj =
38
+ MusicTodayApiWrapper::Resources::Product.from_hash(product)
39
+ @common_response.data[:products] << product_obj
40
+ end
41
+ end
42
+ end
43
+ end
@@ -2,13 +2,14 @@ require 'dotenv'
2
2
 
3
3
  module MusicTodayApiWrapper
4
4
  class Configuration
5
- attr_accessor :user, :api_key, :url
5
+ attr_accessor :user, :api_key, :url, :catalog
6
6
 
7
7
  def initialize
8
8
  Dotenv.load
9
9
  @user = ENV['MUSIC_TODAY_USER']
10
10
  @api_key = ENV['MUSIC_TODAY_API_KEY']
11
11
  @url = ENV['MUSIC_TODAY_BASE_URL']
12
+ @catalog = ENV['MUSIC_TODAY_CATALOG_NAME']
12
13
  end
13
14
  end
14
15
  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: 16.12.15.02
4
+ version: 16.12.15.03
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Gonzaga
@@ -175,12 +175,12 @@ executables: []
175
175
  extensions: []
176
176
  extra_rdoc_files: []
177
177
  files:
178
- - lib/domain/product_services.rb
179
178
  - lib/music_today_api_wrapper.rb
180
179
  - lib/resources/image.rb
181
180
  - lib/resources/product.rb
182
181
  - lib/rest_clients/common_response.rb
183
182
  - lib/rest_clients/music_today_rest_client.rb
183
+ - lib/services/product_services.rb
184
184
  - lib/support/configuration.rb
185
185
  homepage: https://github.com/neonroots/music_today_api_wrapper
186
186
  licenses:
@@ -1,29 +0,0 @@
1
- require 'rest_clients/music_today_rest_client'
2
- require 'resources/product'
3
-
4
- module MusicTodayApiWrapper::Domain
5
- class ProductServices
6
- def initialize
7
- @common_response = MusicTodayApiWrapper::RestClients::CommonResponse.new
8
- @common_response.data[:products] = []
9
- @rest_client = MusicTodayApiWrapper::RestClient.new
10
- end
11
-
12
- def all_products
13
- results = @rest_client.all_products
14
- return results unless results.success?
15
-
16
- @common_response.work do
17
- results.data[:products].each { |product| product_mapper(product) }
18
- end
19
- end
20
-
21
- private
22
-
23
- def product_mapper(product)
24
- product_obj =
25
- MusicTodayApiWrapper::Resources::Product.from_hash(product)
26
- @common_response.data[:products] << product_obj
27
- end
28
- end
29
- end