diff --git a/README.md b/README.md index c20d2b6..008d940 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/lib/mws/endpoints/product.ex b/lib/mws/endpoints/product.ex index a81139d..7ecfe84 100644 --- a/lib/mws/endpoints/product.ex +++ b/lib/mws/endpoints/product.ex @@ -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])