diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-12-26 21:32:44 -0500 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-12-26 21:32:44 -0500 |
commit | d11baa1ab6628781506ad17936dfcd5a9afd0821 (patch) | |
tree | 9c659069e71f84fd4ac9b9761115eb6e0190f3b7 /lib/polyjuice/client | |
parent | fix warnings in test (diff) |
add function for getting user/device ID
and use it when the user ID is unspecified when setting/getting account data
Diffstat (limited to 'lib/polyjuice/client')
-rw-r--r-- | lib/polyjuice/client/account.ex | 12 | ||||
-rw-r--r-- | lib/polyjuice/client/low_level.ex | 4 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/polyjuice/client/account.ex b/lib/polyjuice/client/account.ex index 0ad18c0..d7b8d0d 100644 --- a/lib/polyjuice/client/account.ex +++ b/lib/polyjuice/client/account.ex @@ -24,14 +24,14 @@ defmodule Polyjuice.Client.Account do """ @spec get_data( client_api :: Polyjuice.Client.API.t(), - user_id :: String.t(), + user_id :: String.t() | nil, event_type :: String.t() ) :: {:ok, map()} | any - def get_data(client_api, user_id, event_type) do + def get_data(client_api, user_id \\ nil, event_type) do Polyjuice.Client.API.call( client_api, %Polyjuice.Client.Endpoint.GetAccountData{ - user_id: user_id, + user_id: user_id || Polyjuice.Client.API.get_user_and_device(client_api) |> elem(0), type: event_type } ) @@ -45,15 +45,15 @@ defmodule Polyjuice.Client.Account do """ @spec put_data( client_api :: Polyjuice.Client.API.t(), - user_id :: String.t(), + user_id :: String.t() | nil, event_type :: String.t(), changes :: Map.t() ) :: {:ok} | any - def put_data(client_api, user_id, event_type, changes) do + def put_data(client_api, user_id \\ nil, event_type, changes) do Polyjuice.Client.API.call( client_api, %Polyjuice.Client.Endpoint.PutAccountData{ - user_id: user_id, + user_id: user_id || Polyjuice.Client.API.get_user_and_device(client_api) |> elem(0), type: event_type, account_data: changes } diff --git a/lib/polyjuice/client/low_level.ex b/lib/polyjuice/client/low_level.ex index 54acf83..91b39ae 100644 --- a/lib/polyjuice/client/low_level.ex +++ b/lib/polyjuice/client/low_level.ex @@ -118,6 +118,10 @@ defmodule Polyjuice.Client.LowLevel do "#{Node.self()}_#{:erlang.system_time(:millisecond)}_#{:erlang.unique_integer()}" end + def get_user_and_device(%{user_id: user_id, device_id: device_id}) do + {user_id, device_id} + end + def stop(_, _, _) do # don't need to do anything to stop it :ok |