this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refreshIdentity is POST

+46 -2
+46 -2
atproto/identity/apidir/apidir.go
··· 1 1 package apidir 2 2 3 3 import ( 4 + "bytes" 4 5 "context" 5 6 "encoding/json" 6 7 "fmt" ··· 93 94 return nil 94 95 } 95 96 97 + // body: struct pointer which can be `json.Unmarshal()` 98 + func (dir *APIDirectory) apiPost(ctx context.Context, u string, reqBody []byte, body any, errFail error, errNotFound error) error { 99 + req, err := http.NewRequestWithContext(ctx, "POST", u, bytes.NewBuffer(reqBody)) 100 + if err != nil { 101 + return fmt.Errorf("constructing HTTP request: %w", err) 102 + } 103 + req.Header.Set("Content-Type", "application/json") 104 + if dir.UserAgent != "" { 105 + req.Header.Set("User-Agent", dir.UserAgent) 106 + } 107 + resp, err := dir.Client.Do(req) 108 + if err != nil { 109 + return fmt.Errorf("%w: identity service HTTP: %w", errFail, err) 110 + } 111 + defer resp.Body.Close() 112 + b, err := io.ReadAll(resp.Body) 113 + if err != nil { 114 + return fmt.Errorf("%w: identity service HTTP: %w", errFail, err) 115 + } 116 + 117 + if resp.StatusCode == http.StatusNotFound { 118 + return errNotFound 119 + } 120 + if resp.StatusCode != http.StatusOK { 121 + // TODO: parse error body, handle more error conditions 122 + return fmt.Errorf("%w: identity service HTTP: %d", errFail, resp.StatusCode) 123 + } 124 + 125 + if err := json.Unmarshal(b, body); err != nil { 126 + return fmt.Errorf("%w: identity service HTTP: %w", errFail, err) 127 + } 128 + return nil 129 + } 130 + 96 131 func (dir *APIDirectory) ResolveDIDRaw(ctx context.Context, did syntax.DID) (json.RawMessage, error) { 97 132 var body didBody 98 133 u := dir.Host + "/xrpc/com.atproto.identity.resolveDid?did=" + did.String() ··· 165 200 } 166 201 167 202 func (dir *APIDirectory) Purge(ctx context.Context, atid syntax.AtIdentifier) error { 203 + 204 + input := map[string]string{ 205 + "identifier": atid.String(), 206 + } 207 + reqBody, err := json.Marshal(input) 208 + if err != nil { 209 + return err 210 + } 211 + 168 212 var body identityBody 169 - u := dir.Host + "/xrpc/com.atproto.identity.refreshIdentity?identifier=" + atid.String() 213 + u := dir.Host + "/xrpc/com.atproto.identity.refreshIdentity" 170 214 171 - if err := dir.apiGet(ctx, u, &body, identity.ErrDIDResolutionFailed, identity.ErrDIDNotFound); err != nil { 215 + if err := dir.apiPost(ctx, u, reqBody, &body, identity.ErrDIDResolutionFailed, identity.ErrDIDNotFound); err != nil { 172 216 return err 173 217 } 174 218