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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/response_handler.rb +37 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb05b281b4833e7e98c7f4c4557d72324132191638cd7bbc6abfc256e12b48ec
4
- data.tar.gz: fb8e384411649ca865657a0cc9845901b44464ddf0ddea3ff477365e0beb738d
3
+ metadata.gz: 89deab28dafe36c32e9d8f1f815ef436c86915c950a5f700e7606cc17205f825
4
+ data.tar.gz: a25a163f6f1acf4b93bb89c8e97cecfdab762420144680ff9db2bc530e8d2008
5
5
  SHA512:
6
- metadata.gz: 809b7d6bc5f214db09999fa34834f0df8d5ee66c435e76666d1d4d6f2f2ecd8ad249ac9654355976c85ea0cdc348740edf01128b6b8d068ea45603f83ffadad2
7
- data.tar.gz: 8c9cc86a2db205966e8fcc2441de4ed11d82ff30ce791e52c121384bbbf0d82fd923a419a8679c9a5f6fe8d9e6c0e8709b7ee681ac152119ad8164e76fed46d6
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.1
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