diff --git a/README.md b/README.md index ed1e080..a065c7f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Possum 🐀 -Possum submodule targeting the Tangled xrpc API. Useful for fetching data -about repositories, issues, vouches and pull requests. +Possum submodule targeting Bobbin, the tangled xrpc API. Useful for fetching data +about repositories, issues, vouches, spindles and pull requests. [What is possum?](https://possum.hexdocs.pm/) diff --git a/gleam.toml b/gleam.toml index 909450a..fe21554 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,10 +1,10 @@ name = "possum_tangled" version = "1.0.0" -# description = "🐑 Query data from the tangled API " -# licences = ["Apache-2.0"] -# repository = { type = "github", user = "kacaii", repo = "possum_tangled" } -# links = [{ title = "", href = "" }] +description = "🐑 Query data from the tangled API " +licences = ["Apache-2.0"] +repository = { type = "tangled", user = "kacaii", repo = "possum-tangled" } +links = [{ title = "Possum", href = "https://tangled.org/kacaii.dev/possum" }] [dependencies] gleam_stdlib = ">= 1.0.0 and < 2.0.0" diff --git a/src/possum/tangled.gleam b/src/possum/tangled.gleam index d55d6cc..76efbf5 100644 --- a/src/possum/tangled.gleam +++ b/src/possum/tangled.gleam @@ -1,3 +1,8 @@ +//// Bobbin is an API appview for Tangled records. It serves XRPC endpoints for +//// sh.tangled.*, with it you can get repos, issues, pulls, comments, follows, +//// stars, labels, pipelines, and profiles. It is read-only, there is no auth, +//// since that should all be handled direct-to-PDS and knot respectively. + import gleam/http import gleam/http/request import gleam/int @@ -511,6 +516,20 @@ pub fn list_strings( |> request.set_query(query) } +/// List all SSH public keys assigned to a user +/// +/// ## Examples +/// +/// ```gleam +/// import possum/did +/// import possum/tangled +/// +/// // DID of the user +/// let assert Ok(did) = did.parse("did:plc:dvyyslcz7bicxdumlccviqyv") +/// +/// let request = +/// tangled.list_public_keys(did, cursor: option.None, limit: option.None) +/// ``` pub fn list_public_keys( did: did.Did, cursor cursor: option.Option(String), @@ -542,7 +561,21 @@ pub fn list_public_keys( |> request.set_query(query) } -pub fn list_spindles( +/// List all Spindles owned by an user +/// +/// ## Examples +/// +/// ```gleam +/// import possum/did +/// import possum/tangled +/// +/// // DID of the user +/// let assert Ok(did) = did.parse("did:plc:dvyyslcz7bicxdumlccviqyv") +/// +/// let request = +/// tangled.list_owned_spindles(did, cursor: option.None, limit: option.None) +/// ``` +pub fn list_owned_spindles( did: did.Did, cursor cursor: option.Option(String), limit limit: option.Option(Int), @@ -572,3 +605,52 @@ pub fn list_spindles( ) |> request.set_query(query) } + +/// List all Spindles that an user have access to +/// +/// ## Examples +/// +/// ```gleam +/// import possum/did +/// import possum/tangled +/// +/// // DID of the user +/// let assert Ok(did) = did.parse("did:plc:dvyyslcz7bicxdumlccviqyv") +/// +/// let request = +/// tangled.list_available_spindles( +/// did, +/// cursor: option.None, +/// limit: option.None +/// ) +/// ``` +pub fn list_available_spindles( + did: did.Did, + cursor cursor: option.Option(String), + limit limit: option.Option(Int), +) -> request.Request(String) { + let endpoint = ".spindle.listMembers" + let query = [#("subject", did.to_string(did))] + + let query = case cursor { + option.Some(value) -> [#("cursor", value), ..query] + option.None -> query + } + + let query = case limit { + option.Some(value) -> [#("limit", int.to_string(value)), ..query] + option.None -> query + } + + request.Request( + method: http.Get, + headers: [#("accept", "application/json")], + body: "", + scheme: http.Https, + host: bobbin, + port: option.None, + path: "/xrpc/sh.tangled" <> endpoint, + query: option.None, + ) + |> request.set_query(query) +} diff --git a/test/possum_tangled_test.gleam b/test/possum_tangled_test.gleam index 5c956ab..7b297bd 100644 --- a/test/possum_tangled_test.gleam +++ b/test/possum_tangled_test.gleam @@ -207,17 +207,35 @@ pub fn list_public_keys_test() -> Nil { } /// https://api.tangled.org/xrpc/sh.tangled.spindle.listSpindles?subject=did:plc:wshs7t2adsemcrrd4snkeqli -pub fn list_spindles_test() -> Nil { +pub fn list_owned_spindles_test() -> Nil { let assert Ok(did) = did.parse("did:plc:wshs7t2adsemcrrd4snkeqli") let assert Ok(response) = - tangled.list_spindles(did, cursor: option.None, limit: option.None) + tangled.list_owned_spindles(did, cursor: option.None, limit: option.None) |> httpc.send let assert Ok(_) = response.body |> json.parse(lexicon_decoder("sh.tangled.spindle")) - |> echo + + Nil +} + +/// https://api.tangled.org/xrpc/sh.tangled.spindle.listMembers?subject=did:plc:wshs7t2adsemcrrd4snkeqli +pub fn list_available_spindles_test() -> Nil { + let assert Ok(record) = did.parse("did:plc:dvyyslcz7bicxdumlccviqyv") + + let assert Ok(response) = + tangled.list_available_spindles( + record, + cursor: option.None, + limit: option.None, + ) + |> httpc.send + + let assert Ok(_) = + response.body + |> json.parse(lexicon_decoder("sh.tangled.spindle.member")) Nil }