Class: Kuvera::Api::Oauth
- Inherits:
-
Object
- Object
- Kuvera::Api::Oauth
- Defined in:
- lib/kuvera/api/oauth.rb
Constant Summary collapse
- DEFAULT_CONTENT_TYPE =
{ 'Content-Type' => 'application/json' }.freeze
- FATAL_ERROR_MESSAGE =
{ 'error' => 'Internal error' }.freeze
- CLIENT_SCOPE =
'ext_app'
Instance Method Summary collapse
- #get(url, params = {}) ⇒ Object
-
#initialize(uid:, secret:, host:) ⇒ Oauth
constructor
A new instance of Oauth.
- #post(url, body, headers: DEFAULT_CONTENT_TYPE.dup) ⇒ Object
Constructor Details
#initialize(uid:, secret:, host:) ⇒ Oauth
Returns a new instance of Oauth.
13 14 15 16 17 18 19 20 21 |
# File 'lib/kuvera/api/oauth.rb', line 13 def initialize(uid:, secret:, host:) @oauth_client = OAuth2::Client.new( uid, secret, site: host, token_method: :post ) do |stack| stack.request :multipart stack.request :url_encoded stack.adapter Faraday.default_adapter end end |
Instance Method Details
#get(url, params = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/kuvera/api/oauth.rb', line 23 def get(url, params = {}) token.get(url, params: params).parsed rescue OAuth2::Error => error process_exception(error) end |
#post(url, body, headers: DEFAULT_CONTENT_TYPE.dup) ⇒ Object
29 30 31 32 33 |
# File 'lib/kuvera/api/oauth.rb', line 29 def post(url, body, headers: DEFAULT_CONTENT_TYPE.dup) token.post(url, headers: headers, body: body).parsed rescue OAuth2::Error => error process_exception(error) end |