Class: Yodlicious::YodleeApi
- Inherits:
-
Object
- Object
- Yodlicious::YodleeApi
- Defined in:
- lib/yodlicious/yodlee_api.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#cobranded_password ⇒ Object
readonly
Returns the value of attribute cobranded_password.
-
#cobranded_username ⇒ Object
readonly
Returns the value of attribute cobranded_username.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#proxy_url ⇒ Object
readonly
Returns the value of attribute proxy_url.
Instance Method Summary collapse
- #add_site_account(site_id, site_login_form) ⇒ Object
- #add_site_account_and_wait(site_id, site_login_form, refresh_interval = 0.5, max_trys = 5) ⇒ Object
- #cobranded_auth ⇒ Object
- #cobranded_login ⇒ Object
- #cobranded_session_execute_api(uri, params = {}) ⇒ Object
- #cobranded_session_token ⇒ Object
- #configure(config = {}) ⇒ Object
- #debug_log(msg) ⇒ Object
- #execute_api(uri, params = {}) ⇒ Object
- #execute_user_search_request(options = {}) ⇒ Object
- #get_all_site_accounts ⇒ Object
- #get_content_service_info_by_routing_number(routing_number, no_trim = true) ⇒ Object
- #get_item_summaries ⇒ Object
- #get_item_summaries_for_site(site_account_id) ⇒ Object
- #get_mfa_response_for_site(site_account_id) ⇒ Object
- #get_mfa_response_for_site_and_wait(site_account_id, refresh_interval = 0.5, max_trys = 5) ⇒ Object
- #get_site_info(site_id) ⇒ Object
- #get_site_refresh_info(site_account_id) ⇒ Object
- #get_user_transactions(search_identifier, start_number, end_number) ⇒ Object
- #info_log(msg) ⇒ Object
-
#initialize(config = {}) ⇒ YodleeApi
constructor
A new instance of YodleeApi.
- #login_or_register_user(username, password, email) ⇒ Object
- #logout_user ⇒ Object
- #normal_site_refresh_in_progress?(site_refresh_info) ⇒ Boolean
- #proxy_opts ⇒ Object
- #put_mfa_request_for_site(site_account_id, mfa_type, field_info) ⇒ Object
- #register_user(username, password, emailAddress, options = {}) ⇒ Object
- #search_content_services(search_string) ⇒ Object
- #should_retry_get_mfa_response?(response, try, max_trys) ⇒ Boolean
- #should_retry_get_site_refresh_info?(response, try, max_trys) ⇒ Boolean
- #site_search(search_string) ⇒ Object
- #translator ⇒ Object
- #unregister_user ⇒ Object
- #use_socks? ⇒ Boolean
- #user_auth ⇒ Object
- #user_login(login, pass) ⇒ Object
- #user_session_execute_api(uri, params = {}) ⇒ Object
- #user_session_token ⇒ Object
- #validate(config) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ YodleeApi
Returns a new instance of YodleeApi.
8 9 10 |
# File 'lib/yodlicious/yodlee_api.rb', line 8 def initialize config = {} configure config end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
6 7 8 |
# File 'lib/yodlicious/yodlee_api.rb', line 6 def base_url @base_url end |
#cobranded_password ⇒ Object (readonly)
Returns the value of attribute cobranded_password.
6 7 8 |
# File 'lib/yodlicious/yodlee_api.rb', line 6 def cobranded_password @cobranded_password end |
#cobranded_username ⇒ Object (readonly)
Returns the value of attribute cobranded_username.
6 7 8 |
# File 'lib/yodlicious/yodlee_api.rb', line 6 def cobranded_username @cobranded_username end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/yodlicious/yodlee_api.rb', line 6 def logger @logger end |
#proxy_url ⇒ Object (readonly)
Returns the value of attribute proxy_url.
6 7 8 |
# File 'lib/yodlicious/yodlee_api.rb', line 6 def proxy_url @proxy_url end |
Instance Method Details
#add_site_account(site_id, site_login_form) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/yodlicious/yodlee_api.rb', line 140 def add_site_account site_id, site_login_form params = { siteId: site_id }.merge(translator.site_login_form_to_add_site_account_params(site_login_form)) user_session_execute_api '/jsonsdk/SiteAccountManagement/addSiteAccount1', params end |
#add_site_account_and_wait(site_id, site_login_form, refresh_interval = 0.5, max_trys = 5) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/yodlicious/yodlee_api.rb', line 149 def add_site_account_and_wait site_id, site_login_form, refresh_interval = 0.5, max_trys = 5 add_site_account_response = add_site_account(site_id, site_login_form) if add_site_account_response.success? if normal_site_refresh_in_progress?(add_site_account_response.body['siteRefreshInfo']) site_account_id = add_site_account_response.body['siteAccountId'] try = 1 begin debug_log "try #{try} to get refresh_info for #{site_id}" try += 1 sleep(refresh_interval) refresh_info_response = get_site_refresh_info site_account_id add_site_account_response.body['siteRefreshInfo'] = refresh_info_response.body unless refresh_info_response.fail? end while should_retry_get_site_refresh_info? refresh_info_response, try, max_trys end add_site_account_response end end |
#cobranded_auth ⇒ Object
330 331 332 |
# File 'lib/yodlicious/yodlee_api.rb', line 330 def cobranded_auth @cobranded_auth end |
#cobranded_login ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/yodlicious/yodlee_api.rb', line 46 def cobranded_login params = { cobrandLogin: cobranded_username, cobrandPassword: cobranded_password } response = execute_api '/authenticate/coblogin', params if response.success? @cobranded_auth = response.body else @cobranded_auth = nil end response end |
#cobranded_session_execute_api(uri, params = {}) ⇒ Object
295 296 297 298 299 300 301 |
# File 'lib/yodlicious/yodlee_api.rb', line 295 def cobranded_session_execute_api uri, params = {} params = { cobSessionToken: cobranded_session_token, }.merge(params) execute_api uri, params end |
#cobranded_session_token ⇒ Object
338 339 340 341 |
# File 'lib/yodlicious/yodlee_api.rb', line 338 def cobranded_session_token return nil if cobranded_auth.nil? cobranded_auth.fetch('cobrandConversationCredentials',{}).fetch('sessionToken','dude') end |
#configure(config = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yodlicious/yodlee_api.rb', line 12 def configure config = {} validate config @base_url = config[:base_url] || Yodlicious::Config.base_url @cobranded_username = config[:cobranded_username] || Yodlicious::Config.cobranded_username @cobranded_password = config[:cobranded_password] || Yodlicious::Config.cobranded_password @proxy_url = config[:proxy_url] || Yodlicious::Config.proxy_url @logger = config[:logger] || Yodlicious::Config.logger info_log "YodleeApi configured with base_url=#{base_url} cobranded_username=#{cobranded_username} proxy_url=#{proxy_url} logger=#{logger}" end |
#debug_log(msg) ⇒ Object
348 349 350 |
# File 'lib/yodlicious/yodlee_api.rb', line 348 def debug_log msg logger.debug msg end |
#execute_api(uri, params = {}) ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/yodlicious/yodlee_api.rb', line 311 def execute_api uri, params = {} debug_log "calling #{uri} with #{params}" ssl_opts = { verify: false } connection = Faraday.new(url: base_url, ssl: ssl_opts, request: { proxy: proxy_opts }) response = connection.post("#{base_url}#{uri}", params) debug_log "response=#{response.status} success?=#{response.success?} body=#{response.body} " case response.status when 200 Response.new(JSON.parse(response.body)) else end end |
#execute_user_search_request(options = {}) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/yodlicious/yodlee_api.rb', line 264 def execute_user_search_request = {} params = { 'transactionSearchRequest.containerType' => 'All', 'transactionSearchRequest.lowerFetchLimit' => 1, 'transactionSearchRequest.higherFetchLimit' => 500, 'transactionSearchRequest.resultRange.startNumber' => 1, 'transactionSearchRequest.resultRange.endNumber' => 500, 'transactionSearchRequest.searchClients.clientId' => 1, 'transactionSearchRequest.searchClients.clientName' => 'DataSearchService', 'transactionSearchRequest.ignoreUserInput' => true, #todo make it so that we can pass a simpler hash of arguments # 'transactionSearchRequest.userInput' => nil, # 'transactionSearchRequest.searchFilter.currencyCode' => nil, # 'transactionSearchRequest.searchFilter.postDateRange.fromDate' => nil, # 'transactionSearchRequest.searchFilter.postDateRange.toDate' => nil, # 'transactionSearchRequest.searchFilter.itemAccountId.identifier' => nil, 'transactionSearchRequest.searchFilter.transactionSplitType' => 'ALL_TRANSACTION' }.merge() user_session_execute_api "/jsonsdk/TransactionSearchService/executeUserSearchRequest", params end |
#get_all_site_accounts ⇒ Object
252 253 254 |
# File 'lib/yodlicious/yodlee_api.rb', line 252 def get_all_site_accounts user_session_execute_api '/jsonsdk/SiteAccountManagement/getAllSiteAccounts' end |
#get_content_service_info_by_routing_number(routing_number, no_trim = true) ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'lib/yodlicious/yodlee_api.rb', line 235 def get_content_service_info_by_routing_number routing_number, no_trim = true params = { routingNumber: routing_number, notrim: no_trim } cobranded_session_execute_api '/jsonsdk/RoutingNumberService/getContentServiceInfoByRoutingNumber', params end |
#get_item_summaries ⇒ Object
244 245 246 |
# File 'lib/yodlicious/yodlee_api.rb', line 244 def get_item_summaries user_session_execute_api '/jsonsdk/DataService/getItemSummaries', { 'bridgetAppId' => '10003200' } end |
#get_item_summaries_for_site(site_account_id) ⇒ Object
248 249 250 |
# File 'lib/yodlicious/yodlee_api.rb', line 248 def get_item_summaries_for_site site_account_id user_session_execute_api '/jsonsdk/DataService/getItemSummariesForSite', { memSiteAccId: site_account_id } end |
#get_mfa_response_for_site(site_account_id) ⇒ Object
181 182 183 |
# File 'lib/yodlicious/yodlee_api.rb', line 181 def get_mfa_response_for_site site_account_id user_session_execute_api '/jsonsdk/Refresh/getMFAResponseForSite', { memSiteAccId: site_account_id } end |
#get_mfa_response_for_site_and_wait(site_account_id, refresh_interval = 0.5, max_trys = 5) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/yodlicious/yodlee_api.rb', line 185 def get_mfa_response_for_site_and_wait site_account_id, refresh_interval=0.5, max_trys=5 response = get_mfa_response_for_site site_account_id try = 1 while should_retry_get_mfa_response? response, try, max_trys debug_log "try #{try} to get mfa message for #{site_account_id}" try += 1 sleep(refresh_interval) response = get_mfa_response_for_site site_account_id end response end |
#get_site_info(site_id) ⇒ Object
256 257 258 259 260 261 262 |
# File 'lib/yodlicious/yodlee_api.rb', line 256 def get_site_info site_id params = { 'siteFilter.siteId' => site_id, 'siteFilter.reqSpecifier' => 16 } cobranded_session_execute_api '/jsonsdk/SiteTraversal/getSiteInfo', params end |
#get_site_refresh_info(site_account_id) ⇒ Object
231 232 233 |
# File 'lib/yodlicious/yodlee_api.rb', line 231 def get_site_refresh_info site_account_id user_session_execute_api '/jsonsdk/Refresh/getSiteRefreshInfo', { memSiteAccId: site_account_id } end |
#get_user_transactions(search_identifier, start_number, end_number) ⇒ Object
286 287 288 289 290 291 292 293 |
# File 'lib/yodlicious/yodlee_api.rb', line 286 def get_user_transactions search_identifier, start_number, end_number params = { 'searchFetchRequest.searchIdentifier.identifier' => search_identifier, 'searchFetchRequest.searchResultRange.startNumber' => start_number, 'searchFetchRequest.searchResultRange.endNumber' => end_number } user_session_execute_api '/jsonsdk/TransactionSearchService/getUserTransactions', params end |
#info_log(msg) ⇒ Object
352 353 354 |
# File 'lib/yodlicious/yodlee_api.rb', line 352 def info_log msg logger.info msg end |
#login_or_register_user(username, password, email) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/yodlicious/yodlee_api.rb', line 104 def login_or_register_user username, password, email info_log "attempting to login #{username}" response = user_login(username, password) #TODO look into what other errors could occur here if response.fail? && response.error == "Invalid User Credentials" info_log "invalid credentials for #{username} attempting to register" response = register_user username, password, email end if response.success? @user_auth = response.body else @user_auth = nil end response end |
#logout_user ⇒ Object
80 81 82 |
# File 'lib/yodlicious/yodlee_api.rb', line 80 def logout_user user_session_execute_api '/jsonsdk/Login/logout' end |
#normal_site_refresh_in_progress?(site_refresh_info) ⇒ Boolean
176 177 178 179 |
# File 'lib/yodlicious/yodlee_api.rb', line 176 def normal_site_refresh_in_progress? site_refresh_info return site_refresh_info['siteRefreshMode']['refreshMode'] == 'NORMAL' && ['REFRESH_TRIGGERED','PARTIAL_COMPLETE'].include?(site_refresh_info['siteRefreshStatus']['siteRefreshStatus']) end |
#proxy_opts ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yodlicious/yodlee_api.rb', line 31 def proxy_opts proxy_opts = {} unless proxy_url == nil proxy_opts[:uri] = URI.parse(proxy_url) proxy_opts[:socks] = use_socks? end proxy_opts end |
#put_mfa_request_for_site(site_account_id, mfa_type, field_info) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/yodlicious/yodlee_api.rb', line 203 def put_mfa_request_for_site site_account_id, mfa_type, field_info params = { 'memSiteAccId' => site_account_id, 'userResponse.objectInstanceType' => "com.yodlee.core.mfarefresh.#{mfa_type}" } case mfa_type.to_sym when :MFATokenResponse params['userResponse.token']=field_info['fieldValue'] when :MFAImageResponse params['userResponse.imageString']=field_info['fieldValue'] when :MFAQuesAnsResponse questionsArray = field_info['questionAndAnswerValues'] i = 0 while i < questionsArray.length do puts "questionsArray= #{questionsArray[i].class} #{i}" params["userResponse.quesAnsDetailArray[#{i}].answer"]=questionsArray[i]['fieldValue'] params["userResponse.quesAnsDetailArray[#{i}].answerFieldType"]=questionsArray[i]['answerFieldType'] params["userResponse.quesAnsDetailArray[#{i}].metaData"]=questionsArray[i]['metaData'] params["userResponse.quesAnsDetailArray[#{i}].question"]=questionsArray[i]['question'] params["userResponse.quesAnsDetailArray[#{i}].questionFieldType"]=questionsArray[i]['questionFieldType'] i += 1 end end user_session_execute_api '/jsonsdk/Refresh/putMFARequestForSite', params end |
#register_user(username, password, emailAddress, options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/yodlicious/yodlee_api.rb', line 84 def register_user username, password, emailAddress, = {} params = { 'userCredentials.loginName' => username, 'userCredentials.password' => password, 'userCredentials.objectInstanceType' => 'com.yodlee.ext.login.PasswordCredentials', 'userProfile.emailAddress' => emailAddress #todo add in user preferences }.merge() response = cobranded_session_execute_api "/jsonsdk/UserRegistration/register3", params if response.success? @user_auth = response.body else @user_auth = nil end response end |
#search_content_services(search_string) ⇒ Object
136 137 138 |
# File 'lib/yodlicious/yodlee_api.rb', line 136 def search_content_services search_string user_session_execute_api "/jsonsdk/Search/searchContentServices", { keywords: search_string } end |
#should_retry_get_mfa_response?(response, try, max_trys) ⇒ Boolean
199 200 201 |
# File 'lib/yodlicious/yodlee_api.rb', line 199 def should_retry_get_mfa_response? response, try, max_trys return response.success? && response.body['errorCode'].nil? && response.body['isMessageAvailable'] != true && try < max_trys end |
#should_retry_get_site_refresh_info?(response, try, max_trys) ⇒ Boolean
169 170 171 172 173 174 |
# File 'lib/yodlicious/yodlee_api.rb', line 169 def should_retry_get_site_refresh_info? response, try, max_trys return response.success? && try < max_trys && (response.body['code'] == 801 || (response.body['code'] == 0 && response.body['siteRefreshStatus']['siteRefreshStatus'] != 'REFRESH_COMPLETED' && response.body['siteRefreshStatus']['siteRefreshStatus'] != 'REFRESH_TIMED_OUT' && response.body['siteRefreshStatus']['siteRefreshStatus'] != 'LOGIN_SUCCESS' )) end |
#site_search(search_string) ⇒ Object
132 133 134 |
# File 'lib/yodlicious/yodlee_api.rb', line 132 def site_search search_string user_session_execute_api "/jsonsdk/SiteTraversal/searchSite", { siteSearchString: search_string } end |
#translator ⇒ Object
326 327 328 |
# File 'lib/yodlicious/yodlee_api.rb', line 326 def translator @translator ||= ParameterTranslator.new end |
#unregister_user ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/yodlicious/yodlee_api.rb', line 123 def unregister_user response = user_session_execute_api '/jsonsdk/UserRegistration/unregister' if response.success? @user_auth = nil end response end |
#use_socks? ⇒ Boolean
42 43 44 |
# File 'lib/yodlicious/yodlee_api.rb', line 42 def use_socks? return proxy_url != nil && proxy_url.start_with?('socks') end |
#user_auth ⇒ Object
334 335 336 |
# File 'lib/yodlicious/yodlee_api.rb', line 334 def user_auth @user_auth end |
#user_login(login, pass) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/yodlicious/yodlee_api.rb', line 63 def user_login login, pass params = { login: login, password: pass } response = cobranded_session_execute_api '/authenticate/login', params if response.success? @user_auth = response.body else @user_auth = nil end response end |
#user_session_execute_api(uri, params = {}) ⇒ Object
303 304 305 306 307 308 309 |
# File 'lib/yodlicious/yodlee_api.rb', line 303 def user_session_execute_api uri, params = {} params = { userSessionToken: user_session_token }.merge(params) cobranded_session_execute_api uri, params end |
#user_session_token ⇒ Object
343 344 345 346 |
# File 'lib/yodlicious/yodlee_api.rb', line 343 def user_session_token return nil if user_auth.nil? user_auth.fetch('userContext',{}).fetch('conversationCredentials',{}).fetch('sessionToken',nil) end |
#validate(config) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/yodlicious/yodlee_api.rb', line 23 def validate config [:proxy_url, :base_url, :cobranded_username, :cobranded_password, :logger].each { |key| if config.has_key?(key) && config[key].nil? raise "Invalid config provided to YodleeApi. Values may not be nil or blank." end } end |