Class: Plaider::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/plaider/client.rb

Constant Summary collapse

BASE_URL =
'https://tartan.plaid.com'
DATE_FORMAT =
'%Y-%m-%d'
OPEN_TIMEOUT =
15
READ_TIMEOUT =
120

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
# File 'lib/plaider/client.rb', line 14

def initialize(options={})
  options[:open_timeout] ||= OPEN_TIMEOUT
  options[:read_timeout] ||= READ_TIMEOUT
  options[:verbose] ||= false
  Plaider::Configurable::KEYS.each do |key|
    instance_variable_set(:"@#{key}", !options[key].nil? ? options[key] : Plaider.instance_variable_get(:"@#{key}"))
  end
end

Instance Method Details

#add_user(institution_type, username, password, email) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/plaider/client.rb', line 50

def add_user(institution_type, username, password, email)
  validate(institution_type: institution_type, username: username, password: password, email: email)
  response = post('/connect', {type: institution_type, username: username, password: password, email: email})
  status_code = response[:status_code].to_i
  @access_token = response[:result][:access_token] if [200, 201].include?(status_code)
  response
end

#balanceObject



46
47
48
# File 'lib/plaider/client.rb', line 46

def balance
  post('/balance')
end

#categoriesObject



32
33
34
# File 'lib/plaider/client.rb', line 32

def categories
  get('/categories')
end

#category(category_id) ⇒ Object



36
37
38
39
# File 'lib/plaider/client.rb', line 36

def category(category_id)
  validate(category_id: category_id)
  get("/categories/#{category_id}")
end

#delete_userObject



77
78
79
80
81
# File 'lib/plaider/client.rb', line 77

def delete_user
  response = delete('/connect')
  @access_token = nil
  response
end

#entity(entity_id) ⇒ Object



41
42
43
44
# File 'lib/plaider/client.rb', line 41

def entity(entity_id)
  validate(entity_id: entity_id)
  get("/entities/#{entity_id}")
end

#institution(institution_id) ⇒ Object



27
28
29
30
# File 'lib/plaider/client.rb', line 27

def institution(institution_id)
  validate(institution_id: institution_id)
  get("/institutions/#{institution_id}")
end

#institutionsObject



23
24
25
# File 'lib/plaider/client.rb', line 23

def institutions
  get('/institutions')
end

#transactions(account_id = nil, start_date = nil, end_date = nil, pending = false) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/plaider/client.rb', line 63

def transactions( = nil, start_date = nil, end_date = nil, pending = false)
  params = {}
  params[:account_id] =  if 
  params[:gte] = format_date(start_date)
  params[:lte] = format_date(end_date)
  params[:pending] =  if pending
  post('/connect/get', params)
end

#update_user(username, password) ⇒ Object



72
73
74
75
# File 'lib/plaider/client.rb', line 72

def update_user(username, password)
  validate(username: username, password: password)
  patch('/connect', {username: username, password: password})
end

#user_confirmation(mfa) ⇒ Object



58
59
60
61
# File 'lib/plaider/client.rb', line 58

def user_confirmation(mfa)
  validate(mfa: mfa)
  post('/connect/step', {mfa: mfa})
end