Skip to content

Commit

Permalink
Add statuses/update API.
Browse files Browse the repository at this point in the history
  • Loading branch information
larrylv committed Jun 1, 2014
1 parent c1576dc commit 1938785
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
29 changes: 29 additions & 0 deletions weibo/statuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand All @@ -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
}
33 changes: 33 additions & 0 deletions weibo/statuses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 1938785

Please sign in to comment.