lib/iron_warbler.rb in iron_warbler-2.0.7.41 vs lib/iron_warbler.rb in iron_warbler-2.0.7.42

- old
+ new

@@ -3,10 +3,15 @@ require 'haml' require 'mongoid' require "iro/engine" +class Schwab + include HTTParty + debug_output $stdout +end + class Iro::Iro def self.get_coins out = HTTParty.get( "https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?slug=bitcoin,ethereum", { headers: { 'X-CMC_PRO_API_KEY' => COINMARKETCAP[:key] }, @@ -159,7 +164,37 @@ print '^' end end end end + + def self.schwab_sync + profile = Wco::Profile.find_by email: 'piousbox@gmail.com' + out = Schwab.post( "https://api.schwabapi.com/v1/oauth/token", { + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + basic_auth: { username: SCHWAB_DATA[:key], password: SCHWAB_DATA[:secret] }, + body: { + grant_type: 'refresh_token', + refresh_token: profile.schwab_refresh_token + }, + }) + out = out.parsed_response + puts! out, 'out' + + attrs = { + schwab_access_token: out['access_token'], + schwab_refresh_token: out['refresh_token'], + schwab_id_token: out['id_token'], + } + # puts! attrs, 'attrs' + + if attrs[:schwab_refresh_token] + profile.update(attrs) + profile.save! + return attrs + else + return false + end + end + end