Skip to content

Commit

Permalink
Merge pull request #123 from cgorshing/feature/fix/121
Browse files Browse the repository at this point in the history
Issue #121 Replace JSON library poison with Jason
  • Loading branch information
parroty authored Feb 9, 2020
2 parents d9de7eb + e4a0586 commit 76c8fc8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleases
------
#### Changes
* Update dependency.
- Replaced poison dep with jason 1.1 (#121).

0.11.0
------
#### Changes
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ def application do
end
```

#### JSON support

ExTwitter comes with JSON support out of the box via the [Jason](https://github.com/michalmuskala/jason) library. To use it, add `:jason` to your dependencies:

```elixir
{:jason, "~> 1.1"},
```

You can customize it to use another library via the `:json_library` configuration:

```elixir
config :extwitter, :json_library, Poison
```

### Sample
Sample execution on iex.

Expand Down
8 changes: 6 additions & 2 deletions lib/extwitter/json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ defmodule ExTwitter.JSON do
Decode json string into elixir objects.
"""
def decode!(json) do
Poison.decode!(json, keys: :atoms)
json_library().decode!(json, keys: :atoms)
end

@doc """
Decode json string into elixir objects.
"""
def decode(json) do
Poison.decode(json, keys: :atoms)
json_library().decode(json, keys: :atoms)
end

@doc """
Expand All @@ -25,4 +25,8 @@ defmodule ExTwitter.JSON do
def get(object, key) do
Map.get(object, key, [])
end

defp json_library do
Application.get_env(:extwitter, :json_library, Jason)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule ExTwitter.Mixfile do
def deps do
[
{:oauther, "~> 1.1"},
{:poison, "~> 3.0"},
{:jason, "~> 1.1"},
{:exvcr, "~> 0.8", only: :test},
{:excoveralls, "~> 0.7", only: :test},
{:meck, "~> 0.8.13", only: [:dev, :test]},
Expand Down
1 change: 0 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"mock": {:hex, :mock, "0.3.0", "91523bc43d8c654891284b89b8ad0410212c0ebea332bc719d7167108ea8117d", [:mix], [{:meck, "~> 0.8.7", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm"},
"oauther": {:hex, :oauther, "1.1.0", "c9a56e200507ce64e069f5273143db0cddd7904cd5d1fe46920388a48f22441b", [:mix], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "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"},
}

0 comments on commit 76c8fc8

Please sign in to comment.