Skip to content

Commit

Permalink
Merge pull request #10 from levanto-financial/optional-config
Browse files Browse the repository at this point in the history
Fall back to reasonable default values, for zero-config startup
  • Loading branch information
mike-north committed Mar 8, 2016
2 parents b04de2e + 0dd9928 commit 6878081
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Mix.Config

config :yodlee,
request_handler: Yodlee.Handler,
# request_handler: Yodlee.Handler, # Good for testing w/o hitting the real API
api_base_url: "https://developer.api.yodlee.com/ysl/"

# This configuration is loaded before any dependency and is restricted
Expand Down
7 changes: 6 additions & 1 deletion lib/yodlee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ defmodule Yodlee do
use Application
require Logger

@request_handler Application.get_env(:yodlee, :request_handler)
@request_handler Application.get_env(:yodlee, :request_handler) || Yodlee.Handler
@default_cobrand_name Application.get_env(:yodlee, :default_cobrand_name) || "restserver"

def start do
@request_handler.start
Expand All @@ -13,6 +14,10 @@ defmodule Yodlee do
start
end

def default_cobrand_name do
@default_cobrand_name
end

def as_cob(cob_username, cob_password, x) do
%{"session" => %{
"cobSession" => tok}
Expand Down
10 changes: 5 additions & 5 deletions lib/yodlee/cobrand.ex
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
defmodule Yodlee.Cobrand do
def login(cobrand_login, cobrand_password, cobrand_name \\ "restserver") do
def login(cobrand_login, cobrand_password, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_request("post", "#{cobrand_name}/v1/cobrand/login", %{
"cobrandLogin" => cobrand_login,
"cobrandPassword" => cobrand_password
})
end
def login!(cobrand_login, cobrand_password, cobrand_name \\ "restserver") do
def login!(cobrand_login, cobrand_password, cobrand_name \\ Yodlee.default_cobrand_name) do
{:ok, res} = login(cobrand_login, cobrand_password, cobrand_name)
res
end

def logout(cobrand_token, cobrand_name \\ "restserver") do
def logout(cobrand_token, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_authenticated_request(cobrand_token, "post", "#{cobrand_name}/v1/cobrand/logout")
end

def logout!(cobrand_token, cobrand_name \\ "restserver") do
def logout!(cobrand_token, cobrand_name \\ Yodlee.default_cobrand_name) do
{:ok, r} = logout(cobrand_token, cobrand_name)
r
end

def public_key(cobrand_token, cobrand_name \\ "restserver") do
def public_key(cobrand_token, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_authenticated_request(cobrand_token, "get", "#{cobrand_name}/v1/cobrand/publicKey")
end
end
2 changes: 1 addition & 1 deletion lib/yodlee/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Yodlee.Handler do
use HTTPoison.Base
require Logger

@base Application.get_env(:yodlee, :api_base_url)
@base Application.get_env(:yodlee, :api_base_url) || "https://developer.api.yodlee.com/ysl/"

def start(_type, _args) do
start
Expand Down
4 changes: 2 additions & 2 deletions lib/yodlee/mock_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ defmodule Yodlee.MockHandler do
end

def clear_mock_responses() do
Agent.get_and_update __MODULE__, fn set ->
Agent.get_and_update __MODULE__, fn _ ->
d = HashDict.new
{d, d}
end
end

def make_request(method, endpoint, body \\ [], headers \\ [], options \\ []) do
def make_request(method, endpoint, body \\ [], _headers \\ [], _options \\ []) do
Agent.get __MODULE__, fn set ->
method_ops = HashDict.fetch!(set, method)
handler = HashDict.fetch!(method_ops, endpoint)
Expand Down
3 changes: 2 additions & 1 deletion lib/yodlee/provider.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
defmodule Yodlee.Provider do

def search(cob_session_token, params, cobrand_name \\ "restserver") do
def search(cob_session_token, params, cobrand_name \\ Yodlee.default_cobrand_name) do
do_search cob_session_token, params, cobrand_name
end

defp do_search(cob_session_token, %{"name" => name}, cobrand_name) do
body = %{"name" => name}
Yodlee.make_authenticated_request(cob_session_token, "get", "#{cobrand_name}/v1/providers", body)
Expand Down
5 changes: 3 additions & 2 deletions lib/yodlee/user.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
defmodule Yodlee.User do
def login(cob_session_token, user_login, user_password, cobrand_name \\ "restserver") do

def login(cob_session_token, user_login, user_password, cobrand_name \\ Yodlee.default_cobrand_name) do
Yodlee.make_authenticated_request(cob_session_token, "post", "#{cobrand_name}/v1/user/login", %{
"loginName" => user_login,
"password" => user_password
})
end
def login!(cob_session_token, user_login, user_password, cobrand_name \\ "restserver") do
def login!(cob_session_token, user_login, user_password, cobrand_name \\ Yodlee.default_cobrand_name) do
{:ok, res} = login(cob_session_token, user_login, user_password, cobrand_name)
res
end
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ defmodule Yodlee.Mixfile do

def project do
[app: :yodlee,
version: "0.1.0",
version: "0.1.1",
elixir: "~> 1.1",
description: "Yodlee Aggregation API",
description: "Yodlee API",
package: package,
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down

0 comments on commit 6878081

Please sign in to comment.