Class: RubyLokaliseApi::OAuth2::Auth

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseRequest

#delete, #get, #patch, #post, #put

Methods included from Connection

#connection

Methods included from JsonHandler

#custom_dump, #custom_load

Constructor Details

#initialize(client_id, client_secret, params = {}) ⇒ Auth

Returns a new instance of Auth.



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

def initialize(client_id, client_secret, params = {})
  @client_id = client_id
  @client_secret = client_secret
  @timeout = params[:timeout]
  @open_timeout = params[:open_timeout]
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

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



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

def open_timeout
  @open_timeout
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

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



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

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

#base_urlObject



48
49
50
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 48

def base_url
  URI('https://app.lokalise.com/oauth2/')
end

#compression?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 52

def compression?
  false
end

#refresh(token) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 39

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

  RubyLokaliseApi::OAuth2::Refresh.new post('token', self, params)
end

#token(code) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 30

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

  RubyLokaliseApi::OAuth2::Token.new post('token', self, params)
end