Created
March 28, 2016 03:56
-
-
Save sikanhe/54a4b9a1fe10ea8b7a85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RethinkDB.Response do | |
@moduledoc false | |
def parse(raw_data, token, pid) do | |
d = Poison.decode!(raw_data) | |
r = RethinkDB.Pseudotypes.convert_reql_pseudotypes(d["r"]) | |
profile = d["p"] | |
type = d["t"] | |
resp = case type do | |
1 -> {:ok, hd(r)} | |
2 -> {:ok, r} | |
3 -> case d["n"] do | |
[2] -> {:ok, %RethinkDB.Feed{token: token, data: hd(r), pid: pid, note: d["n"]}} | |
_ -> {:ok, %RethinkDB.Feed{token: token, data: r, pid: pid, note: d["n"]}} | |
end | |
4 -> {:ok, :noreply} | |
5 -> {:ok, hd(r)} | |
16 -> {:error, hd(r)} | |
17 -> {:error, hd(r)} | |
18 -> {:error, hd(r)} | |
end | |
maybe_add_profile(profile, resp) | |
end | |
defp maybe_add_profile(resp, nil), do: resp | |
defp maybe_add_profile({status, resp}, profile) do | |
resp = case resp do | |
%RethinkDB.Feed{} = struct -> | |
%{feed | :profile => profile} | |
_ -> | |
%{data: resp, profile: profile} | |
end | |
{status, resp} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment