Created
April 8, 2017 18:34
-
-
Save iwada/500ec2401b2fd52aa4ffc8bab65010b8 to your computer and use it in GitHub Desktop.
HTTPoison
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
Assuming HTTPoison.get produces this on a Failed API call | |
[:ok, | |
%HTTPoison.Response{body: "{\"ACTION\":\"avail.datacenters\",\"DATA\":{},\"ERRORARRAY\":[{\"ERRORMESSAGE\":\"Authentication failed\",\"ERRORCODE\":4}]}", | |
headers: [{"Server", "nginx"}, {"Date", "Sat, 08 Apr 2017 18:13:06 GMT"}, | |
{"Content-Type", "application/json;charset=UTF-8"}, | |
{"Transfer-Encoding", "chunked"}, {"Connection", "keep-alive"}, | |
{"X-Powered-By", "Tiger Blood"}, {"Access-Control-Allow-Origin", "*"}, | |
{"Strict-Transport-Security", "max-age=31536000"}], status_code: 200}] | |
and a Correct API call produces | |
{:ok, | |
%HTTPoison.Response{body: "{\"ACTION\":\"avail.datacenters\",\"DATA\":[{\"LOCATION\":\"Dallas, TX, USA\",\"DATACENTERID\":2,\"ABBR\":\"dallas\"},{\"LOCATION\":\"Fremont, CA, USA\",\"DATACENTERID\":3,\"ABBR\":\"fremont\"},{\"LOCATION\":\"Atlanta, GA, USA\",\"DATACENTERID\":4,\"ABBR\":\"atlanta\"},{\"LOCATION\":\"Newark, NJ, USA\",\"DATACENTERID\":6,\"ABBR\":\"newark\"},{\"LOCATION\":\"London, England, UK\",\"DATACENTERID\":7,\"ABBR\":\"london\"},{\"LOCATION\":\"Tokyo, JP\",\"DATACENTERID\":8,\"ABBR\":\"tokyo\"},{\"LOCATION\":\"Singapore, SG\",\"DATACENTERID\":9,\"ABBR\":\"singapore\"},{\"LOCATION\":\"Frankfurt, DE\",\"DATACENTERID\":10,\"ABBR\":\"frankfurt\"},{\"LOCATION\":\"Tokyo 2, JP\",\"DATACENTERID\":11,\"ABBR\":\"shinagawa1\"}],\"ERRORARRAY\":[]}", | |
headers: [{"Server", "nginx"}, {"Date", "Sat, 08 Apr 2017 18:31:09 GMT"}, | |
{"Content-Type", "application/json;charset=UTF-8"}, | |
{"Transfer-Encoding", "chunked"}, {"Connection", "keep-alive"}, | |
{"X-Powered-By", "Tiger Blood"}, {"Access-Control-Allow-Origin", "*"}, | |
{"Strict-Transport-Security", "max-age=31536000"}], status_code: 200}} | |
Please how would i pattern match knowing that both the failed request and "Correct" one both return | |
{:ok, %HTTPoison.Response{status_code: 200}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment