func decodeListing(resp *httpclient.Response) (*Listing, error) { var value map[string]interface{} err := resp.DecodeJSON(&value) if err != nil { return nil, err } data, ok := value["data"].(map[string]interface{}) if !ok { return nil, ErrInvalidDataFormat } children, ok := data["children"].([]interface{}) if !ok { return nil, ErrInvalidDataFormat } var stories []*Story for _, v := range children { story, err := decodeStory(v) if err != nil { return nil, err } stories = append(stories, story) } return &Listing{ Stories: stories, }, nil }
func decodeResponseError(resp *httpclient.Response) error { c := &ErrorContainer{} if err := resp.DecodeJSON(&c); err != nil { return err } return fmt.Errorf("error from Facebook (type %v): %v", c.Error.Type, c.Error.Message) }
func parseJson(resp *httpclient.Response) (map[string]interface{}, error) { var m map[string]interface{} if err := resp.DecodeJSON(&m); err != nil { return nil, err } if rresp, ok := m["resource_response"].(map[string]interface{}); ok { if err, ok := rresp["error"].(map[string]interface{}); ok { msg, _ := err["message"].(string) if msg == "" { msg, _ = err["code"].(string) } return nil, errors.New(msg) } } return m, nil }
func decodeArgs(resp *httpclient.Response) (map[string]string, error) { var m map[string]interface{} if err := resp.DecodeJSON(&m); err != nil { return nil, err } var args map[string]interface{} if strings.HasSuffix(resp.Request.URL.Path, "post") { args = m["form"].(map[string]interface{}) } else { args = m["args"].(map[string]interface{}) } values := make(map[string]string, len(args)) for k, v := range args { values[k] = v.(string) } return values, nil }
func parseTwitterResponse(resp *httpclient.Response, out interface{}) error { if !resp.IsOK() { var message string var code int var errs twitterErrors if resp.DecodeJSON(&errs) == nil && len(errs.Errors) > 0 { message = errs.Errors[0].Message code = errs.Errors[0].Code } return &TwitterError{ Message: message, Code: code, StatusCode: resp.StatusCode, } } if err := resp.DecodeJSON(out); err != nil { return err } return nil }