Class: QuestradeApi::Authorization
- Inherits:
-
Object
- Object
- QuestradeApi::Authorization
- Includes:
- Util
- Defined in:
- lib/questrade_api/authorization.rb
Overview
Constant Summary collapse
- MODE =
%i(live practice).freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
-
#access_token ⇒ Object
Returns the authorized access token.
-
#initialize(params, mode = :practice) ⇒ Authorization
constructor
Initialize an instance of QuestradeApi::Client.
-
#live? ⇒ Boolean
Checks if selected mode is live.
-
#refresh_token ⇒ Object
Uses refresh_token to fetch a new valid access token.
-
#url ⇒ Object
Returns the server associated with the authorized access token.
Constructor Details
#initialize(params, mode = :practice) ⇒ Authorization
Only access_token, api_server, and refresh_token are needed for this gem.
Initialize an instance of QuestradeApi::Client.
26 27 28 29 30 31 32 33 |
# File 'lib/questrade_api/authorization.rb', line 26 def initialize(params, mode = :practice) raise 'Mode must be :live or :practice' unless MODE.include?(mode) @mode = mode @connection = build_connection build_data(params) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/questrade_api/authorization.rb', line 12 def connection @connection end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/questrade_api/authorization.rb', line 12 def data @data end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
12 13 14 |
# File 'lib/questrade_api/authorization.rb', line 12 def mode @mode end |
Instance Method Details
#access_token ⇒ Object
Returns the authorized access token.
55 56 57 |
# File 'lib/questrade_api/authorization.rb', line 55 def access_token data.access_token end |
#live? ⇒ Boolean
Checks if selected mode is live.
67 68 69 |
# File 'lib/questrade_api/authorization.rb', line 67 def live? mode == :live end |
#refresh_token ⇒ Object
data will be populated accordingly, if call is successful.
Uses refresh_token to fetch a new valid access token.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/questrade_api/authorization.rb', line 40 def refresh_token response = connection.get do |req| req.params[:grant_type] = 'refresh_token' req.params[:refresh_token] = data.refresh_token end if response.status == 200 raw_body = JSON.parse(response.body) build_data(raw_body) end response end |
#url ⇒ Object
Returns the server associated with the authorized access token.
60 61 62 |
# File 'lib/questrade_api/authorization.rb', line 60 def url data.api_server end |