Class: Authkeeper::HttpService::Client
- Inherits:
-
Object
- Object
- Authkeeper::HttpService::Client
- 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
-
#post(path:, body: nil, headers: nil) ⇒ Object
rubocop: disable Metrics/AbcSize.
Instance Method Details
#form_post(path:, body: {}, params: {}, headers: {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/lib/authkeeper/http_service/client.rb', line 35 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 headers.each do |header, value| request.headers[header] = 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, headers) { success: response.success?, body: response.body } end |
#post(path:, body: nil, headers: nil) ⇒ Object
rubocop: disable Metrics/AbcSize
26 27 28 29 30 31 32 33 |
# File 'app/lib/authkeeper/http_service/client.rb', line 26 def 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, headers) response.body if response.success? end |