(method, path string, data interface{}, headers map[string]string, ttl int)
| 856 | } |
| 857 | |
| 858 | func (client *Client) GenericAPIRequest(method, path string, data interface{}, headers map[string]string, ttl int) (*simpleResponse, error) { |
| 859 | api, err := client.simpleApi() |
| 860 | if err != nil { |
| 861 | return nil, err |
| 862 | } |
| 863 | api.CacheTTL = ttl |
| 864 | |
| 865 | var body io.Reader |
| 866 | switch d := data.(type) { |
| 867 | case map[string]interface{}: |
| 868 | if method == "GET" { |
| 869 | path = addQuery(path, d) |
| 870 | } else if len(d) > 0 { |
| 871 | json, err := json.Marshal(d) |
| 872 | if err != nil { |
| 873 | return nil, err |
| 874 | } |
| 875 | body = bytes.NewBuffer(json) |
| 876 | } |
| 877 | case io.Reader: |
| 878 | body = d |
| 879 | } |
| 880 | |
| 881 | return api.performRequest(method, path, body, func(req *http.Request) { |
| 882 | if body != nil { |
| 883 | req.Header.Set("Content-Type", "application/json; charset=utf-8") |
| 884 | } |
| 885 | for key, value := range headers { |
| 886 | req.Header.Set(key, value) |
| 887 | } |
| 888 | }) |
| 889 | } |
| 890 | |
| 891 | // GraphQL facilitates performing a GraphQL request and parsing the response |
| 892 | func (client *Client) GraphQL(query string, variables interface{}, data interface{}) error { |
no test coverage detected