Skip to content

Instantly share code, notes, and snippets.

@arcreative
Created August 2, 2015 02:15
Show Gist options
  • Save arcreative/4982b180d641d3174c2c to your computer and use it in GitHub Desktop.
Save arcreative/4982b180d641d3174c2c to your computer and use it in GitHub Desktop.
require 'httparty'
class Plaid
class << self
def connect(username, password, institution, options = {})
# Login only unless otherwise specified
options[:login_only] ||= true
options[:webhook] ||= ENV['PLAID_WEBHOOK_URL'] if ENV['PLAID_WEBHOOK_URL']
# Form request options
request_options = {
body: {
client_id: ENV['PLAID_CUSTOMER_ID'],
secret: ENV['PLAID_SECRET'],
username: username,
password: password,
type: institution,
options: options
}
}
# Request
HTTParty.post(plaid_url + '/connect', request_options)
end
def submit_mfa(access_token, mfa_response, options = {})
request_options = {
body: {
client_id: ENV['PLAID_CUSTOMER_ID'],
secret: ENV['PLAID_SECRET'],
access_token: access_token,
mfa: mfa_response,
options: options
}
}
# Request
HTTParty.post(plaid_url + '/connect/step', request_options)
end
def get(access_token, options = {})
# Form request options
request_options = {
body: {
client_id: ENV['PLAID_CUSTOMER_ID'],
secret: ENV['PLAID_SECRET'],
access_token: access_token,
options: options
}
}
# Request
HTTParty.post(plaid_url + '/connect/get', request_options)
end
def plaid_url
ENV['PLAID_ENV'] == 'production' ? 'https://api.plaid.com' : 'https://tartan.plaid.com'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment