Current section

14 Versions

Jump to

Compare versions

6 files changed
+65 additions
-31 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
  @@ -55,14 +55,14 @@ There are two ways to provide your keys to the Simplex library:
55 55 2. Set them as the environment variables `AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY`
56 56 ```
57 57 AWS_ACCESS_KEY=your-access-key AWS_SECRET_ACCESS_KEY=your-secret-access-key iex -S mix
58 -
58 +
59 59 iex(1)> {:ok, simplex} = Simplex.new
60 60 {:ok, #PID<0.164.0>}
61 61 iex(2)> Simplex.aws_access_key(simplex)
62 62 "your-access-key"
63 63 iex(3)> Simplex.aws_secret_access_key(simplex)
64 64 "your-secret-access-key"
65 -
65 +
66 66 ```
67 67
68 68 3. If not provided by the above two methods Simplex will attempt to retrieve keys from [instance metadata](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) if it's running in EC2 and you launched your instance with an IAM role with permission to access SimpleDB.
  @@ -74,19 +74,40 @@ By default Simplex will send all requests to the us-east-1 SimpleDB url: `https:
74 74 1. Setting it from within your application
75 75 ```elixir
76 76 {:ok, simplex} = Simplex.new
77 - Simplex.simpledb_url(simplex, "https://sdb.us-west-1.amazonaws.com")
77 + Simplex.simpledb_url(simplex, "https://sdb.us-west-1.amazonaws.com")
78 78 ```
79 79
80 80 2. Set it as the environment variable `SIMPLEDB_URL`
81 81 ```
82 82 SIMPLEDB_URL=https://sdb.us-west-1.amazonaws.com iex -S mix
83 -
83 +
84 84 iex(1)> {:ok, simplex} = Simplex.new
85 85 {:ok, #PID<0.164.0>}
86 86 iex(2)> Simplex.simpledb_url(simplex)
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}`
  @@ -153,7 +174,7 @@ You can pattern match to determine how to handle the response:
153 174 # The replace tuple indicates that the value should replace the existing
154 175 # value for that attribute, rather than be added to its values
155 176
156 - Simplex.Attributes.put(simplex,
177 + Simplex.Attributes.put(simplex,
157 178 "your_domain",
158 179 "your_item_name",
159 180 %{"some_key" => "some_value",
  @@ -163,7 +184,7 @@ You can pattern match to determine how to handle the response:
163 184
164 185 # put "some_value" in the "some_key" attribute only if
165 186 # "other_key" has the "other_value" value
166 - Simplex.Attributes.put(simplex,
187 + Simplex.Attributes.put(simplex,
167 188 "your_domain",
168 189 "your_item_name",
169 190 %{"some_key" => "some_value"},
  @@ -174,13 +195,13 @@ You can pattern match to determine how to handle the response:
174 195
175 196 ````elixir
176 197 # Delete the "some_value" value from the "some_key" attribute
177 - Simplex.Attributes.delete(simplex,
198 + Simplex.Attributes.delete(simplex,
178 199 "your_domain",
179 200 "your_item_name",
180 201 %{"some_key" => "some_value"})
181 202
182 203 # Delete "your_item_name" if it doesn't have the "some_key" attribute
183 - Simplex.Attributes.delete(simplex,
204 + Simplex.Attributes.delete(simplex,
184 205 "your_domain",
185 206 "your_item_name",
186 207 %{},
  @@ -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…