From 6ecf025b25b91a49871d0f97227cab2c541d0f92 Mon Sep 17 00:00:00 2001 From: Mathew Bramson Date: Mon, 17 Dec 2018 20:32:07 -0500 Subject: [PATCH 1/4] Replace Poison with Jason --- lib/catalog_api.ex | 12 +++++++----- mix.exs | 2 ++ mix.lock | 9 ++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/catalog_api.ex b/lib/catalog_api.ex index 01d1a91..0939c50 100644 --- a/lib/catalog_api.ex +++ b/lib/catalog_api.ex @@ -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) @@ -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} @@ -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) @@ -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) @@ -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 diff --git a/mix.exs b/mix.exs index 69377f5..1977b47 100644 --- a/mix.exs +++ b/mix.exs @@ -30,6 +30,8 @@ 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 }, diff --git a/mix.lock b/mix.lock index 106d8d5..0d1304f 100644 --- a/mix.lock +++ b/mix.lock @@ -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"}, + "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"}, } From 75b0df28a7ebc7b7f100ddbb9da3c178503e78da Mon Sep 17 00:00:00 2001 From: Mathew Bramson Date: Mon, 17 Dec 2018 20:41:08 -0500 Subject: [PATCH 2/4] Derive Jason.Encoder for response structs --- lib/catalog_api/address.ex | 1 + lib/catalog_api/cart_item.ex | 1 + lib/catalog_api/category.ex | 1 + lib/catalog_api/fault.ex | 1 + lib/catalog_api/item.ex | 1 + lib/catalog_api/order.ex | 2 ++ 6 files changed, 7 insertions(+) diff --git a/lib/catalog_api/address.ex b/lib/catalog_api/address.ex index cdf13a5..7bb10fd 100644 --- a/lib/catalog_api/address.ex +++ b/lib/catalog_api/address.ex @@ -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: "", diff --git a/lib/catalog_api/cart_item.ex b/lib/catalog_api/cart_item.ex index 7168a5a..b7eda91 100644 --- a/lib/catalog_api/cart_item.ex +++ b/lib/catalog_api/cart_item.ex @@ -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, diff --git a/lib/catalog_api/category.ex b/lib/catalog_api/category.ex index 626fb13..4e57bf8 100644 --- a/lib/catalog_api/category.ex +++ b/lib/catalog_api/category.ex @@ -6,6 +6,7 @@ defmodule CatalogApi.Category do alias CatalogApi.Category + @derive Jason.Encoder defstruct category_id: nil, children: [], depth: 1, diff --git a/lib/catalog_api/fault.ex b/lib/catalog_api/fault.ex index cc99e0a..6ef0ecc 100644 --- a/lib/catalog_api/fault.ex +++ b/lib/catalog_api/fault.ex @@ -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()} diff --git a/lib/catalog_api/item.ex b/lib/catalog_api/item.ex index c4cd10d..e88c7f2 100644 --- a/lib/catalog_api/item.ex +++ b/lib/catalog_api/item.ex @@ -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, diff --git a/lib/catalog_api/order.ex b/lib/catalog_api/order.ex index c277830..7767156 100644 --- a/lib/catalog_api/order.ex +++ b/lib/catalog_api/order.ex @@ -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__ From 55af90574058b817cce80f0b2384c02626325bfb Mon Sep 17 00:00:00 2001 From: Mathew Bramson Date: Mon, 17 Dec 2018 20:51:30 -0500 Subject: [PATCH 3/4] Fix remaining Poison References Remove Poison dependency --- lib/catalog_api/error.ex | 4 ++-- mix.exs | 1 - mix.lock | 2 +- test/support/fixture_helper.ex | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/catalog_api/error.ex b/lib/catalog_api/error.ex index 2a38d38..824e81d 100644 --- a/lib/catalog_api/error.ex +++ b/lib/catalog_api/error.ex @@ -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 diff --git a/mix.exs b/mix.exs index 1977b47..ea6e5dd 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,6 @@ defmodule CatalogApi.Mixfile do {: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" }, ] diff --git a/mix.lock b/mix.lock index 0d1304f..3240d9b 100644 --- a/mix.lock +++ b/mix.lock @@ -14,7 +14,7 @@ "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"}, + "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"}, diff --git a/test/support/fixture_helper.ex b/test/support/fixture_helper.ex index 8db1093..b2d1a2c 100644 --- a/test/support/fixture_helper.ex +++ b/test/support/fixture_helper.ex @@ -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 From 7b40e19e30b2840bed3a6550248150dd5d76773b Mon Sep 17 00:00:00 2001 From: Mathew Bramson Date: Mon, 17 Dec 2018 20:55:10 -0500 Subject: [PATCH 4/4] Bump version to 0.0.15 --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index ea6e5dd..0ead827 100644 --- a/mix.exs +++ b/mix.exs @@ -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,