This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from hellodigit/json-responses
v1.0
- Loading branch information
Showing
27 changed files
with
1,797 additions
and
101 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,93 @@ | ||
_ = require "lodash" | ||
Request = require "./request" | ||
|
||
BASE_URL = "https://financialdatafeed.platform.intuit.com/v1" | ||
|
||
zeroBased = (number) -> | ||
("0" + number).slice(-2) | ||
|
||
# 2015-07-29 | ||
formatDate = (date) -> | ||
year = date.getFullYear() | ||
month = zeroBased date.getMonth() + 1 | ||
day = zeroBased date.getDate() | ||
"#{year}-#{month}-#{day}" | ||
|
||
module.exports = class IntuitClient | ||
constructor: (@options) -> | ||
|
||
request: (method, path, body, done) -> | ||
[body, done] = [{}, body] if typeof(body) is "function" | ||
new Request(@options)[method]("#{BASE_URL}#{path}", body, done) | ||
|
||
institutions: (done) -> | ||
@request "get", "/institutions", done | ||
institutions: (userId, done) -> | ||
@options.userId = userId | ||
@request "get", "/institutions", (err, response) -> | ||
return done err if err | ||
done err, response.institution | ||
|
||
getInstitutionDetails: (institutionId, done) -> | ||
getInstitutionDetails: (userId, institutionId, done) -> | ||
@options.userId = userId | ||
@request "get", "/institutions/#{institutionId}", done | ||
|
||
discoverAndAddAccounts: (institutionId, credentials, done) -> | ||
@request "post", "/institutions/#{institutionId}/logins", credentials, done | ||
discoverAndAddAccounts: (userId, institutionId, credentials, done) -> | ||
@options.userId = userId | ||
@request "post", "/institutions/#{institutionId}/logins", credentials, (err, response) -> | ||
return done err if err | ||
if response.challenge | ||
done err, response | ||
else | ||
done err, response.accounts | ||
|
||
handleMfa: (userId, institutionId, challengeSessionId, challengeNodeId, answers, done) -> | ||
@options.headers = | ||
challengeSessionId: challengeSessionId | ||
challengeNodeId: challengeNodeId | ||
@request "post", "/institutions/#{institutionId}/logins", answers, (err, response) -> | ||
return done err if err | ||
done err, response.accounts | ||
|
||
getCustomerAccounts: (userId, done) -> | ||
@options.userId = userId | ||
@request "get", "/accounts", (err, response) -> | ||
return done err if err | ||
done err, response.accounts | ||
|
||
getAccount: (userId, accountId, done) -> | ||
@options.userId = userId | ||
@request "get", "/accounts/#{accountId}", (err, response) -> | ||
return done err if err | ||
done err, _.first response.accounts | ||
|
||
# Download last week of transactions unless a date range is specified | ||
# If no endDate is specified, startDate to current is downloaded | ||
getAccountTransactions: (userId, accountId, startDate, endDate, done) -> | ||
oneWeekAgo = -10080 | ||
defaultStartDate = formatDate new Date(new Date().getTime() + oneWeekAgo * 60000) | ||
|
||
getCustomerAccounts: (done) -> | ||
@request "get", "/accounts", done | ||
if typeof(startDate) is "function" | ||
[startDate, endDate, done] = [defaultStartDate, null, startDate] | ||
else if typeof(endDate) is "function" | ||
[startDate, endDate, done] = [formatDate(startDate), null, endDate] | ||
else | ||
[startDate, endDate, done] = [formatDate(startDate), formatDate(endDate), done] | ||
|
||
getAccount: (accountId, done) -> | ||
@request "get", "/accounts/#{accountId}", done | ||
url = "/accounts/#{accountId}/transactions?txnStartDate=#{startDate}" | ||
url += "&txnEndDate=#{endDate}" if endDate | ||
|
||
getAccountTransactions: (accountId, startDate, endDate) -> | ||
@request "get", "/accounts/#{accountId}/transactions", done | ||
@options.userId = userId | ||
@request "get", url, (err, response) -> | ||
return done err if err | ||
done err, response.bankingTransactions | ||
|
||
updateInstitutionLogin: (institutionId, loginId, credentials, done) -> | ||
updateInstitutionLogin: (userId, institutionId, loginId, credentials, done) -> | ||
@options.userId = userId | ||
@request "put", "/logins/#{loginId}?refresh=true", credentials, done | ||
|
||
deleteAccount: (accountId, done) -> | ||
deleteAccount: (userId, accountId, done) -> | ||
@options.userId = userId | ||
@request "delete", "/accounts/#{accountId}", done | ||
|
||
deleteCustomer: -> | ||
deleteCustomer: (userId, done) -> | ||
@options.userId = userId | ||
@request "delete", "/customers", done |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.