Skip to content

Commit bca99f7

Browse files
authored
Merge pull request #219 from BlakeWilliams/acc-upgrade-jason
[IMPORTANT] Swap Jason for Poison
2 parents b032f28 + c127a39 commit bca99f7

File tree

11 files changed

+31
-28
lines changed

11 files changed

+31
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def application do
2424
end
2525

2626
def deps do
27-
[{:slack, "~> 0.22.0"}]
27+
[{:slack, "~> 0.23.0"}]
2828
end
2929
```
3030

lib/slack/bot.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ defmodule Slack.Bot do
181181
binstring
182182
|> :binary.split(<<0>>)
183183
|> List.first()
184-
|> Poison.Parser.parse!(%{keys: :atoms})
184+
|> Jason.decode!(keys: :atoms)
185185
end
186186

187187
defp handle_exception(e) do

lib/slack/rtm.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule Slack.Rtm do
2222
end
2323

2424
defp handle_response({:ok, %HTTPoison.Response{body: body}}) do
25-
case Poison.Parser.parse!(body, %{keys: :atoms}) do
25+
case Jason.decode!(body, keys: :atoms) do
2626
%{ok: true} = json ->
2727
{:ok, json}
2828

@@ -33,8 +33,8 @@ defmodule Slack.Rtm do
3333
{:error, "Invalid RTM response"}
3434
end
3535
rescue
36-
error in Poison.ParseError ->
37-
%Poison.ParseError{pos: _, value: reason, rest: _} = error
36+
error in Jason.DecodeError ->
37+
%Jason.DecodeError{data: reason, position: _, token: _} = error
3838
{:error, %Slack.JsonDecodeError{reason: reason, string: body}}
3939
end
4040

lib/slack/sends.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ defmodule Slack.Sends do
3939
text: text,
4040
channel: channel
4141
}
42-
|> Poison.encode!()
42+
|> Jason.encode!()
4343
|> send_raw(slack)
4444
end
4545

@@ -60,7 +60,7 @@ defmodule Slack.Sends do
6060
channel: channel,
6161
thread_ts: thread
6262
}
63-
|> Poison.encode!()
63+
|> Jason.encode!()
6464
|> send_raw(slack)
6565
end
6666

@@ -72,7 +72,7 @@ defmodule Slack.Sends do
7272
type: "typing",
7373
channel: channel
7474
}
75-
|> Poison.encode!()
75+
|> Jason.encode!()
7676
|> send_raw(slack)
7777
end
7878

@@ -84,7 +84,7 @@ defmodule Slack.Sends do
8484
type: "ping"
8585
}
8686
|> Map.merge(Map.new(data))
87-
|> Poison.encode!()
87+
|> Jason.encode!()
8888
|> send_raw(slack)
8989
end
9090

@@ -96,7 +96,7 @@ defmodule Slack.Sends do
9696
type: "presence_sub",
9797
ids: ids
9898
}
99-
|> Poison.encode!()
99+
|> Jason.encode!()
100100
|> send_raw(slack)
101101
end
102102

@@ -133,7 +133,7 @@ defmodule Slack.Sends do
133133

134134
case im_open do
135135
{:ok, response} ->
136-
case Poison.Parser.parse!(response.body, %{keys: :atoms}) do
136+
case Jason.decode!(response.body, keys: :atoms) do
137137
%{ok: true, channel: %{id: id}} -> on_success.(id)
138138
e = %{error: _error_message} -> on_error.(e)
139139
end

lib/slack/web/default_client.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule Slack.Web.DefaultClient do
2222
url
2323
|> HTTPoison.post!(body, [], opts())
2424
|> Map.fetch!(:body)
25-
|> Poison.Parser.parse!(%{})
25+
|> Jason.decode!(%{})
2626
end
2727

2828
defp opts do

lib/slack/web/web.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule Slack.Web do
1010
Enum.reduce(files, %{}, fn file, module_names ->
1111
json =
1212
File.read!("#{__DIR__}/docs/#{file}")
13-
|> Poison.Parser.parse!(%{})
13+
|> Jason.decode!(%{})
1414

1515
doc = Slack.Web.Documentation.new(json, file)
1616

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Slack.Mixfile do
44
def project do
55
[
66
app: :slack,
7-
version: "0.22.0",
7+
version: "0.23.0",
88
elixir: "~> 1.7",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
name: "Slack",
@@ -29,7 +29,7 @@ defmodule Slack.Mixfile do
2929
[
3030
{:httpoison, "~> 1.2"},
3131
{:websocket_client, "~> 1.2.4"},
32-
{:poison, "~> 4.0"},
32+
{:jason, "~> 1.1"},
3333
{:ex_doc, "~> 0.19", only: :dev},
3434
{:credo, "~> 0.5", only: [:dev, :test]},
3535
{:plug, "~> 1.6", only: :test},

test/integration/bot_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ defmodule Slack.Integration.BotTest do
5757
end
5858

5959
defp send_message_to_client(pid, message) do
60-
send(pid, Poison.encode!(%{type: "message", text: message, channel: "C0123abc"}))
60+
send(pid, Jason.encode!(%{type: "message", text: message, channel: "C0123abc"}))
6161
end
6262
end

test/slack/sends_test.exs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule Slack.SendsTest do
1919

2020
test "send_message sends message formatted to client" do
2121
result = Sends.send_message("hello", "channel", %{process: nil, client: FakeWebsocketClient})
22-
assert result == {nil, ~s/{"type":"message","text":"hello","channel":"channel"}/}
22+
assert result == {nil, ~s/{"channel":"channel","text":"hello","type":"message"}/}
2323
end
2424

2525
test "send_message understands #channel names" do
@@ -30,7 +30,7 @@ defmodule Slack.SendsTest do
3030
}
3131

3232
result = Sends.send_message("hello", "#channel", slack)
33-
assert result == {nil, ~s/{"type":"message","text":"hello","channel":"C456"}/}
33+
assert result == {nil, ~s/{"channel":"C456","text":"hello","type":"message"}/}
3434
end
3535

3636
test "send_message understands @user names" do
@@ -42,7 +42,7 @@ defmodule Slack.SendsTest do
4242
}
4343

4444
result = Sends.send_message("hello", "@user", slack)
45-
assert result == {nil, ~s/{"type":"message","text":"hello","channel":"D789"}/}
45+
assert result == {nil, ~s/{"channel":"D789","text":"hello","type":"message"}/}
4646
end
4747

4848
test "send_message understands user ids (Uxxx)" do
@@ -54,7 +54,7 @@ defmodule Slack.SendsTest do
5454
}
5555

5656
result = Sends.send_message("hello", "U123", slack)
57-
assert result == {nil, ~s/{"type":"message","text":"hello","channel":"D789"}/}
57+
assert result == {nil, ~s/{"channel":"D789","text":"hello","type":"message"}/}
5858
end
5959

6060
test "send_message understands user ids (Wxxx)" do
@@ -66,7 +66,7 @@ defmodule Slack.SendsTest do
6666
}
6767

6868
result = Sends.send_message("hello", "W123", slack)
69-
assert result == {nil, ~s/{"type":"message","text":"hello","channel":"D789"}/}
69+
assert result == {nil, ~s/{"channel":"D789","text":"hello","type":"message"}/}
7070
end
7171

7272
test "send_message with a thread attribute includes thread_ts in message to client" do
@@ -78,12 +78,15 @@ defmodule Slack.SendsTest do
7878
}
7979

8080
result = Sends.send_message("hello", "D789", slack, "1555508888.000100")
81-
assert result == {nil, ~s/{"type":"message","thread_ts":"1555508888.000100","text":"hello","channel":"D789"}/}
81+
82+
assert result ==
83+
{nil,
84+
~s/{"channel":"D789","text":"hello","thread_ts":"1555508888.000100","type":"message"}/}
8285
end
8386

8487
test "indicate_typing sends typing notification to client" do
8588
result = Sends.indicate_typing("channel", %{process: nil, client: FakeWebsocketClient})
86-
assert result == {nil, ~s/{"type":"typing","channel":"channel"}/}
89+
assert result == {nil, ~s/{"channel":"channel","type":"typing"}/}
8790
end
8891

8992
test "send_ping sends ping to client" do
@@ -93,16 +96,16 @@ defmodule Slack.SendsTest do
9396

9497
test "send_ping with data sends ping + data to client" do
9598
result = Sends.send_ping(%{foo: :bar}, %{process: nil, client: FakeWebsocketClient})
96-
assert result == {nil, ~s/{"type":"ping","foo":"bar"}/}
99+
assert result == {nil, ~s/{"foo":"bar","type":"ping"}/}
97100
end
98101

99102
test "subscribe_presence sends presence subscription message to client" do
100103
result = Sends.subscribe_presence(["a_user_id"], %{process: nil, client: FakeWebsocketClient})
101-
assert result == {nil, ~s/{"type":"presence_sub","ids":["a_user_id"]}/}
104+
assert result == {nil, ~s/{"ids":["a_user_id"],"type":"presence_sub"}/}
102105
end
103106

104107
test "subscribe_presence without ids sends presence subscription message to client" do
105108
result = Sends.subscribe_presence(%{process: nil, client: FakeWebsocketClient})
106-
assert result == {nil, ~s/{"type":"presence_sub","ids":[]}/}
109+
assert result == {nil, ~s/{"ids":[],"type":"presence_sub"}/}
107110
end
108111
end

test/slack/web/documentation_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defmodule Slack.Web.DocumentationTest do
3838
file_content =
3939
"#{__DIR__}/../../../lib/slack/web/docs/oauth.v2.access.json"
4040
|> File.read!()
41-
|> Poison.Parser.parse!(%{})
41+
|> Jason.decode!(%{})
4242

4343
doc = Documentation.new(file_content, "oauth.v2.access.json")
4444

0 commit comments

Comments
 (0)