Module: Croudia::Rest::OAuth
- Included in:
- Client
- Defined in:
- lib/croudia/rest/oauth.rb
Instance Method Summary collapse
-
#authorize_url(params = {}) ⇒ String
Returns an authorization url.
-
#refresh(params = {}) ⇒ Croudia::Object::Tokens
Refresh an OAuth 2 Bearer Token.
-
#token(params = {}) ⇒ Croudia::Object::Tokens
Allows a registered application to obtain an OAuth 2 Bearer Token.
Instance Method Details
#authorize_url(params = {}) ⇒ String
Returns an authorization url.
12 13 14 15 16 17 18 |
# File 'lib/croudia/rest/oauth.rb', line 12 def (params = {}) unless (params[:state].nil?) "https://api.croudia.com/oauth/authorize?response_type=code&client_id=#{@client_id}&state=#{params[:state]}" else "https://api.croudia.com/oauth/authorize?response_type=code&client_id=#{@client_id}" end end |
#refresh(params = {}) ⇒ Croudia::Object::Tokens
Refresh an OAuth 2 Bearer Token.
40 41 42 43 44 45 |
# File 'lib/croudia/rest/oauth.rb', line 40 def refresh(params = {}) default_params = {grant_type: 'refresh_token', client_id: @client_id, client_secret: @client_secret } params.merge!(default_params) response = post('oauth/token', params) Croudia::Object::Tokens.new(response) end |
#token(params = {}) ⇒ Croudia::Object::Tokens
Allows a registered application to obtain an OAuth 2 Bearer Token.
26 27 28 29 30 31 32 |
# File 'lib/croudia/rest/oauth.rb', line 26 def token(params = {}) default_params = {grant_type: 'authorization_code', client_id: @client_id, client_secret: @client_secret} params.merge!(default_params) response = post('oauth/token', params) puts response Croudia::Object::Tokens.new(response) end |