-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
Get-Current-Member-Info
- Loading branch information
1 parent
9228466
commit a658c90
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"languages": { | ||
"Elixir": { | ||
"language_servers": ["lexical", "!elixir-ls", "..."] | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule ShortcutApi.Members do | ||
import ShortcutApi.ApiHelpers | ||
|
||
@behaviour ShortcutApi.MembersBehavior | ||
@moduledoc """ | ||
API wrapper for Shortcut Members endpoints. | ||
See: https://developer.shortcut.com/api/rest/v3#Member | ||
All functions require a valid Shortcut API token. | ||
""" | ||
|
||
@type token :: String.t() | ||
@type response :: {:ok, map() | list(map())} | {:error, any()} | ||
|
||
@doc """ | ||
Gets information about the currently authenticated member. | ||
## Parameters | ||
* `token` - Shortcut API token | ||
## Examples | ||
iex> ShortcutApi.Members.get_current_member("token") | ||
{:ok, %{id: "12345678-9012-3456-7890-123456789012", name: "Member Name"}} | ||
""" | ||
@spec get_current_member(token()) :: response() | ||
def get_current_member(token) when is_binary(token) do | ||
make_request(:get, "/member", token) | ||
end | ||
end | ||
|
||
defmodule ShortcutApi.MembersBehavior do | ||
@moduledoc """ | ||
A behaviour for interacting with Shortcut Members API endpoints. | ||
This module defines the required callbacks for operations related to members. | ||
Implementations of this behaviour must provide the necessary logic to handle | ||
interactions with the Shortcut API. | ||
All callbacks require a valid Shortcut API token. | ||
""" | ||
|
||
@callback get_current_member(String.t()) :: {:ok, map()} | {:error, any()} | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule ShortcutApi.MembersTest do | ||
use ExUnit.Case | ||
|
||
setup do | ||
bypass = Bypass.open() | ||
# Override the base URL for testing | ||
base_url = "http://localhost:#{bypass.port}/api/v3" | ||
Application.put_env(:shortcut_api, :base_url, base_url) | ||
{:ok, bypass: bypass} | ||
end | ||
|
||
setup_all do | ||
Hammox.protect(ShortcutApi.Members, ShortcutApi.MembersBehavior) | ||
end | ||
|
||
test "get_current_member/1", %{bypass: bypass, get_current_member_1: get_current_member} do | ||
Bypass.expect(bypass, "GET", "/api/v3/member", fn conn -> | ||
conn | ||
|> Plug.Conn.put_resp_content_type("application/json") | ||
|> Plug.Conn.resp( | ||
200, | ||
Jason.encode!(%{ | ||
"id" => "12345678-9012-3456-7890-123456789012", | ||
"mention_name" => "testuser", | ||
"name" => "Test User", | ||
"workspace2" => %{ | ||
"estimate_scale" => [0, 1, 2, 3], | ||
"url_slug" => "test-workspace" | ||
} | ||
}) | ||
) | ||
end) | ||
|
||
{:ok, member} = get_current_member.("fake-token") | ||
assert member["id"] == "12345678-9012-3456-7890-123456789012" | ||
assert member["mention_name"] == "testuser" | ||
assert member["name"] == "Test User" | ||
assert member["workspace2"]["url_slug"] == "test-workspace" | ||
assert member["workspace2"]["estimate_scale"] == [0, 1, 2, 3] | ||
end | ||
end |
This file contains 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