Created
August 2, 2015 02:15
-
-
Save arcreative/4982b180d641d3174c2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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