Class: AddonsApi::Client::OAuth::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/addons-api/client.rb

Overview

Token

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Token

Returns a new instance of Token.



128
129
130
# File 'lib/addons-api/client.rb', line 128

def initialize(client)
  @client = client
end

Instance Method Details

#create(client, code) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/addons-api/client.rb', line 132

def create(client, code)
  path =  "#{BASE_PATH}/token"
  token = @client.request(:post, path, body: { 
    code: code,
    grant_type: "authorization_code",
    client_id: client[:id],
    client_secret: client[:secret],
  })
  token
end

#refresh(client, refresh_token) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/addons-api/client.rb', line 143

def refresh(client, refresh_token)
  path =  "#{BASE_PATH}/token"
  token = @client.request(:post, path, body: { 
    refresh_token: refresh_token,
    grant_type: "refresh_token",
    client_id: client[:id],
    client_secret: client[:secret],
  })
  token
end