Module: Tastytrade::Authentication
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#access_token_expires_at ⇒ Object
readonly
Returns the value of attribute access_token_expires_at.
-
#authorization_code ⇒ Object
readonly
Returns the value of attribute authorization_code.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#redirect_uri ⇒ Object
readonly
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #default_headers ⇒ Object
-
#refresh_access_token ⇒ Object
Refresh tokens never expire per TastyTrade docs.
-
#request_access_token(authorization_grant_code) ⇒ Object
Returns a hash with access_token, refresh_token, expires_in, etc.
Methods included from Util
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/tastytrade/authentication.rb', line 8 def access_token @access_token end |
#access_token_expires_at ⇒ Object (readonly)
Returns the value of attribute access_token_expires_at.
8 9 10 |
# File 'lib/tastytrade/authentication.rb', line 8 def access_token_expires_at @access_token_expires_at end |
#authorization_code ⇒ Object (readonly)
Returns the value of attribute authorization_code.
8 9 10 |
# File 'lib/tastytrade/authentication.rb', line 8 def @authorization_code end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
8 9 10 |
# File 'lib/tastytrade/authentication.rb', line 8 def client_id @client_id end |
#redirect_uri ⇒ Object (readonly)
Returns the value of attribute redirect_uri.
8 9 10 |
# File 'lib/tastytrade/authentication.rb', line 8 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
8 9 10 |
# File 'lib/tastytrade/authentication.rb', line 8 def refresh_token @refresh_token end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
8 9 10 |
# File 'lib/tastytrade/authentication.rb', line 8 def secret @secret end |
Instance Method Details
#default_headers ⇒ Object
11 12 13 |
# File 'lib/tastytrade/authentication.rb', line 11 def default_headers { 'Content-Type': 'application/x-www-form-urlencoded' } end |
#refresh_access_token ⇒ Object
Refresh tokens never expire per TastyTrade docs.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tastytrade/authentication.rb', line 45 def refresh_access_token = { body: { 'grant_type' => 'refresh_token', 'refresh_token' => refresh_token, 'client_secret' => secret }, headers: default_headers } response = HTTParty.post( "#{Tastytrade::BASE_URL}/oauth/token", ) update_tokens(response) response end |
#request_access_token(authorization_grant_code) ⇒ Object
Returns a hash with access_token, refresh_token, expires_in, etc. Used for trusted partner applications that have obtained an authorization code.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tastytrade/authentication.rb', line 17 def request_access_token() = { body: { 'grant_type' => 'authorization_code', 'code' => , 'client_id' => client_id, 'client_secret' => secret, 'redirect_uri' => redirect_uri }, headers: default_headers } response = HTTParty.post( "#{Tastytrade::BASE_URL}/oauth/token", ) unless response_success?(response) raise Tastytrade::APIError.new( "Unable to retrieve access tokens from API - #{response.code} - #{response.body}" ) end update_tokens(response) response end |