MCPcopy
hub / github.com/perkeep/perkeep / PopulateJSONFromURL

Method PopulateJSONFromURL

pkg/importer/oauth.go:194–214  ·  view source on GitHub ↗

PopulateJSONFromURL makes a POST or GET call at apiURL, using keyval as parameters of the associated form. The JSON response is decoded into result.

(result interface{}, method string, apiURL string, keyval ...string)

Source from the content-addressed store, hash-verified

192// PopulateJSONFromURL makes a POST or GET call at apiURL, using keyval as parameters of
193// the associated form. The JSON response is decoded into result.
194func (octx OAuthContext) PopulateJSONFromURL(result interface{}, method string, apiURL string, keyval ...string) error {
195 if method != http.MethodGet && method != http.MethodPost {
196 return fmt.Errorf("only HTTP Get or Post supported: found %v", method)
197 }
198 if len(keyval)%2 == 1 {
199 return errors.New("incorrect number of keyval arguments. must be even")
200 }
201 form := url.Values{}
202 for i := 0; i < len(keyval); i += 2 {
203 form.Set(keyval[i], keyval[i+1])
204 }
205 hres, err := octx.do(method, apiURL, form)
206 if err != nil {
207 return err
208 }
209 err = httputil.DecodeJSON(hres, result)
210 if err != nil {
211 return fmt.Errorf("could not parse response for %s: %v", apiURL, err)
212 }
213 return err
214}
215
216// OAuthURIs holds the URIs needed to initialize an OAuth 1 client.
217type OAuthURIs struct {

Callers 5

doAPIMethod · 0.80
getUserInfoFunction · 0.80
getUserInfoFunction · 0.80
doAPIMethod · 0.80
flickrAPIRequestMethod · 0.80

Calls 3

doMethod · 0.95
DecodeJSONFunction · 0.92
SetMethod · 0.65

Tested by

no test coverage detected