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)
| 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. |
| 194 | func (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. |
| 217 | type OAuthURIs struct { |
no test coverage detected