Module: QuestradeClient
- Defined in:
- lib/questrade_client.rb,
lib/questrade_client/client.rb,
lib/questrade_client/market.rb,
lib/questrade_client/symbol.rb,
lib/questrade_client/account.rb,
lib/questrade_client/version.rb,
lib/questrade_client/questrade/account.rb
Defined Under Namespace
Modules: Account, Market, Symbol Classes: Client, Questrade
Constant Summary collapse
- USER_AGENT =
"questrade_client/#{QuestradeClient::VERSION}".freeze
- VERSION =
'0.0.2'.freeze
Class Method Summary collapse
Class Method Details
.login(refresh_token, practice = false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/questrade_client/client.rb', line 8 def self.login(refresh_token, practice = false) url = if practice "https://practicelogin.questrade.com/oauth2/" else "https://login.questrade.com/oauth2/" end conn = Faraday.new @endpoint do |f| f.headers[:user_agent] = QuestradeClient::USER_AGENT f.headers['Content-length'] = '0' f.response :json, content_type: /\bjson$/ f.adapter Faraday.default_adapter end endpoint = "#{url}token?grant_type=refresh_token&refresh_token=#{refresh_token}" r = conn.send(:post, endpoint) if r.success? # puts "New refresh token: #{r.body['refresh_token']}" endpoint = r.body['api_server'] token = r.body['access_token'] return Client.new(endpoint: endpoint, token: token) else # puts "Login failed!" # puts r.body return nil end end |