Browse Source

add support for new list all orgs method

Fixes #215.

Change-Id: Ic17192cc0b1dbe02745e4c7f76bd81457f73141a
Glenn Lewis 10 years ago
parent
commit
2741d95887
2 changed files with 56 additions and 0 deletions
  1. +33
    -0
      github/orgs.go
  2. +23
    -0
      github/orgs_test.go

+ 33
- 0
github/orgs.go View File

@ -68,6 +68,39 @@ func (p Plan) String() string {
return Stringify(p)
}
// OrganizationsListOptions specifies the optional parameters to the
// OrganizationsService.ListAll method.
type OrganizationsListOptions struct {
// Since filters Organizations by ID.
Since int `url:"since,omitempty"`
}
// ListAll lists all organizations, in the order that they were created on GitHub.
//
// Note: Pagination is powered exclusively by the since parameter. To continue
// listing the next set of organizations, use the ID of the last-returned organization
// as the opts.Since parameter for the next call.
//
// GitHub API docs: https://developer.github.com/v3/orgs/#list-all-organizations
func (s *OrganizationsService) ListAll(opt *OrganizationsListOptions) ([]Organization, *Response, error) {
u, err := addOptions("organizations", opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
orgs := []Organization{}
resp, err := s.client.Do(req, &orgs)
if err != nil {
return nil, resp, err
}
return orgs, resp, err
}
// List the organizations for a user. Passing the empty string will list
// organizations for the authenticated user.
//


+ 23
- 0
github/orgs_test.go View File

@ -13,6 +13,29 @@ import (
"testing"
)
func TestOrganizationsService_ListAll(t *testing.T) {
setup()
defer teardown()
since := 1342004
mux.HandleFunc("/organizations", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"since": "1342004"})
fmt.Fprint(w, `[{"id":4314092}]`)
})
opt := &OrganizationsListOptions{Since: since}
orgs, _, err := client.Organizations.ListAll(opt)
if err != nil {
t.Errorf("Organizations.ListAll returned error: %v", err)
}
want := []Organization{{ID: Int(4314092)}}
if !reflect.DeepEqual(orgs, want) {
t.Errorf("Organizations.ListAll returned %+v, want %+v", orgs, want)
}
}
func TestOrganizationsService_List_authenticatedUser(t *testing.T) {
setup()
defer teardown()


Loading…
Cancel
Save