Class: RubyLokaliseApi::OAuth2::Auth

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/ruby_lokalise_api/oauth2/auth.rb

Constant Summary

Constants included from Connection

Connection::BASE_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#post

Methods included from Connection

#connection

Methods included from JsonHandler

#custom_dump, #custom_load

Constructor Details

#initialize(client_id, client_secret) ⇒ Auth

Returns a new instance of Auth.



10
11
12
13
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 10

def initialize(client_id, client_secret)
  @client_id = client_id
  @client_secret = client_secret
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



8
9
10
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 8

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



8
9
10
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 8

def client_secret
  @client_secret
end

Instance Method Details

#auth(scope:, redirect_uri: nil, state: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 15

def auth(scope:, redirect_uri: nil, state: nil)
  scope = scope.join(' ') if scope.is_a?(Array)

  params = {
    client_id: client_id,
    scope: scope
  }
  params[:state] = state unless state.nil?
  params[:redirect_uri] = redirect_uri unless redirect_uri.nil?

  _build_url_from params
end

#refresh(token) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 36

def refresh(token)
  params = base_params.merge({
                               refresh_token: token,
                               grant_type: 'refresh_token'
                             })
  post 'token', params
end

#token(code) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 28

def token(code)
  params = base_params.merge({
                               code: code,
                               grant_type: 'authorization_code'
                             })
  post 'token', params
end