Module: Croudia::Rest::OAuth

Included in:
Client
Defined in:
lib/croudia/rest/oauth.rb

Instance Method Summary collapse

Instance Method Details

#authorize_url(params = {}) ⇒ String

Returns an authorization url.

Parameters:

  • params (Hash) (defaults to: {})

    A customized options.

Options Hash (params):

  • :state (String)

    OAuth 2 Authorization State Code.

Returns:

  • (String)

    Authorization url.



12
13
14
15
16
17
18
# File 'lib/croudia/rest/oauth.rb', line 12

def authorize_url(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.

Parameters:

  • params (Hash) (defaults to: {})

    A customized options.

Options Hash (params):

  • :refresh_token (String)

    OAuth 2 refresh token.

Returns:

See Also:



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.

Parameters:

  • params (Hash) (defaults to: {})

    A customized options.

Options Hash (params):

  • :code (String)

    Authorization code of application.

Returns:

See Also:



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