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 +4 -4
- data/lib/music_today_api_wrapper.rb +7 -2
- data/lib/resources/image.rb +9 -7
- data/lib/resources/product.rb +25 -16
- data/lib/rest_clients/common_response.rb +18 -16
- data/lib/rest_clients/music_today_rest_client.rb +13 -1
- data/lib/services/product_services.rb +43 -0
- data/lib/support/configuration.rb +2 -1
- metadata +2 -2
- data/lib/domain/product_services.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5257b1448b701bcfbbda6c1c88a866d1ffeed5f7
|
4
|
+
data.tar.gz: 231cffef87679a3827e7c992298a3ff831caf0af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63729e32b5b07c461e3f09adef9ea84c2b1268522d4a9c68842ad218a477bb4138dd677edcdc67c451f37abee0684dc7b7ef6d302bea683b47a0d32da68e3e08
|
7
|
+
data.tar.gz: dd3e6a5d12b15b73b8ca428dff2b25e1d4b1dca44a90ee9499d10bd808b818020ea3e14e14bc2dfc6840d118a14698e2e91118a6a454337e54a37768d433afca
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'support/configuration'
|
2
|
-
require '
|
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 =
|
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
|
data/lib/resources/image.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
module MusicTodayApiWrapper
|
2
|
-
|
3
|
-
|
1
|
+
module MusicTodayApiWrapper
|
2
|
+
module Resources
|
3
|
+
class Image
|
4
|
+
attr_accessor :short, :medium, :large
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/lib/resources/product.rb
CHANGED
@@ -1,24 +1,33 @@
|
|
1
1
|
require 'resources/image'
|
2
2
|
|
3
|
-
module MusicTodayApiWrapper
|
4
|
-
|
5
|
-
|
3
|
+
module MusicTodayApiWrapper
|
4
|
+
module Resources
|
5
|
+
class Product
|
6
|
+
attr_accessor :uid, :name, :description, :category, :image, :price
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
-
|
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
|
2
|
-
|
3
|
-
|
1
|
+
module MusicTodayApiWrapper
|
2
|
+
module RestClients
|
3
|
+
class CommonResponse
|
4
|
+
attr_accessor :data, :errors
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(data = {}, errors = [])
|
7
|
+
@data = data
|
8
|
+
@errors = errors
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def work
|
12
|
+
yield
|
13
|
+
self
|
14
|
+
rescue StandardError => error
|
15
|
+
@errors.push(error.message)
|
16
|
+
self
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
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
|
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.
|
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
|