From 6fc98c3952824da98197622df54c8830c398dcd3 Mon Sep 17 00:00:00 2001 From: Mike North Date: Tue, 8 Mar 2016 18:15:59 +0800 Subject: [PATCH] User registeration and de-registration --- README.md | 36 ++++++++++++++++++++++++++++++++++-- lib/yodlee/user.ex | 26 ++++++++++++++++++++++++++ mix.exs | 2 +- test/auth_test.exs | 2 +- 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 990697e..bd40042 100644 --- a/README.md +++ b/README.md @@ -93,16 +93,48 @@ end ``` +Or you could create and then immediately delete a user + +```ex + +case Yodlee.as_cob( + System.get_env("COBRAND_USERNAME"), + System.get_env("COBRAND_PASSWORD"), fn cob_tok -> + + IO.puts "======== CREATE A USER ========" + + {:ok, new_user} = Yodlee.User.create cob_tok, %{ + "user" => %{ + "loginName" => "mike-logina", + "password" => "aho12eoed12d$$Aa", + "email" => "test-1241nd12a@example.com"}} + + + + IO.puts "======== AND DELETE IT ========" + + user_tok = new_user["user"]["session"]["userSession"] + Yodlee.User.delete cob_tok, user_tok + + new_user + end) do + {:ok, result} -> + IO.inspect result + {:error, err} -> raise err +end + +``` + ## API Coverage - [x] **get** - /{cobrandName}/v1/cobrand/publicKey - [x] **post** - /{cobrandName}/v1/cobrand/logout - [x] **post** - /{cobrandName}/v1/cobrand/login -- [ ] **post** - /{cobrandName}/v1/user/register +- [x] **post** - /{cobrandName}/v1/user/register - [ ] **get** - /{cobrandName}/v1/user - [ ] **get** - /{cobrandName}/v1/user/credentials/token - [ ] **post** - /{cobrandName}/v1/user/credentials -- [ ] **delete** - /{cobrandName}/v1/user/unregister +- [x] **delete** - /{cobrandName}/v1/user/unregister - [ ] **post** - /{cobrandName}/v1/user/samlRegister - [ ] **post** - /{cobrandName}/v1/user/samlLogin - [x] **post** - /{cobrandName}/v1/user/logout diff --git a/lib/yodlee/user.ex b/lib/yodlee/user.ex index 945c545..b09f0be 100644 --- a/lib/yodlee/user.ex +++ b/lib/yodlee/user.ex @@ -10,4 +10,30 @@ defmodule Yodlee.User do {:ok, res} = login(cob_session_token, user_login, user_password, cobrand_name) res end + + # Returns: + # { + # "user": { + # "id": 25890176, + # "loginName": "levanto-12312a", + # "name": {}, + # "session": { + # "userSession": "06102015_0:d8744eff21d68ab60497ae1bbcfd5c7a59a69e75ac4625c8d3b8ccd4639ee6ee5c6a8df0dde8f91c9c03d48fe4b5e748f440bd521741f8958df07599f5b805e5" + # }, + # "preferences": { + # "currency": "USD", + # "timeZone": "PST", + # "dateFormat": "MM/dd/yyyy" + # } + # } + # } + def create(cob_session_token, params, cobrand_name \\ Yodlee.default_cobrand_name) do + Yodlee.make_authenticated_request(cob_session_token, "post", "#{cobrand_name}/v1/user/register", %{ + "registerParam" => Poison.encode!(params) + }) + end + + def delete(cob_session_token, user_session_token, cobrand_name \\ Yodlee.default_cobrand_name) do + Yodlee.make_authenticated_request({cob_session_token, user_session_token}, "delete", "#{cobrand_name}/v1/user/unregister") + end end diff --git a/mix.exs b/mix.exs index 483c7ee..d18aef9 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule Yodlee.Mixfile do def project do [app: :yodlee, - version: "0.1.1", + version: "0.1.2", elixir: "~> 1.1", description: "Yodlee API", package: package, diff --git a/test/auth_test.exs b/test/auth_test.exs index f769bc0..2829787 100644 --- a/test/auth_test.exs +++ b/test/auth_test.exs @@ -4,7 +4,7 @@ defmodule YodleeAuthTest do doctest Yodlee.Cobrand test "successful cobrand login" do - Yodlee.MockHandler.add_mock_response "post", "restserver/v1/cobrand/login", fn _ -> + Yodlee.MockHandler.add_mock_response "post", "#{Yodlee.default_cobrand_name}/v1/cobrand/login", fn _ -> {:ok, %{ "applicationId" => "3A4CAE9B71A1CCD7FF41F51006E9ED00", "cobrandId" => 1111,