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 http_status_code() View Source
http_status_code() :: number()
Link to this type parsed_list_response() View Source
parsed_list_response() :: success_list() | error()
Link to this type parsed_response() View Source
parsed_response() :: success() | error()
Link to this type success() View Source
success() :: {:ok, map()}
Link to this type success_list() View Source
success_list() :: {:ok, [map()]}

Link to this section Functions

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"}}

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"}]}