ExponentServerSdk v0.2.0 ExponentServerSdk.Parser View Source
A JSON parser tuned specifically for Expo Push Notification API responses. Based on Poison’s excellent JSON decoder.
Link to this section Summary
Functions
Parse a response expected to contain a single Map
Parse a response expected to contain a list of Maps
Link to this section Types
Link to this type
parsed_list_response()
View Source
parsed_list_response() :: success_list() | error()
Link to this section Functions
Link to this function
parse(response)
View Source
parse(HTTPoison.Response.t()) :: success() | error()
Parse a response expected to contain a single Map
Examples
It will parse into a map. with the message response status
iex> response = %{body: "{\"data\": {\"status\": \"ok\", \"id\": \"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\"}}", status_code: 200}
iex> return_value = ExponentServerSdk.Parser.parse(response)
iex> return_value
{:ok, %{"status" => "ok", "id" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"}}
Link to this function
parse_list(response)
View Source
parse_list(HTTPoison.Response.t()) :: success_list() | error()
Parse a response expected to contain a list of Maps
Examples
It will parse into a list of maps with the message response status.
iex> response = %{body: "{ \"data\": [{\"status\": \"ok\", \"id\": \"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\"}, {\"status\": \"ok\", \"id\": \"YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY\"}] }", status_code: 200}
iex> return_value = ExponentServerSdk.Parser.parse_list(response)
iex> return_value
{:ok, [%{"id" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "status" => "ok"}, %{"id" => "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY", "status" => "ok"}]}