Class: Authkeeper::HttpService::Client
- Inherits:
-
Object
- Object
- Authkeeper::HttpService::Client
show all
- Defined in:
- app/lib/authkeeper/http_service/client.rb
Direct Known Subclasses
DiscordApi::Client, DiscordAuthApi::Client, GithubApi::Client, GithubAuthApi::Client, GitlabApi::Client, GitlabAuthApi::Client, GoogleApi::Client, GoogleAuthApi::Client, VkAuthApi::Client, YandexApi::Client, YandexAuthApi::Client
Instance Method Summary
collapse
-
#form_post(path:, body: {}, params: {}, headers: {}) ⇒ Object
-
#get(path:, params: nil, headers: nil) ⇒ Object
-
#no_params_post(path:, body: nil, headers: nil) ⇒ Object
-
#post(path:, body: {}, params: {}, headers: {}) ⇒ Object
rubocop: disable Metrics/AbcSize.
Instance Method Details
#form_post(path:, body: {}, params: {}, headers: {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/lib/authkeeper/http_service/client.rb', line 51
def form_post(path:, body: {}, params: {}, headers: {})
if Rails.env.test? && connection.adapter != 'Faraday::Adapter::Test'
raise StandardError, 'please stub request in test env'
end
response = connection.post(path) do |request|
params.each do |param, value|
request.params[param] = value
end
.each do |, value|
request.[] = value
end
request.body = URI.encode_www_form(body)
end
response.body if response.success?
end
|
#get(path:, params: nil, headers: nil) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/lib/authkeeper/http_service/client.rb', line 13
def get(path:, params: nil, headers: nil)
if Rails.env.test? && connection.adapter != 'Faraday::Adapter::Test'
raise StandardError, 'please stub request in test env'
end
response = connection.get(path, params, )
{
success: response.success?,
body: response.body
}
end
|
#no_params_post(path:, body: nil, headers: nil) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'app/lib/authkeeper/http_service/client.rb', line 25
def no_params_post(path:, body: nil, headers: nil)
if Rails.env.test? && connection.adapter != 'Faraday::Adapter::Test'
raise StandardError, 'please stub request in test env'
end
response = connection.post(path, body, )
response.body if response.success?
end
|
#post(path:, body: {}, params: {}, headers: {}) ⇒ Object
rubocop: disable Metrics/AbcSize
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/lib/authkeeper/http_service/client.rb', line 34
def post(path:, body: {}, params: {}, headers: {}) if Rails.env.test? && connection.adapter != 'Faraday::Adapter::Test'
raise StandardError, 'please stub request in test env'
end
response = connection.post(path) do |request|
params.each do |param, value|
request.params[param] = value
end
.each do |, value|
request.[] = value
end
request.body = body.to_json
end
response.body if response.success?
end
|