Class: MyInfo::V3::Api
- Inherits:
-
Object
show all
- Extended by:
- Callable
- Defined in:
- lib/myinfo/v3/api.rb
Overview
Instance Method Summary
collapse
Instance Method Details
#call ⇒ Object
24
25
26
27
28
|
# File 'lib/myinfo/v3/api.rb', line 24
def call
yield
rescue StandardError => e
Response.new(success: false, data: e)
end
|
#endpoint ⇒ Object
12
13
14
|
# File 'lib/myinfo/v3/api.rb', line 12
def endpoint
raise NotImplementedError, 'abstract'
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/myinfo/v3/api.rb', line 38
def (params:, access_token: nil)
{
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Cache-Control' => 'no-cache'
}.tap do |values|
values['Authorization'] = (params: params, access_token: access_token) unless config.sandbox?
if support_gzip?
values['Accept-Encoding'] = 'gzip'
values['Content-Encoding'] = 'gzip'
end
end
end
|
#http_method ⇒ Object
30
31
32
|
# File 'lib/myinfo/v3/api.rb', line 30
def http_method
'GET'
end
|
#params(_args) ⇒ Object
16
17
18
|
# File 'lib/myinfo/v3/api.rb', line 16
def params(_args)
raise NotImplementedError, 'abstract'
end
|
#parse_response(response) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/myinfo/v3/api.rb', line 53
def parse_response(response)
if response.code == '200'
yield
elsif errors.include?(response.code)
json = JSON.parse(response.body)
Response.new(success: false, data: "#{json['code']} - #{json['message']}")
else
Response.new(success: false, data: "#{response.code} - #{response.body}")
end
rescue StandardError => e
Response.new(success: false, data: e)
end
|
#slug ⇒ Object
20
21
22
|
# File 'lib/myinfo/v3/api.rb', line 20
def slug
''
end
|
#support_gzip? ⇒ Boolean
34
35
36
|
# File 'lib/myinfo/v3/api.rb', line 34
def support_gzip?
false
end
|