Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ def deps do
end
```

## Configuration

```elixir
config :mws,
seller_id: "xxxx",
marketplace_id: "xxxx",
access_key_id: "xxxx",
secret_key: "xxxx",
mws_auth_token: "xxxx"
```

## Example Usage

```elixir
config = %Mws.Config{
endpoint: Mws.Config.endpoint(:europe),
seller_id: Application.get_env(:mws, :seller_id),
marketplace_id: Application.get_env(:mws, :marketplace_id),
access_key_id: Application.get_env(:mws, :access_key_id),
secret_key: Application.get_env(:mws, :secret_key),
mws_auth_token: Application.get_env(:mws, :mws_auth_token)
}

Note, `endpoint` (from above) can be one of `:europe`, `:north_america`, `:india`, `:china`, `:japan`.

{:ok, pid} = Mws.Client.start_link(config)

response = Mws.Product.get_matching_product(pid, "B017R5CP1C")
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/mws](https://hexdocs.pm/mws).
Expand Down
33 changes: 33 additions & 0 deletions lib/mws/endpoints/product.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
defmodule Mws.Product do
@doc """
Lists products matching a given `search_term`. This can
be optionally limited to a given `context`.

## Parameters

- conn: pid of the client
- search_term: String representing a standard amazon search term
- context: String representing an amazon QueryContextId
more here: http://docs.developer.amazonservices.com/en_UK/products/Products_QueryContextIDs.html
defaults to "All"

## Examples

iex> Mws.Product.list_matching_products(pid, "Harry potter")
%{body: %{...}, %{header: %{...}}}
"""
def list_matching_products(conn, search_term, context \\ "All") do
query =
%{
"Action" => "ListMatchingProducts",
"Version" => "2011-10-01",
"Query" => search_term,
"QueryContextId" => context
}

url = %URI{
path: "/Products/2011-10-01",
query: query
}

Mws.Client.request(conn, :post, url)
end

def get_matching_product(conn, asin) when is_bitstring(asin),
do: get_matching_product(conn, [asin])
Expand Down