Skip to content

Commit

Permalink
Add support for Get-Current-Member-Info
Browse files Browse the repository at this point in the history
  • Loading branch information
avery-mech authored and medoror-mo committed Jan 6, 2025
1 parent 9228466 commit a658c90
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .zed/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"languages": {
"Elixir": {
"language_servers": ["lexical", "!elixir-ls", "..."]
}
}
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ It will:
* Bump the version in the mix.exs file
* Create a github release for that version

Remember to update the README.md documentation with the latest version (manual, for now, due to technical dificulties getting this to auto update)
Remember to update the README.md documentation with the latest version (manual, for now, due to technical difficulties getting this to auto update)
45 changes: 45 additions & 0 deletions lib/members.ex
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
41 changes: 41 additions & 0 deletions test/members_test.exs
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
1 change: 0 additions & 1 deletion test/projects_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule ShortcutApi.ProjectsTest do

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}
Expand Down

0 comments on commit a658c90

Please sign in to comment.