Skip to content

Commit

Permalink
Merge pull request #14 from levanto-financial/acct-management
Browse files Browse the repository at this point in the history
Account and refresh management
  • Loading branch information
mike-north committed Mar 9, 2016
2 parents a03fdcb + 33b4acc commit 46f9542
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 27 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ end
- [ ] **post** - /{cobrandName}/v1/user/samlLogin
- [x] **post** - /{cobrandName}/v1/user/logout
- [x] **post** - /{cobrandName}/v1/user/login
- [ ] **get** - /{cobrandName}/v1/accounts/{accountId}
- [x] **get** - /{cobrandName}/v1/accounts/{accountId}
- [ ] **post** - /{cobrandName}/v1/accounts/{accountId}
- [ ] **delete** - /{cobrandName}/v1/accounts/{accountId}
- [x] **delete** - /{cobrandName}/v1/accounts/{accountId}
- [ ] **get** - /{cobrandName}/v1/accounts/investmentPlan/investmentOptions
- [ ] **get** - /{cobrandName}/v1/accounts/historicalBalances
- [ ] **get** - /{cobrandName}/v1/accounts
- [x] **get** - /{cobrandName}/v1/accounts
- [ ] **get** - /{cobrandName}/v1/holdings/holdingTypeList
- [ ] **get** - /{cobrandName}/v1/holdings/assetClassificationList
- [ ] **get** - /{cobrandName}/v1/holdings
Expand All @@ -166,9 +166,9 @@ end
- [ ] **get** - /{cobrandName}/v1/statements
- [ ] **get** - /{cobrandName}/v1/derived/holdingSummary
- [ ] **get** - /{cobrandName}/v1/derived/networth
- [ ] **post** - /{cobrandName}/v1/refresh
- [ ] **get** - /{cobrandName}/v1/refresh
- [ ] **get** - /{cobrandName}/v1/refresh/{providerAccountId}
- [x] **post** - /{cobrandName}/v1/refresh
- [x] **get** - /{cobrandName}/v1/refresh
- [x] **get** - /{cobrandName}/v1/refresh/{providerAccountId}

## Installation

Expand All @@ -177,7 +177,7 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed
1. Add yodlee to your list of dependencies in `mix.exs`:

def deps do
[{:yodlee, "~> 0.1.3"}]
[{:yodlee, "~> 0.1.4"}]
end

2. Ensure yodlee is started before your application:
Expand Down
35 changes: 35 additions & 0 deletions lib/yodlee/account.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Yodlee.Account do

def delete(creds, account_id, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_authenticated_request(creds, "delete", "#{cobrand_name}/v1/accounts/#{account_id}")
end

def delete!(creds, account_id, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.throw_on_fail fn ->
delete(creds, account_id, cobrand_name)
end
end

def get(creds, account_id, container_name, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_authenticated_request(creds, "get", "#{cobrand_name}/v1/accounts/#{account_id}", %{
"container" => container_name
})
end

def get!(creds, account_id, container_name, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.throw_on_fail fn ->
get(creds, account_id, container_name, cobrand_name)
end
end

def search(creds, params, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_authenticated_request(creds, "get", "#{cobrand_name}/v1/accounts", params)
end

def search!(creds, params, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.throw_on_fail fn ->
search(creds, params, cobrand_name)
end
end

end
29 changes: 29 additions & 0 deletions lib/yodlee/refresh.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule Yodlee.Refresh do

def begin(creds, account_ids, cobrand_name \\ Yodlee.default_cobrand_name) do
ids_param = cond do
is_list(account_ids) -> Enum.join(account_ids, ",")
true -> Enum.join([account_ids], ",")
end
Yodlee.make_authenticated_request(creds, "post", "#{cobrand_name}/v1/refresh", %{
"accountIds" => ids_param
})
end

def begin!(creds, account_ids, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.throw_on_fail fn ->
begin(creds, account_ids, cobrand_name)
end
end

def get_pending_account_status(creds, provider_account_id, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_authenticated_request(creds, "get", "#{cobrand_name}/v1/refresh/#{provider_account_id}")
end

def get_pending_account_status!(creds, provider_account_id, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.throw_on_fail fn ->
get_pending_account_status(creds, provider_account_id, cobrand_name)
end
end

end
95 changes: 75 additions & 20 deletions test/provider_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ defmodule Yodlee.ProviderTest do

doctest Yodlee.Provider


def finish_refresh(creds, provider_acct_id) do
refresh_result = Yodlee.Refresh.get_pending_account_status! creds, provider_acct_id
case refresh_result["refreshInfo"]["statusCode"] do
801 ->
:timer.sleep(2000)
finish_refresh(creds, provider_acct_id)
0 ->
assert refresh_result["refreshInfo"]["statusCode"] == 0
assert refresh_result["refreshInfo"]["refreshStatus"] == "LOGIN_SUCCESS"
refresh_result
end
end

test "Provider search", c do
creds = c[:creds]
results = Yodlee.Provider.search! creds, "PNC"
Expand All @@ -21,29 +35,70 @@ defmodule Yodlee.ProviderTest do
assert hd(provider_info["provider"])["id"] == 16441
end

test "create user account for provider", c do
test "create user account for provider, get information about it, and delete it", c do
creds = c[:creds]
form_params = %{"provider" => [%{"baseUrl" => "http://64.14.28.129/dag/index.do",
"containerNames" => ["creditCard", "insurance", "tax", "reward", "bill",
"bank", "loan", "investment"],
"favicon" => "https://moneycenter.ydlstatic.com/fastlink/appscenter/siteImage.fastlink.do?access_type=APPS_CENTER_PRODUCTION&siteId=16441&imageType=FAVICON",
"forgetPasswordUrl" => "http://64.14.28.129/dag/index.do", "id" => 16441,
"lastModified" => "2016-03-03T10:16:08Z",
"loginForm" => %{"forgetPasswordURL" => "http://64.14.28.129/dag/index.do",
"formType" => "login", "id" => 16103,
"row" => [%{"field" => [%{"id" => 65499, "isOptional" => false,
"name" => "LOGIN", "type" => "text", "value" => "MyLogin123",
"valueEditable" => true}], "fieldRowChoice" => "0001",
"form" => "0001", "id" => 150862, "label" => "Catalog"},
%{"field" => [%{"id" => 65500, "isOptional" => false,
"name" => "PASSWORD", "type" => "password", "value" => "12oy1odbj12B",
"valueEditable" => true}], "fieldRowChoice" => "0002",
"form" => "0001", "id" => 150863, "label" => "Password"}]},
"loginUrl" => "http://64.14.28.129/dag/index.do",
"logo" => "https://moneycenter.ydlstatic.com/fastlink/appscenter/siteImage.fastlink.do?access_type=APPS_CENTER_PRODUCTION&siteId=16441&imageType=LOGO",
"name" => "Dag Site", "oAuthSite" => false, "status" => "Supported"}]}
form_params = %{"provider": [%{
"id": 16441,
"name": "Dag Site",
"loginUrl": "http://192.168.210.152:9090/dag/index.do",
"baseUrl": "http://www.bakerboyer.com/index.cfm?id=105",
"status": "Supported",
"oAuthSite": false,
"lastModified": "2015-06-17T16:46:32Z",
"forgetPasswordUrl": "http://192.168.210.152:9090/dag/index.do",
"loginForm": %{
"id": 16103,
"forgetPasswordURL": "http://192.168.210.152:9090/dag/index.do",
"formType": "login",
"row": [
%{
"id": 150862,
"label": "Catalog",
"form": "0001",
"fieldRowChoice": "0001",
"field": [
%{
"id": 65499,
"name": "LOGIN",
"type": "text",
"value": "DAPI.site16441.7",
"isOptional": false,
"valueEditable": true
}
]
},
%{
"id": 150863,
"label": "Password",
"form": "0001",
"fieldRowChoice": "0002",
"field": [
%{
"id": 65500,
"name": "PASSWORD",
"type": "password",
"value": "site16441.7",
"isOptional": false,
"valueEditable": true
}
]
}
]
}
}
]}

provider_info = Yodlee.Provider.create_account! creds, 16441, form_params
assert provider_info["providerAccountId"]
provider_acct_id = provider_info["providerAccountId"]

finish_refresh(creds, provider_acct_id)

acct_info = Yodlee.Account.search! creds, %{"container" => "bank", "providerAccountId" => provider_acct_id}

assert acct_info
IO.inspect acct_info

# {:ok, _} = Yodlee.Account.delete creds, acct_id
end
end

0 comments on commit 46f9542

Please sign in to comment.