-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Labels
Description
Hi, awesome library!
I'm trying to use shotgun to read from firebase bitcoin event-source. If I try to read it using curl
it works, but somehow can't get it to work with shotgun
, it gets the first response with the content-type set as "text/event-stream" but the subsequent events never show up. Any ideas of what am I doing wrong, or could it be a bug?
$ curl "https://s-usc1c-nss-128.firebaseio.com/bitcoin.json?ns=publicdata-cryptocurrency&sse=true"
event: put
data: {"path":"/","data":{"_credits":"Powered By Coinbase.com","_updated":"Mon Nov 30 2015 01:13:45 GMT+0000 (UTC)","ask":"377.65","bid":"377.64","last":"377.64"}}
event: put
data: {"path":"/_updated","data":"Mon Nov 30 2015 01:14:01 GMT+0000 (UTC)"}
...
event: put
data: {"path":"/last","data":"377.65"}
The following example is in Elixir:
iex(37)> {:ok, conn_pid} = :shotgun.open('s-usc1c-nss-128.firebaseio.com', 443, :https)
{:ok, #PID<0.236.0>}
iex(38)> {:ok, response} = :shotgun.get(conn_pid, '/bitcoin.json?ns=publicdata-cryptocurrency&sse=true', %{}, %{async: true, async_mode: :sse})
{:ok,
%{body: "event: put\ndata: {\"path\":\"/\",\"data\":{\"_credits\":\"Powered By Coinbase.com\",\"_updated\":\"Mon Nov 30 2015 01:06:17 GMT+0000 (UTC)\",\"ask\":\"377.23\",\"bid\":\"377.22\",\"last\":\"377.23\"}}\n\n",
headers: [{"content-type", "text/event-stream"},
{"cache-control", "no-cache"}, {"access-control-allow-origin", "*"}],
status_code: 200}}
...
iex(39)> flush
:ok
iex(40)> :shotgun.events(conn_pid)
[]
and hopefully properly translated to Erlang, which I basically copied from the example on PR #115
F=fun() ->
l_all(shotgun),
ensure_all_started(shotgun),
{ok, Pid}=shotgun:open("s-usc1c-nss-128.firebaseio.com", 443, https),
io:format("~p~n", [shotgun:get(Pid, "/bitcoin.json?ns=publicdata-cryptocurrency&sse=true", #{}, #{async => true, async_mode => sse})]),
io:format("~p~n", [shotgun:events(Pid)]),
shotgun:close(Pid)
end.
F().