diff --git a/weibo/statuses.go b/weibo/statuses.go index 04eb288..8eb43f8 100644 --- a/weibo/statuses.go +++ b/weibo/statuses.go @@ -43,6 +43,18 @@ type StatusListOptions struct { ListOptions } +// UpdateOptions specifies the optional parameters to the +// StatusService.Update method. +type UpdateOptions struct { + Status *string `json:status` + Visible *int `json:visible,omitempty` + ListID *int `json:list_id,omitempty` + Lat *float64 `json:lat,omitempty` + Long *float64 `json:long,omitempty` + Annotations *string `json:annotations,omitempty` + RealIP *string `json:rip,omitempty` +} + // Timeline for a user. Passing the empty string will return // timeline for the authenticated user. // @@ -66,3 +78,20 @@ func (s *StatusesService) UserTimeline(opt *StatusListOptions) (*Timeline, *Resp return timeline, resp, err } + +func (s *StatusesService) Update(opt *UpdateOptions) (*Status, *Response, error) { + u := "statuses/update" + + req, err := s.client.NewRequest("POST", u, opt) + if err != nil { + return nil, nil, err + } + + status := &Status{} + resp, err := s.client.Do(req, status) + if err != nil { + return nil, resp, err + } + + return status, resp, err +} diff --git a/weibo/statuses_test.go b/weibo/statuses_test.go index e35e9f9..02cbfa3 100644 --- a/weibo/statuses_test.go +++ b/weibo/statuses_test.go @@ -33,3 +33,36 @@ func TestUserTimeline(t *testing.T) { t.Errorf("Statuses.UserTimeline returned %+v, want %+v", timeline, want) } } + +func TestUpdate(t *testing.T) { + setup() + defer teardown() + + text := "Hello, weibo!" + visible := 2 + + mux.HandleFunc("/2/statuses/update", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + + fmt.Fprint(w, + ` + { + "id" : 1, + "text" : "Hello, weibo!", + "visible": 1 + } + `) + }) + + opt := &UpdateOptions{Status: String(text), Visible: Int(visible)} + status, _, err := client.Statuses.Update(opt) + + if err != nil { + t.Errorf("Statuses.Update returned error %v", err) + } + + want := &Status{ID: Int(1), Text: String("Hello, weibo!"), Visible: Int(1)} + if !reflect.DeepEqual(status, want) { + t.Errorf("Statuses.Update returned %+v, want %+v", status, want) + } +}