forked from tangled.org/core
this repo has no description
at packages 2.6 kB view raw
1package xrpcclient 2 3import ( 4 "bytes" 5 "context" 6 "io" 7 8 "github.com/bluesky-social/indigo/api/atproto" 9 "github.com/bluesky-social/indigo/xrpc" 10 oauth "tangled.sh/icyphox.sh/atproto-oauth" 11) 12 13type Client struct { 14 *oauth.XrpcClient 15 authArgs *oauth.XrpcAuthedRequestArgs 16} 17 18func NewClient(client *oauth.XrpcClient, authArgs *oauth.XrpcAuthedRequestArgs) *Client { 19 return &Client{ 20 XrpcClient: client, 21 authArgs: authArgs, 22 } 23} 24 25func (c *Client) RepoPutRecord(ctx context.Context, input *atproto.RepoPutRecord_Input) (*atproto.RepoPutRecord_Output, error) { 26 var out atproto.RepoPutRecord_Output 27 if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "application/json", "com.atproto.repo.putRecord", nil, input, &out); err != nil { 28 return nil, err 29 } 30 31 return &out, nil 32} 33 34func (c *Client) RepoApplyWrites(ctx context.Context, input *atproto.RepoApplyWrites_Input) (*atproto.RepoApplyWrites_Output, error) { 35 var out atproto.RepoApplyWrites_Output 36 if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "application/json", "com.atproto.repo.applyWrites", nil, input, &out); err != nil { 37 return nil, err 38 } 39 40 return &out, nil 41} 42 43func (c *Client) RepoGetRecord(ctx context.Context, cid string, collection string, repo string, rkey string) (*atproto.RepoGetRecord_Output, error) { 44 var out atproto.RepoGetRecord_Output 45 46 params := map[string]interface{}{ 47 "cid": cid, 48 "collection": collection, 49 "repo": repo, 50 "rkey": rkey, 51 } 52 if err := c.Do(ctx, c.authArgs, xrpc.Query, "", "com.atproto.repo.getRecord", params, nil, &out); err != nil { 53 return nil, err 54 } 55 56 return &out, nil 57} 58 59func (c *Client) RepoUploadBlob(ctx context.Context, input io.Reader) (*atproto.RepoUploadBlob_Output, error) { 60 var out atproto.RepoUploadBlob_Output 61 if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "*/*", "com.atproto.repo.uploadBlob", nil, input, &out); err != nil { 62 return nil, err 63 } 64 65 return &out, nil 66} 67 68func (c *Client) SyncGetBlob(ctx context.Context, cid string, did string) ([]byte, error) { 69 buf := new(bytes.Buffer) 70 71 params := map[string]interface{}{ 72 "cid": cid, 73 "did": did, 74 } 75 if err := c.Do(ctx, c.authArgs, xrpc.Query, "", "com.atproto.sync.getBlob", params, nil, buf); err != nil { 76 return nil, err 77 } 78 79 return buf.Bytes(), nil 80} 81 82func (c *Client) RepoDeleteRecord(ctx context.Context, input *atproto.RepoDeleteRecord_Input) (*atproto.RepoDeleteRecord_Output, error) { 83 var out atproto.RepoDeleteRecord_Output 84 if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "application/json", "com.atproto.repo.deleteRecord", nil, input, &out); err != nil { 85 return nil, err 86 } 87 88 return &out, nil 89}