Current section

14 Versions

Jump to

Compare versions

6 files changed
+57 additions
-23 deletions
  @@ -25,3 +25,6 @@ CHANGELOG
25 25
26 26 ---- 0.2.3 / 2014-09-18 / token ------------------------------------------------
27 27 * fix IAM credentials by including token
28 +
29 + ---- 0.2.5 / 2014-09-23 / configurable-version ---------------------------------
30 + * allow configuration of simpledb version
  @@ -87,6 +87,27 @@ By default Simplex will send all requests to the us-east-1 SimpleDB url: `https:
87 87 "https://sdb.us-west-1.amazonaws.com"
88 88 ```
89 89
90 + #### SimpleDB Version
91 +
92 + By default Simplex will use the 2009-04-15 version of the SimpleDB API. If you wish to use a different version you can change it by:
93 +
94 + 1. Setting it from within your application
95 + ```elixir
96 + {:ok, simplex} = Simplex.new
97 + Simplex.simpledb_version(simplex, "2008-02-12")
98 + ```
99 +
100 + 2. Set it as the environment variable `SIMPLEDB_VERSION`
101 + ```
102 + SIMPLEDB_VERSION=2008-02-12 iex -S mix
103 +
104 + iex(1)> {:ok, simplex} = Simplex.new
105 + {:ok, #PID<0.164.0>}
106 + iex(2)> Simplex.simpledb_version(simplex)
107 + "2008-02-12"
108 + ```
109 +
110 +
90 111 ## Responses
91 112
92 113 Simplex will respond to SimpleDB requests with a 3 element tuple, either `{:ok, result, response}` or `{:error, messages, response}`
  @@ -1,5 +1,5 @@
1 1 ---
2 2 major: 0
3 3 minor: 2
4 - patch: 4
4 + patch: 5
5 5 pre:
  @@ -17,4 +17,4 @@
17 17 <<"poison">> => #{<<"optional">> => nil,<<"requirement">> => <<"~> 1.2.0">>},
18 18 <<"sweet_xml">> => #{<<"optional">> => nil,<<"requirement">> => <<"~> 0.1.1">>},
19 19 <<"timex">> => #{<<"optional">> => nil,<<"requirement">> => <<"~> 0.12.5">>}}}.
20 - {<<"version">>,<<"0.2.4">>}.
20 + {<<"version">>,<<"0.2.5">>}.
  @@ -15,12 +15,13 @@ defmodule Simplex do
15 15 |> Map.put_new(:aws_access_key, System.get_env("AWS_ACCESS_KEY"))
16 16 |> Map.put_new(:aws_secret_access_key, System.get_env("AWS_SECRET_ACCESS_KEY"))
17 17 |> Map.put_new(:simpledb_url, System.get_env("SIMPLEDB_URL") || "https://sdb.amazonaws.com")
18 + |> Map.put_new(:simpledb_version, System.get_env("SIMPLEDB_VERSION") || "2009-04-15")
18 19
19 20 GenServer.start_link(__MODULE__, config, options)
20 21 end
21 22
22 23 def aws_access_key(simplex) do
23 - aws_credentials(simplex)[:aws_access_key]
24 + configuration(simplex)[:aws_access_key]
24 25 end
25 26
26 27 def aws_access_key(simplex, access_key) do
  @@ -28,25 +29,33 @@ defmodule Simplex do
28 29 end
29 30
30 31 def aws_secret_access_key(simplex) do
31 - aws_credentials(simplex)[:aws_secret_access_key]
32 + configuration(simplex)[:aws_secret_access_key]
32 33 end
33 34
34 35 def aws_secret_access_key(simplex, secret_access_key) do
35 36 GenServer.call(simplex, {:set_aws_secret_access_key, secret_access_key})
36 37 end
37 38
38 - def aws_credentials(simplex) do
39 - GenServer.call(simplex, :get_aws_credentials)
39 + def configuration(simplex) do
40 + GenServer.call(simplex, :get_configuration)
40 41 end
41 42
42 43 def simpledb_url(simplex) do
43 - GenServer.call(simplex, :get_simpledb_url)
44 + configuration(simplex)[:simpledb_url]
44 45 end
45 46
46 47 def simpledb_url(simplex, url) do
47 48 GenServer.call(simplex, {:set_simpledb_url, url})
48 49 end
49 50
51 + def simpledb_version(simplex) do
52 + configuration(simplex)[:simpledb_version]
53 + end
54 +
55 + def simpledb_version(simplex, version) do
56 + GenServer.call(simplex, {:set_simpledb_version, version})
57 + end
58 +
50 59 defp needs_refresh?(config) do
51 60 expiring?(config) or missing_keys?(config)
52 61 end
  @@ -92,19 +101,15 @@ defmodule Simplex do
92 101 {:ok, config}
93 102 end
94 103
95 - def handle_call(:get_aws_credentials, _from, config) do
104 + def handle_call(:get_configuration, _from, config) do
96 105 if needs_refresh?(config) do
97 106 config = refresh(config)
98 - {:reply, Map.take(config, [:aws_access_key, :aws_secret_access_key, :token]), config}
107 + {:reply, config, config}
99 108 else
100 - {:reply, Map.take(config, [:aws_access_key, :aws_secret_access_key, :token]), config}
109 + {:reply, config, config}
101 110 end
102 111 end
103 112
104 - def handle_call(:get_simpledb_url, _from, config) do
105 - {:reply, config[:simpledb_url], config}
106 - end
107 -
108 113 def handle_call({:set_aws_access_key, access_key}, _from, config) do
109 114 config = config
110 115 |> Map.put(:aws_access_key, access_key)
  @@ -126,6 +131,11 @@ defmodule Simplex do
126 131 {:reply, config[:simpledb_url], config}
127 132 end
128 133
134 + def handle_call({:set_simpledb_version, version}, _from, config) do
135 + config = Map.put(config, :simpledb_version, version)
136 + {:reply, config[:simpledb_version], config}
137 + end
138 +
129 139 def handle_info(_msg, config) do
130 140 {:noreply, config}
131 141 end
Loading more files…