Class: Threads::API::OAuth2::Client
- Inherits:
-
Object
- Object
- Threads::API::OAuth2::Client
show all
- Defined in:
- lib/threads/api/oauth2/client.rb
Defined Under Namespace
Classes: LongLivedResponse, ShortLivedResponse
Instance Method Summary
collapse
Constructor Details
#initialize(client_id:, client_secret:) ⇒ Client
Returns a new instance of Client.
8
9
10
11
|
# File 'lib/threads/api/oauth2/client.rb', line 8
def initialize(client_id:, client_secret:)
@client_id = client_id
@client_secret = client_secret
end
|
Instance Method Details
#access_token(code:, redirect_uri:) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/threads/api/oauth2/client.rb', line 13
def access_token(code:, redirect_uri:)
response = connection.post("/oauth/access_token", {
client_id: @client_id,
client_secret: @client_secret,
code: code,
grant_type: "authorization_code",
redirect_uri: redirect_uri
})
ShortLivedResponse.new(*response.body.values_at("access_token", "user_id", "error_type", "error_message", "code"))
end
|
#exchange_access_token(access_token) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/threads/api/oauth2/client.rb', line 25
def exchange_access_token(access_token)
response = connection.get("/access_token", {
client_secret: @client_secret,
grant_type: "th_exchange_token",
access_token: access_token
})
LongLivedResponse.new(*response.body.values_at("access_token", "token_type", "expires_in"))
end
|
#refresh_access_token(access_token) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/threads/api/oauth2/client.rb', line 35
def refresh_access_token(access_token)
response = connection.get("/refresh_access_token", {
grant_type: "th_refresh_token",
access_token: access_token
})
LongLivedResponse.new(*response.body.values_at("access_token", "token_type", "expires_in"))
end
|