diff --git a/lib/jellyfish/client.ex b/lib/jellyfish/client.ex index 71ea351..cd0d5ae 100644 --- a/lib/jellyfish/client.ex +++ b/lib/jellyfish/client.ex @@ -27,24 +27,24 @@ defmodule Jellyfish.Client do } @doc """ - Creates new instance of `t:Jellyfish.Client.t/0`. + Creates a new instance of `t:Jellyfish.Client.t/0`. ## Parameters * `address` - url or IP address of the Jellyfish server instance - * `token` - token used for authorizing HTTP requests. It's the same + * `server_api_token` - token used for authorizing HTTP requests. It's the same token as the one configured in Jellyfish. """ @spec new(String.t(), String.t()) :: t() - def new(address, token), do: build_client(address, token) + def new(address, server_api_token), do: build_client(address, server_api_token) @doc """ - Creates new instance of `t:Jellyfish.Client.t/0`. + Creates a new instance of `t:Jellyfish.Client.t/0`. Uses token set in `config.exs`. To explicitly pass the token, see `new/2`. ``` # in config.exs - config :jellyfish_server_sdk, token: "your-jellyfish-token" + config :jellyfish_server_sdk, server_api_token: "your-jellyfish-token" client = Jellyfish.Client.new("http://address-of-your-server.com") ``` @@ -53,14 +53,14 @@ defmodule Jellyfish.Client do """ @spec new(String.t()) :: t() def new(address) do - token = Application.fetch_env!(:jellyfish_server_sdk, :token) - build_client(address, token) + server_api_token = Application.fetch_env!(:jellyfish_server_sdk, :server_api_token) + build_client(address, server_api_token) end - defp build_client(address, token) do + defp build_client(address, server_api_token) do middleware = [ {Tesla.Middleware.BaseUrl, address}, - {Tesla.Middleware.BearerAuth, token: token}, + {Tesla.Middleware.BearerAuth, token: server_api_token}, Tesla.Middleware.JSON ] diff --git a/lib/jellyfish/room.ex b/lib/jellyfish/room.ex index f44137e..437375a 100644 --- a/lib/jellyfish/room.ex +++ b/lib/jellyfish/room.ex @@ -13,7 +13,7 @@ defmodule Jellyfish.Room do peers: [] }} - iex> {:ok, peer, token} = Jellyfish.Room.add_peer(client, room.id, "webrtc") + iex> {:ok, peer, peer_token} = Jellyfish.Room.add_peer(client, room.id, "webrtc") {:ok, %Jellyfish.Peer{id: "5a731f2e-f49f-4d58-8f64-16a5c09b520e", type: "webrtc"}, "3LTQ3ZDEtYTRjNy0yZDQyZjU1MDAxY2FkAAdyb29tX2lkbQAAACQ0M"} @@ -41,7 +41,7 @@ defmodule Jellyfish.Room do @type id :: String.t() @typedoc """ - Client token, created by Jellyfish. Required by client application to open connection to Jellyfish. + Peer token, created by Jellyfish. Required by client application to open connection to Jellyfish. """ @type peer_token :: String.t() diff --git a/test/jellyfish/client_test.exs b/test/jellyfish/client_test.exs index 8607b75..a9f2f26 100644 --- a/test/jellyfish/client_test.exs +++ b/test/jellyfish/client_test.exs @@ -7,15 +7,15 @@ defmodule Jellyfish.ClientTest do describe "sdk" do test "creates client struct" do - token = "mock_token" - client = Client.new(@url, token) + server_api_token = "mock_token" + client = Client.new(@url, server_api_token) assert %Client{ http_client: %Tesla.Client{ adapter: {Tesla.Adapter.Mint, :call, [[]]}, pre: [ {Tesla.Middleware.BaseUrl, :call, [@url]}, - {Tesla.Middleware.BearerAuth, :call, [[token: ^token]]}, + {Tesla.Middleware.BearerAuth, :call, [[token: ^server_api_token]]}, {Tesla.Middleware.JSON, :call, [[]]} ] } diff --git a/test/jellyfish/room_test.exs b/test/jellyfish/room_test.exs index ed3ba8d..8d2c54b 100644 --- a/test/jellyfish/room_test.exs +++ b/test/jellyfish/room_test.exs @@ -5,7 +5,7 @@ defmodule Jellyfish.RoomTest do alias Jellyfish.{Client, Component, Peer, Room} - @token "testtoken" + @server_api_token "testtoken" @url "http://mockurl.com" @invalid_url "http://invalid-url.com" @@ -43,7 +43,7 @@ defmodule Jellyfish.RoomTest do end end) - %{client: Client.new(@url, @token)} + %{client: Client.new(@url, @server_api_token)} end describe "auth" do @@ -56,7 +56,7 @@ defmodule Jellyfish.RoomTest do body: ^valid_body } = env -> case Tesla.get_header(env, "authorization") do - "Bearer " <> @token -> + "Bearer " <> @server_api_token -> json(%{"data" => build_room_json(true)}, status: 201) "Bearer " <> _other -> @@ -71,7 +71,7 @@ defmodule Jellyfish.RoomTest do end test "invalid token" do - client = Client.new(@url, "invalid" <> @token) + client = Client.new(@url, "invalid" <> @server_api_token) assert {:error, _reason} = Room.create(client, max_peers: @max_peers) end end @@ -283,7 +283,7 @@ defmodule Jellyfish.RoomTest do end test "when request is valid", %{client: client} do - assert {:ok, peer, _token} = Room.add_peer(client, @room_id, @peer_type) + assert {:ok, peer, _peer_token} = Room.add_peer(client, @room_id, @peer_type) assert peer == build_peer() end