As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. If I use cURL all is good, but my code reports a success code of 200, so the call executed correctly, but a failed login.
It seems to me that the parameters are the same, so I can’t figure out what is wrong. A successful login returns:
{
“return_code”: 1,
“session”: “nlvpneu7jgk2t4nvrus9hi4bp6”,
“uid”: “804276”,
“username”: “me@example.com”
}
But I get the return for a failed login:
{“return_code”:0}
I’ll paste the cURL and my code, if someone sees the issue and can help me I would greatly appreciate the help.
Here is the cURL:
curl -X POST
‘SimpliSafe Control Panel’
-H ‘Cache-Control: no-cache’
-H ‘Content-Type: application/x-www-form-urlencoded’
-d ‘name=user%example.com&pass=mypass&device_name=my_iphone&device_uuid=51644e80-1b62-11e3-b773-0800200c9a66&version=1200&no_persist=1&XDEBUG_SESSION_START=session_name’
Here is my code:
defmodule Simplisafe.SsFreeze do
@user_agent [ { “User-agent”, “Elixir” } ]
def fetch(user, password) do
ss_url()
|> ss_login(user, password)
|> handle_response
end
defp ss_url do
“SimpliSafe Control Panel”
end
defp handle_response({ :ok, %{status_code: 200, body: body}}) do
{ :ok, body }
end
defp handle_response({ :error, %{status_code: sc, body: body}}) do
{ :error, sc, body }
end
defp handle_response({ ec, %{status_code: sc, body: body}}) do
{ ec, sc, body }
end
def post_body(user, password) do
%{“name” => user,
“pass” => password,
“device_name” => “my_iphone”,
“device_uuid” => “51644e80-1b62-11e3-b773-0800200c9a66”,
“version” => “1200”,
“no_persist” => “1”,
“XDEBUG_SESSION_START” => “session_name”,
} |> Poison.encode!
end
def ss_login(user, password) do
HTTPoison.post(ss_url(), post_body(user, password),
%{“Content-Type” => “application/x-www-form-urlencoded”, “Cache-Control” => “no-cache”})
end
def ss_login(url, user, password) do
HTTPoison.post(url, post_body(user, password), %{“Content-Type” => “application/x-www-form-urlencoded”, “Cache-Control” => “no-cache”})
end
end