Module: OldPlaid

Extended by:
Configure
Defined in:
lib/old_plaid.rb,
lib/old_plaid/config.rb,
lib/old_plaid/errors.rb,
lib/old_plaid/version.rb,
lib/old_plaid/connection.rb,
lib/old_plaid/models/info.rb,
lib/old_plaid/models/user.rb,
lib/old_plaid/models/account.rb,
lib/old_plaid/models/balances.rb,
lib/old_plaid/models/category.rb,
lib/old_plaid/models/institution.rb,
lib/old_plaid/models/transaction.rb,
lib/old_plaid/models/exchange_token_response.rb

Defined Under Namespace

Modules: Configure Classes: Account, BadRequest, Balances, Category, Connection, ExchangeTokenResponse, Information, Institution, NotFound, OldPlaidError, RequestFailed, ServerError, Transaction, Unauthorized, User

Constant Summary collapse

VERSION =
'2.8.2'

Constants included from Configure

Configure::KEYS

Instance Attribute Summary

Attributes included from Configure

#customer_id, #environment_location, #secret

Class Method Summary collapse

Methods included from Configure

config

Class Method Details

.add_user(api_level, username, password, type, pin = nil, options = nil) ⇒ Object

API: public Use this to create a new OldPlaid user Required parameters:

api_level, username, password, type

TODO: Rename this to something more descriptive for 2.0, such as ‘create_user`



24
25
26
27
28
29
30
31
32
# File 'lib/old_plaid.rb', line 24

def add_user(api_level, username, password, type, pin = nil, options = nil)
  payload = { username: username, password: password, type: type }

  payload[:pin]     = pin if pin
  payload[:options] = options.is_a?(Hash) ? JSON.generate(options) : options if options

  res = Connection.post(api_level, payload)
  User.build(res, api_level)
end

.category(id = nil) ⇒ Object

API: public Builds an category object and returns when the category details exist



95
96
97
98
# File 'lib/old_plaid.rb', line 95

def category(id = nil)
  res = Connection.get('categories', id)
  id.nil? ? Category.all(res) : Category.new(res)
end

.exchange_token(public_token, account_id = nil) ⇒ Object

API: public Exchange a OldPlaid Link public_token for a OldPlaid access_token Required parameters:

public_token
 (optional)


39
40
41
42
43
44
45
46
# File 'lib/old_plaid.rb', line 39

def exchange_token(public_token,  = nil)
  payload = { public_token: public_token }
  # include the account id, if set
  payload[:account_id] =  if 

  res = Connection.post('exchange_token', payload)
  ExchangeTokenResponse.new(res)
end

.fully_qualified_token(token, institution_type) ⇒ Object

API: public Returns the fully-qualified token based upon type Note: Don’t see this documented in the OldPlaid API docs, need to investigate this



82
83
84
# File 'lib/old_plaid.rb', line 82

def fully_qualified_token(token, institution_type)
  institution_type.nil? ? token : token + '_' + institution_type
end

.institution(id = nil) ⇒ Object

API: public Builds an institution object and returns when the institution details exist



88
89
90
91
# File 'lib/old_plaid.rb', line 88

def institution(id = nil)
  res = Connection.get('institutions', id)
  id.nil? ? Institution.all(res) : Institution.new(res)
end

.set_user(token, api_levels = [], institution_type = nil) ⇒ Object

API: public Use this to restore a user from OldPlaid based upon the access token TODO: Rename this to something more descriptive for 2.0, such as ‘get_user’



51
52
53
54
55
56
57
# File 'lib/old_plaid.rb', line 51

def set_user(token, api_levels=[], institution_type=nil)
  _user = User.new
  _user.access_token = fully_qualified_token(token, institution_type)
  _user.permissions = api_levels
  api_levels.each { |l| _user.get(l) }
  _user
end

.transactions(token, options = {}) ⇒ Object

API: public Given an access code and query options, use this to get a dataset of transactions and accounts for # a given user. See /connect/get endpoint

Returns a User object with accounts and transactions within the date range given Examples:

OldPlaid.transactions 'test_wells', account: 'QPO8Jo8vdDHMepg41PBwckXm4KdK1yUdmXOwK'


67
68
69
70
71
72
73
74
75
76
77
# File 'lib/old_plaid.rb', line 67

def transactions(token, options = {})
  _user = User.new
  _user.access_token = token
  _user.permit! 'connect'

  # TODO: For 2.0, submit all data as JSON
  options = JSON.generate(options) if options.kind_of?(Hash)

  _user.get_connect(options: options)
  _user
end