Class: Twitch::OAuth
- Inherits:
-
Object
- Object
- Twitch::OAuth
- Defined in:
- lib/twitch/oauth.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
Instance Method Summary collapse
- #create(grant_type:, scope: nil) ⇒ Object
- #device(scopes:) ⇒ Object
-
#initialize(client_id:, client_secret:) ⇒ OAuth
constructor
A new instance of OAuth.
- #refresh(refresh_token:) ⇒ Object
- #revoke(token:) ⇒ Object
- #validate(token:) ⇒ Object
Constructor Details
#initialize(client_id:, client_secret:) ⇒ OAuth
Returns a new instance of OAuth.
5 6 7 8 |
# File 'lib/twitch/oauth.rb', line 5 def initialize(client_id:, client_secret:) @client_id = client_id @client_secret = client_secret end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
3 4 5 |
# File 'lib/twitch/oauth.rb', line 3 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
3 4 5 |
# File 'lib/twitch/oauth.rb', line 3 def client_secret @client_secret end |
Instance Method Details
#create(grant_type:, scope: nil) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/twitch/oauth.rb', line 10 def create(grant_type:, scope: nil) send_request(url: "https://id.twitch.tv/oauth2/token", body: { client_id: client_id, client_secret: client_secret, grant_type: grant_type, scope: scope }) end |
#device(scopes:) ⇒ Object
28 29 30 |
# File 'lib/twitch/oauth.rb', line 28 def device(scopes:) send_request(url: "https://id.twitch.tv/oauth2/device", body: { client_id: client_id, scope: scopes }) end |
#refresh(refresh_token:) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/twitch/oauth.rb', line 19 def refresh(refresh_token:) send_request(url: "https://id.twitch.tv/oauth2/token", body: { client_id: client_id, client_secret: client_secret, grant_type: "refresh_token", refresh_token: refresh_token }) end |
#revoke(token:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/twitch/oauth.rb', line 40 def revoke(token:) response = Faraday.post("https://id.twitch.tv/oauth2/revoke", { client_id: client_id, token: token }) JSON.parse(response.body, object_class: OpenStruct) if response.status != 200 true end |
#validate(token:) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/twitch/oauth.rb', line 32 def validate(token:) response = Faraday.get("https://id.twitch.tv/oauth2/validate", nil, { "Authorization" => "OAuth #{token}" }) return false if response.status != 200 JSON.parse(response.body, object_class: OpenStruct) end |