Skip to content

Commit

Permalink
Merge pull request #18 from mbramson/switch-encoder-to-jason
Browse files Browse the repository at this point in the history
Switch encoder to jason
  • Loading branch information
mbramson authored Dec 18, 2018
2 parents 9c6dc0f + 7b40e19 commit a53c1fc
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 14 deletions.
12 changes: 7 additions & 5 deletions lib/catalog_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ defmodule CatalogApi do
{:ok, %{items: Item.t(), page_info: map()}}
| {:error, {:bad_status, integer()}}
| {:error, {:catalog_api_fault, Error.extracted_fault()}}
| {:error, Poison.ParseError.t()}
| {:error, Jason.DecodeError.t()}
def search_catalog(socket_id, opts \\ %{}) do
required_params = %{socket_id: socket_id}
params = merge_required_filter_invalid(opts, required_params, @valid_search_catalog_keys)
Expand Down Expand Up @@ -155,7 +155,7 @@ defmodule CatalogApi do
{:ok, %{item: Item.t()}}
| {:error, {:bad_status, integer()}}
| {:error, {:catalog_api_fault, Error.extracted_fault()}}
| {:error, Poison.ParseError.t()}
| {:error, Jason.DecodeError.t()}
| {:error, :item_not_found}
def view_item(socket_id, catalog_item_id) do
params = %{socket_id: socket_id, catalog_item_id: catalog_item_id}
Expand Down Expand Up @@ -195,7 +195,7 @@ defmodule CatalogApi do
| {:error, Address.invalid_address_error()}
| {:error, {:bad_status, integer()}}
| {:error, {:catalog_api_fault, Error.extracted_fault()}}
| {:error, Poison.ParseError.t()}
| {:error, Jason.DecodeError.t()}
| {:error, :unparseable_response_description}
def cart_set_address(socket_id, external_user_id, %Address{} = address) do
address_params = Map.from_struct(address)
Expand Down Expand Up @@ -555,7 +555,7 @@ defmodule CatalogApi do
| {:error, :stale_cart_version}
| {:error, {:bad_status, integer()}}
| {:error, {:catalog_api_fault, Error.extracted_fault()}}
| {:error, Poison.ParseError.t()}
| {:error, Jason.DecodeError.t()}
def cart_order_place(socket_id, external_user_id, opts \\ []) do
allowed = [:cart_version]
{:ok, optional_params} = filter_optional_params([], opts, allowed)
Expand Down Expand Up @@ -627,8 +627,10 @@ defmodule CatalogApi do
HTTPoison.get(url)
end

@spec parse_json(iodata()) ::
{:ok, term()} | {:error, Jason.DecodeError.t()}
defp parse_json(json) do
Poison.decode(json)
Jason.decode(json)
end

defp merge_required_filter_invalid(opts, required, valid_keys) do
Expand Down
1 change: 1 addition & 0 deletions lib/catalog_api/address.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule CatalogApi.Address do
alias CatalogApi.Address.Iso3166
alias CatalogApi.StructHelper

@derive Jason.Encoder
defstruct first_name: "",
last_name: "",
address_1: "",
Expand Down
1 change: 1 addition & 0 deletions lib/catalog_api/cart_item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule CatalogApi.CartItem do
alias CatalogApi.Coercion
alias CatalogApi.CartItem

@derive Jason.Encoder
defstruct cart_price: nil,
catalog_item_id: nil,
catalog_points: nil,
Expand Down
1 change: 1 addition & 0 deletions lib/catalog_api/category.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule CatalogApi.Category do

alias CatalogApi.Category

@derive Jason.Encoder
defstruct category_id: nil,
children: [],
depth: 1,
Expand Down
4 changes: 2 additions & 2 deletions lib/catalog_api/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ defmodule CatalogApi.Error do

@type extracted_fault ::
Fault.t()
| {:error, Poison.ParseError.t()}
| {:error, Jason.DecodeError.t()}
| {:error, :unparseable_catalog_api_fault}

@spec extract_fault(Response.t()) :: extracted_fault
defp extract_fault(%Response{} = response) do
with {:ok, parsed} <- Poison.decode(response.body),
with {:ok, parsed} <- Jason.decode(response.body),
{:ok, fault} <- Fault.extract_fault_from_json(parsed) do
fault
end
Expand Down
1 change: 1 addition & 0 deletions lib/catalog_api/fault.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule CatalogApi.Fault do
alias CatalogApi.Fault
alias CatalogApi.StructHelper

@derive Jason.Encoder
defstruct detail: "", faultcode: "", faultstring: ""

@type t :: %Fault{detail: String.t(), faultcode: String.t(), faultstring: String.t()}
Expand Down
1 change: 1 addition & 0 deletions lib/catalog_api/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule CatalogApi.Item do
alias CatalogApi.Coercion
alias CatalogApi.Item

@derive Jason.Encoder
defstruct brand: nil,
catalog_item_id: nil,
catalog_price: nil,
Expand Down
2 changes: 2 additions & 0 deletions lib/catalog_api/order.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule CatalogApi.Order do
Defines the `CatalogApi.Order` struct and associated functions for dealing
with orders in CatalogAPI responses.
"""

@derive Jason.Encoder
defstruct order_id: nil

alias __MODULE__
Expand Down
5 changes: 3 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule CatalogApi.Mixfile do
def project do
[
app: :catalog_api,
version: "0.0.14",
version: "0.0.15",
elixir: "~> 1.3",
elixirc_paths: elixirc_paths(Mix.env),
build_embedded: Mix.env == :prod,
Expand All @@ -30,8 +30,9 @@ defmodule CatalogApi.Mixfile do
{:credo, "~> 0.9.1", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.16", only: :dev, runtime: false},
{:httpoison, "~> 1.0"},
{:jason, "~> 1.1.2"},
{:mix_test_watch, "~> 0.6", only: :dev, runtime: false},
{:mock, "~> 0.3.0", only: :test},
{:poison, "~> 3.1"},
{:quixir, "~> 0.9", only: :test },
{:uuid, "~> 1.1" },
]
Expand Down
11 changes: 7 additions & 4 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
"credo": {:hex, :credo, "0.9.2", "841d316612f568beb22ba310d816353dddf31c2d94aa488ae5a27bb53760d0bf", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.2", "993e0a95e9fbb790ac54ea58e700b45b299bd48bc44b4ae0404f28161f37a83e", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.11.0", "4951ee019df102492dabba66a09e305f61919a8a183a7860236c0fde586134b6", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "1.0.0", "1f02f827148d945d40b24f0b0a89afe40bfe037171a6cf70f2486976d86921cd", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"meck": {:hex, :meck, "0.8.9", "64c5c0bd8bcca3a180b44196265c8ed7594e16bcc845d0698ec6b4e577f48188", [:rebar3], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
"mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"},
"mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"pollution": {:hex, :pollution, "0.9.2", "3f67542631071c99f807d2a8f9da799c07cd983c902f5357b9e1569c20a26e76", [], [], "hexpm"},
"quixir": {:hex, :quixir, "0.9.3", "f01c37386b9e1d0526f01a8734a6d7884af294a0ec360f05c24c7171d74632bd", [], [{:pollution, "~> 0.9.2", [hex: :pollution, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"},
"pollution": {:hex, :pollution, "0.9.2", "3f67542631071c99f807d2a8f9da799c07cd983c902f5357b9e1569c20a26e76", [:mix], [], "hexpm"},
"quixir": {:hex, :quixir, "0.9.3", "f01c37386b9e1d0526f01a8734a6d7884af294a0ec360f05c24c7171d74632bd", [:mix], [{:pollution, "~> 0.9.2", [hex: :pollution, repo: "hexpm", optional: false]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [], [], "hexpm"},
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"},
}
2 changes: 1 addition & 1 deletion test/support/fixture_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule CatalogApi.FixtureHelper do
end

def retrieve_json_fixture(fixture_name) do
"#{fixture_name}.json" |> retrieve_fixture |> Poison.decode!()
"#{fixture_name}.json" |> retrieve_fixture |> Jason.decode!()
end

def retrieve_json_response(fixture_name, status_code \\ 200) do
Expand Down

0 comments on commit a53c1fc

Please sign in to comment.