music_today_api_wrapper 16.12.15.01 → 16.12.15.02
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/domain/product_services.rb +4 -3
- data/lib/music_today_api_wrapper.rb +1 -1
- data/lib/resources/image.rb +8 -6
- data/lib/resources/product.rb +17 -14
- data/lib/rest_clients/common_response.rb +17 -15
- data/lib/rest_clients/music_today_rest_client.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: effc5bf9a3a58bcc1f5007ef6c7e2a77e880f644
|
4
|
+
data.tar.gz: 6696f8fd1e8acf1ca717c88f0fc894f0c234e8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df24654c72e4d2987007cfa02e4ef508ca4e586d64194f1ebb4146eb74a67d522fe6c2006e083cca701074a25c9e8ce0e608071e8619b8b61e8204189791591
|
7
|
+
data.tar.gz: 826067c3af04fcfb1138cbd8864348cd09023646e74aae9420a84ee618919e81458a3b57b0b1fdd93ee135a9fd320ee575d1acf2cb1ac357e33606353bde1aff
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rest_clients/music_today_rest_client'
|
2
2
|
require 'resources/product'
|
3
3
|
|
4
|
-
module MusicTodayApiWrapper
|
4
|
+
module MusicTodayApiWrapper::Domain
|
5
5
|
class ProductServices
|
6
6
|
def initialize
|
7
|
-
@common_response = CommonResponse.new
|
7
|
+
@common_response = MusicTodayApiWrapper::RestClients::CommonResponse.new
|
8
8
|
@common_response.data[:products] = []
|
9
9
|
@rest_client = MusicTodayApiWrapper::RestClient.new
|
10
10
|
end
|
@@ -21,7 +21,8 @@ module MusicTodayApiWrapper
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def product_mapper(product)
|
24
|
-
product_obj =
|
24
|
+
product_obj =
|
25
|
+
MusicTodayApiWrapper::Resources::Product.from_hash(product)
|
25
26
|
@common_response.data[:products] << product_obj
|
26
27
|
end
|
27
28
|
end
|
data/lib/resources/image.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module MusicTodayApiWrapper::Resources
|
2
|
+
class Image
|
3
|
+
attr_accessor :short, :medium, :large
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(short = nil, medium = nil, large = nil)
|
6
|
+
@short = short
|
7
|
+
@medium = medium
|
8
|
+
@large = large
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/resources/product.rb
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
require 'resources/image'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module MusicTodayApiWrapper::Resources
|
4
|
+
class Product
|
5
|
+
attr_accessor :name, :description, :category, :image
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def self.from_hash(product_hash)
|
16
|
+
image = Image.new(product_hash['imageUrlSmall'],
|
17
|
+
product_hash['imageUrlMedium'],
|
18
|
+
product_hash['imageUrlLarge'])
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
Product.new(product_hash['name'], product_hash['lang']['en']['textDesc'],
|
21
|
+
product_hash['categoryName'], image)
|
22
|
+
end
|
20
23
|
end
|
21
24
|
end
|
@@ -1,20 +1,22 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module MusicTodayApiWrapper::RestClients
|
2
|
+
class CommonResponse
|
3
|
+
attr_accessor :data, :errors
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(data = {}, errors = [])
|
6
|
+
@data = data
|
7
|
+
@errors = errors
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
def work
|
11
|
+
yield
|
12
|
+
self
|
13
|
+
rescue StandardError => error
|
14
|
+
@errors.push(error.message)
|
15
|
+
self
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
def success?
|
19
|
+
@errors.empty?
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|