Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/sprites/filesystem.ex
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,8 @@ defmodule Sprites.Filesystem do
# Private Helpers
# ============================================================================

defp build_url(_fs, endpoint, params) do
query = URI.encode_query(params)
"#{endpoint}?#{query}"
defp build_url(fs, endpoint, params) do
Sprites.Sprite.path(fs.sprite, endpoint, params)
end

defp resolve_path(_fs, "/" <> _ = absolute_path), do: absolute_path
Expand Down
9 changes: 9 additions & 0 deletions lib/sprites/sprite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ defmodule Sprites.Sprite do
client.token
end

@doc """
Builds a path for sprite-specific API endpoints.
"""
@spec path(t(), String.t(), keyword()) :: String.t()
def path(%__MODULE__{name: name}, endpoint, params \\ []) do
query = if params == [], do: "", else: "?#{URI.encode_query(params)}"
"/v1/sprites/#{URI.encode(name)}#{endpoint}#{query}"
end
Copy link
Author

@jonlunsford jonlunsford Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally open to a better names, Sprites.Sprite.path was just my first thought :)


defp build_query_params(command, args, opts) do
[{"path", command} | Enum.map([command | args], &{"cmd", &1})]
|> add_stdin_param(opts)
Expand Down
37 changes: 37 additions & 0 deletions test/sprites/sprite_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule Sprites.SpriteTest do
use ExUnit.Case, async: true

alias Sprites.Sprite

describe "path/3" do
test "it builds the correct path when no param are provided" do
client = Sprites.Client.new("test_token", base_url: "https://api.sprites.dev")
sprite = Sprite.new(client, "my_sprite")

url =
Sprite.path(sprite, "/fs/list")

assert url == "/v1/sprites/my_sprite/fs/list"
end

test "it builds the correct path when params are provided as a map" do
client = Sprites.Client.new("test_token", base_url: "https://api.sprites.dev")
sprite = Sprite.new(client, "my_sprite")

url =
Sprite.path(sprite, "/fs/list", %{path: "/home/user", recursive: true})

assert url == "/v1/sprites/my_sprite/fs/list?path=%2Fhome%2Fuser&recursive=true"
end

test "it builds the correct path when params are provided as a keyword list" do
client = Sprites.Client.new("test_token", base_url: "https://api.sprites.dev")
sprite = Sprite.new(client, "my_sprite")

url =
Sprite.path(sprite, "/fs/list", path: "/home/user", recursive: true)

assert url == "/v1/sprites/my_sprite/fs/list?path=%2Fhome%2Fuser&recursive=true"
end
end
end