Class: RedHaze::Client
- Inherits:
-
Object
- Object
- RedHaze::Client
- Includes:
- HTTParty
- Defined in:
- lib/red_haze/client.rb
Constant Summary collapse
- TOKEN_ENDPOINT =
"https://api.soundcloud.com/oauth2/token"
- CONNECT_ENDPOINT =
"https://soundcloud.com/connect"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Instance Method Summary collapse
- #authorize_url ⇒ Object
- #get_token_from_code(code) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/red_haze/client.rb', line 12 def initialize(={}) () update_from_response() end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/red_haze/client.rb', line 6 def access_token @access_token end |
#client_id ⇒ Object
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/red_haze/client.rb', line 6 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
6 7 8 |
# File 'lib/red_haze/client.rb', line 6 def client_secret @client_secret end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
6 7 8 |
# File 'lib/red_haze/client.rb', line 6 def expires_in @expires_in end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
6 7 8 |
# File 'lib/red_haze/client.rb', line 6 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
6 7 8 |
# File 'lib/red_haze/client.rb', line 6 def refresh_token @refresh_token end |
Instance Method Details
#authorize_url ⇒ Object
17 18 19 20 21 |
# File 'lib/red_haze/client.rb', line 17 def raise "Missing redirect_uri" unless redirect_uri params = "client_id=#{client_id}&redirect_uri=#{redirect_uri}&response_type=code" URI.encode "#{CONNECT_ENDPOINT}?#{params}" end |
#get_token_from_code(code) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/red_haze/client.rb', line 23 def get_token_from_code(code) body = { client_id: client_id, client_secret: client_secret, redirect_uri: redirect_uri, code: code, grant_type: 'authorization_code' } response = self.class.post TOKEN_ENDPOINT, body: body, headers: {'Content-Type' => 'application/x-www-form-urlencoded'} raise response.inspect unless response.code == 200 update_from_response(response) self end |