summaryrefslogtreecommitdiff
path: root/lib/polyjuice/client/profile.ex
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2021-02-06 01:03:34 +0000
committerHubert Chathi <hubert@uhoreg.ca>2021-02-06 01:03:34 +0000
commit8a6f5650dec2e43b6dc81c8f7f2fa5baf3be9161 (patch)
tree38d89654b5b66c70c7e0aab5adcdf4b9508e284b /lib/polyjuice/client/profile.ex
parentMerge branch 'user_impersonation' into 'master' (diff)
parentrename display_name_test and remove get_acount_test (diff)
Merge branch 'profile_function' into 'master'
Profile function See merge request uhoreg/polyjuice_client!7
Diffstat (limited to 'lib/polyjuice/client/profile.ex')
-rw-r--r--lib/polyjuice/client/profile.ex126
1 files changed, 126 insertions, 0 deletions
diff --git a/lib/polyjuice/client/profile.ex b/lib/polyjuice/client/profile.ex
new file mode 100644
index 0000000..74612c3
--- /dev/null
+++ b/lib/polyjuice/client/profile.ex
@@ -0,0 +1,126 @@
+# Copyright 2020 Multi Prise <multiprisestunhappydev@gmail.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+defmodule Polyjuice.Client.Profile do
+ @moduledoc """
+ Profile-related functions.
+ """
+ require Logger
+
+ @doc """
+ Get user profile.
+
+ `user_id` is a string representing the user whose profile should be retrieved
+ If `user_id` is ommited it defaults to the user_id represented by the client
+ """
+ @spec get_profile(
+ client_api :: Polyjuice.Client.API.t(),
+ user_id :: String.t() | nil
+ ) :: {:ok, map()} | any
+ def get_profile(client_api, user_id \\ nil)
+ when is_binary(user_id) or user_id == nil do
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.GetProfile{
+ user_id: user_id || Polyjuice.Client.API.get_user_and_device(client_api) |> elem(0)
+ }
+ )
+ end
+
+ @doc """
+ Get avatar url for the user.
+
+ `user_id` is a string representing the user whose profile should be retrieved
+ If `user_id` is ommited it defaults to the user_id represented by the client
+ """
+ @spec get_avatar_url(
+ client_api :: Polyjuice.Client.API.t(),
+ user_id :: String.t() | nil
+ ) :: {:ok, String.t()} | any
+ def get_avatar_url(client_api, user_id \\ nil)
+ when is_binary(user_id) or user_id == nil do
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.GetProfileAvatarUrl{
+ user_id: user_id || Polyjuice.Client.API.get_user_and_device(client_api) |> elem(0)
+ }
+ )
+ end
+
+ @doc """
+ Get display name for the user.
+
+ `user_id` is a string representing the user whose profile should be retrieved
+ If `user_id` is ommited it defaults to the user_id represented by the client
+ """
+ @spec get_displayname(
+ client_api :: Polyjuice.Client.API.t(),
+ user_id :: String.t() | nil
+ ) :: {:ok, String.t()} | any
+ def get_displayname(client_api, user_id \\ nil)
+ when is_binary(user_id) or user_id == nil do
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.GetProfileDisplayname{
+ user_id: user_id || Polyjuice.Client.API.get_user_and_device(client_api) |> elem(0)
+ }
+ )
+ end
+
+ @doc """
+ Modify avatar url for the user.
+
+ `user_id` is a string representing the user whose profile should be retrieved
+ If `user_id` is ommited it defaults to the user_id represented by the client
+ `avatar_url` is an url specifying the location of the new profile avatar
+ """
+ @spec put_avatar_url(
+ client_api :: Polyjuice.Client.API.t(),
+ user_id :: String.t() | nil,
+ avatar_url :: String.t()
+ ) :: :ok | any
+ def put_avatar_url(client_api, user_id \\ nil, avatar_url)
+ when is_binary(user_id) or user_id == nil do
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PutProfileAvatarUrl{
+ user_id: user_id || Polyjuice.Client.API.get_user_and_device(client_api) |> elem(0),
+ avatar_url: avatar_url
+ }
+ )
+ end
+
+ @doc """
+ Modify display name for the user.
+
+ `user_id` is a string representing the user whose profile should be retrieved
+ If `user_id` is ommited it defaults to the user_id represented by the client
+ `displayname` is a string representing the new displayname
+ """
+ @spec put_displayname(
+ client_api :: Polyjuice.Client.API.t(),
+ user_id :: String.t() | nil,
+ displayname :: String.t()
+ ) :: :ok | any
+ def put_displayname(client_api, user_id \\ nil, displayname)
+ when is_binary(user_id) or user_id == nil do
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PutProfileDisplayname{
+ user_id: user_id || Polyjuice.Client.API.get_user_and_device(client_api) |> elem(0),
+ displayname: displayname
+ }
+ )
+ end
+end