forked from tangled.org/core
this repo has no description
at opengraph 2.3 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 "github.com/haileyok/atproto-oauth-golang" 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) RepoGetRecord(ctx context.Context, cid string, collection string, repo string, rkey string) (*atproto.RepoGetRecord_Output, error) { 35 var out atproto.RepoGetRecord_Output 36 37 params := map[string]interface{}{ 38 "cid": cid, 39 "collection": collection, 40 "repo": repo, 41 "rkey": rkey, 42 } 43 if err := c.Do(ctx, c.authArgs, xrpc.Query, "", "com.atproto.repo.getRecord", params, nil, &out); err != nil { 44 return nil, err 45 } 46 47 return &out, nil 48} 49 50func (c *Client) RepoUploadBlob(ctx context.Context, input io.Reader) (*atproto.RepoUploadBlob_Output, error) { 51 var out atproto.RepoUploadBlob_Output 52 if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "*/*", "com.atproto.repo.uploadBlob", nil, input, &out); err != nil { 53 return nil, err 54 } 55 56 return &out, nil 57} 58 59func (c *Client) SyncGetBlob(ctx context.Context, cid string, did string) ([]byte, error) { 60 buf := new(bytes.Buffer) 61 62 params := map[string]interface{}{ 63 "cid": cid, 64 "did": did, 65 } 66 if err := c.Do(ctx, c.authArgs, xrpc.Query, "", "com.atproto.sync.getBlob", params, nil, buf); err != nil { 67 return nil, err 68 } 69 70 return buf.Bytes(), nil 71} 72 73func (c *Client) RepoDeleteRecord(ctx context.Context, input *atproto.RepoDeleteRecord_Input) (*atproto.RepoDeleteRecord_Output, error) { 74 var out atproto.RepoDeleteRecord_Output 75 if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "application/json", "com.atproto.repo.deleteRecord", nil, input, &out); err != nil { 76 return nil, err 77 } 78 79 return &out, nil 80}