dooca_commerce 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/response_handler.rb +37 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89deab28dafe36c32e9d8f1f815ef436c86915c950a5f700e7606cc17205f825
|
4
|
+
data.tar.gz: a25a163f6f1acf4b93bb89c8e97cecfdab762420144680ff9db2bc530e8d2008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c09a5439a6fd13595ce6da57a180c231d815b43264f2ca3c7984923ac0673d9e8f7ffdd3d252224f7a2935083ab572a34ea5abf333f1b6fa636bbdb2aacfa07
|
7
|
+
data.tar.gz: ace2e794f17ea50a2465939a9f1cc2bec46bffd41dd0441d1002e33770ae816a0ccbd5366bdcaf8f19e3cbc02bac136c0bfa8009a8590c2719fa72b9307d2d35
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class ResponseHandler
|
2
|
+
|
3
|
+
def initialize(response, single_from_list: false)
|
4
|
+
@response = response
|
5
|
+
@single_from_list = single_from_list
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :response, :single_from_list
|
9
|
+
|
10
|
+
def parse!
|
11
|
+
success? ? handle_success : handle_error
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def handle_success
|
17
|
+
@payload = payload.data.first if single_from_list
|
18
|
+
|
19
|
+
payload.success = true
|
20
|
+
|
21
|
+
payload
|
22
|
+
end
|
23
|
+
|
24
|
+
def handle_error
|
25
|
+
payload.success = false
|
26
|
+
|
27
|
+
payload
|
28
|
+
end
|
29
|
+
|
30
|
+
def payload
|
31
|
+
@payload ||= JSON.parse(response.body, object_class: OpenStruct)
|
32
|
+
end
|
33
|
+
|
34
|
+
def success?
|
35
|
+
single_from_list ? payload.data&.first.present? : (response.status == 200)
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dooca_commerce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luciano Cesar Cordeiro
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/dooca_commerce.rb
|
34
|
+
- lib/response_handler.rb
|
34
35
|
homepage: https://rubygems.org/gems/doca_commerce
|
35
36
|
licenses:
|
36
37
|
- MIT
|