myinfo 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed7daa60be9cb221ff90dc1df8138351c74339935e1c20aaf072924733ba95ee
4
- data.tar.gz: 330f5df3d40c7fcf71e4a688f88b9994bfc212ca4834b896ff41d48e8fb0f41e
3
+ metadata.gz: d5d7dc12ba1a9838d28d91a48cd8a67c9e85431142ae8f5667e12aa01ee00f38
4
+ data.tar.gz: 813f9329ec6de41dcfd08510720e6d9f42b4ca4a2650f5efa285f6a2eac9f527
5
5
  SHA512:
6
- metadata.gz: 2921ef5121d5b616287eb6eacb914d3fa3288122079b89b0bf94d250f3b64a7f868dc7cd4f2da93d5be33f403caa0e42036d515d31af1e7ee59cfc561d458f5d
7
- data.tar.gz: 7fd25c754e169fc8f4ea5d80c464cd2520463ed226f8046270c222a215ffe3217d5b920d4c6875ab114168f05cb6dce1b805b48328a03df4bbb26bddd7a22180
6
+ metadata.gz: a7eb3335c08accd46b642506b28c0c26ea0f998fab3892028aacd7f408a52cf87b961705002d5961e45e263858d7b9bf147e5211a5fbf32a93cc457d770aa78f
7
+ data.tar.gz: 249d333b307dc455bf67572bfc30025bce1a265a0cf9ea2cc2865ffab04dd640a4430c438f5af172c3ae76dcff2da25b50264e232a9269a71d29c0284c3c953e
data/lib/myinfo/v3/api.rb CHANGED
@@ -21,6 +21,12 @@ module MyInfo
21
21
  ''
22
22
  end
23
23
 
24
+ def call
25
+ yield
26
+ rescue StandardError => e
27
+ Response.new(success: false, data: e)
28
+ end
29
+
24
30
  def http_method
25
31
  'GET'
26
32
  end
@@ -54,6 +60,8 @@ module MyInfo
54
60
  else
55
61
  Response.new(success: false, data: "#{response.code} - #{response.body}")
56
62
  end
63
+ rescue StandardError => e
64
+ Response.new(success: false, data: e)
57
65
  end
58
66
 
59
67
  protected
@@ -14,11 +14,13 @@ module MyInfo
14
14
  end
15
15
 
16
16
  def call
17
- headers = header(params: params, access_token: access_token)
18
- endpoint_url = "/#{slug}?#{params.to_query}"
17
+ super do
18
+ headers = header(params: params, access_token: access_token)
19
+ endpoint_url = "/#{slug}?#{params.to_query}"
19
20
 
20
- response = http.request_get(endpoint_url, headers)
21
- parse_response(response)
21
+ response = http.request_get(endpoint_url, headers)
22
+ parse_response(response)
23
+ end
22
24
  end
23
25
 
24
26
  def slug
@@ -15,11 +15,13 @@ module MyInfo
15
15
  end
16
16
 
17
17
  def call
18
- headers = header(params: params)
19
- endpoint_url = "/#{slug}?#{params.to_query}"
18
+ super do
19
+ headers = header(params: params)
20
+ endpoint_url = "/#{slug}?#{params.to_query}"
20
21
 
21
- response = http.request_get(endpoint_url, headers)
22
- parse_response(response)
22
+ response = http.request_get(endpoint_url, headers)
23
+ parse_response(response)
24
+ end
23
25
  end
24
26
 
25
27
  def slug
@@ -4,11 +4,22 @@ module MyInfo
4
4
  module V3
5
5
  # Simple response wrapper
6
6
  class Response
7
- attr_accessor :success, :data
7
+ attr_reader :data
8
8
 
9
9
  def initialize(success:, data:)
10
10
  @success = success
11
- @data = data
11
+
12
+ if data.is_a?(StandardError)
13
+ @data = data.message
14
+ @exception = true
15
+ else
16
+ @data = data
17
+ @exception = false
18
+ end
19
+ end
20
+
21
+ def exception?
22
+ @exception
12
23
  end
13
24
 
14
25
  def success?
@@ -12,10 +12,12 @@ module MyInfo
12
12
  end
13
13
 
14
14
  def call
15
- headers = header(params: params).merge({ 'Content-Type' => 'application/x-www-form-urlencoded' })
16
- response = http.request_post("/#{slug}", params.to_param, headers)
15
+ super do
16
+ headers = header(params: params).merge({ 'Content-Type' => 'application/x-www-form-urlencoded' })
17
+ response = http.request_post("/#{slug}", params.to_param, headers)
17
18
 
18
- parse_response(response)
19
+ parse_response(response)
20
+ end
19
21
  end
20
22
 
21
23
  def http_method
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MyInfo
4
4
  module Version
5
- WRAPPER_VERSION = '0.4.0'
5
+ WRAPPER_VERSION = '0.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lim Yao Jie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-02 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwe