Module: Mercadolibre::Core::Oauth

Included in:
Api
Defined in:
lib/mercadolibre/core/oauth.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(auth_code) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mercadolibre/core/oauth.rb', line 14

def authenticate(auth_code)
  response = post_request('/oauth/token', {
    grant_type: 'authorization_code',
    client_id: @app_key,
    client_secret: @app_secret,
    code: auth_code,
    redirect_uri: @callback_url
  })

  @access_token = response.body.access_token
  response.body.expiration_time = (Time.now + response.body.expires_in.to_i)
  response.body
end

#authenticate_urlObject



4
5
6
7
8
9
10
11
12
# File 'lib/mercadolibre/core/oauth.rb', line 4

def authenticate_url
  get_attrs = {
    response_type: 'code',
    client_id: @app_key,
    redirect_uri: CGI.escape(@callback_url)
  }.map { |k,v| "#{k}=#{v}" }.join('&')

  "#{@auth_url}/authorization?#{get_attrs}"
end

#update_token(refresh_token) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mercadolibre/core/oauth.rb', line 28

def update_token(refresh_token)
  response = post_request('/oauth/token', {
    grant_type: 'refresh_token',
    client_id: @app_key,
    client_secret: @app_secret,
    refresh_token: refresh_token
  })

  @access_token = response.body.access_token
  response.body.expiration_time = (Time.now + response.body.expires_in.to_i)
  response.body
end