diff --git a/github/activity.go b/github/activity.go index 491f9e7..886d06f 100644 --- a/github/activity.go +++ b/github/activity.go @@ -5,60 +5,10 @@ package github -import ( - "fmt" - "net/url" - "strconv" -) - // ActivityService handles communication with the activity related // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/users/ type ActivityService struct { - client *Client -} - -// ActivityListStarredOptions specifies the optional parameters to the -// ActivityService.ListStarred method. -type ActivityListStarredOptions struct { - // How to sort the repository list. Possible values are: created, updated, - // pushed, full_name. Default is "full_name". - Sort string - - // Direction in which to sort repositories. Possible values are: asc, desc. - // Default is "asc" when sort is "full_name", otherwise default is "desc". - Direction string - - // For paginated result sets, page of results to retrieve. - Page int -} - -// ListStarred lists all the repos starred by a user. Passing the empty string -// will list the starred repositories for the authenticated user. -// -// GitHub API docs: http://developer.github.com/v3/activity/starring/#list-repositories-being-starred -func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]Repository, error) { - var u string - if user != "" { - u = fmt.Sprintf("users/%v/starred", user) - } else { - u = "user/starred" - } - if opt != nil { - params := url.Values{ - "sort": []string{opt.Sort}, - "direction": []string{opt.Direction}, - "page": []string{strconv.Itoa(opt.Page)}, - } - u += "?" + params.Encode() - } - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, err - } - - repos := new([]Repository) - _, err = s.client.Do(req, repos) - return *repos, err + client *Client } diff --git a/github/events.go b/github/activity_events.go similarity index 86% rename from github/events.go rename to github/activity_events.go index 6251997..fcf72cc 100644 --- a/github/events.go +++ b/github/activity_events.go @@ -13,14 +13,6 @@ import ( "time" ) -// EventsService provides access to the event related functions -// in the GitHub API. -// -// GitHub API docs: http://developer.github.com/v3/activity/events/ -type EventsService struct { - client *Client -} - // Event represents a GitHub event. type Event struct { Type string `json:"type,omitempty"` @@ -66,11 +58,11 @@ type PushEventCommit struct { Distinct bool `json:"distinct"` } -// ListPerformedByUser lists the events performed by a user. If publicOnly is +// ListEventsPerformedByUser lists the events performed by a user. If publicOnly is // true, only public events will be returned. // // GitHub API docs: http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user -func (s *EventsService) ListPerformedByUser(user string, publicOnly bool, opt *ListOptions) ([]Event, error) { +func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool, opt *ListOptions) ([]Event, error) { var u string if publicOnly { u = fmt.Sprintf("users/%v/events/public", user) diff --git a/github/events_test.go b/github/activity_events_test.go similarity index 84% rename from github/events_test.go rename to github/activity_events_test.go index 723e4bc..63badf6 100644 --- a/github/events_test.go +++ b/github/activity_events_test.go @@ -13,7 +13,7 @@ import ( "testing" ) -func TestEventsService_ListPerformedByUser_all(t *testing.T) { +func TestEventsService_ListEventsPerformedByUser_all(t *testing.T) { setup() defer teardown() @@ -26,7 +26,7 @@ func TestEventsService_ListPerformedByUser_all(t *testing.T) { }) opt := &ListOptions{Page: 2} - events, err := client.Events.ListPerformedByUser("u", false, opt) + events, err := client.Activity.ListEventsPerformedByUser("u", false, opt) if err != nil { t.Errorf("Events.ListPerformedByUser returned error: %v", err) } @@ -37,7 +37,7 @@ func TestEventsService_ListPerformedByUser_all(t *testing.T) { } } -func TestEventsService_ListPerformedByUser_publicOnly(t *testing.T) { +func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) { setup() defer teardown() @@ -46,7 +46,7 @@ func TestEventsService_ListPerformedByUser_publicOnly(t *testing.T) { fmt.Fprint(w, `[{"id":"1"},{"id":"2"}]`) }) - events, err := client.Events.ListPerformedByUser("u", true, nil) + events, err := client.Activity.ListEventsPerformedByUser("u", true, nil) if err != nil { t.Errorf("Events.ListPerformedByUser returned error: %v", err) } @@ -57,7 +57,7 @@ func TestEventsService_ListPerformedByUser_publicOnly(t *testing.T) { } } -func TestEvent_Payload_typed(t *testing.T) { +func TestActivity_EventPayload_typed(t *testing.T) { raw := []byte(`{"type": "PushEvent","payload":{"push_id": 1}}`) var event *Event if err := json.Unmarshal(raw, &event); err != nil { @@ -73,7 +73,7 @@ func TestEvent_Payload_typed(t *testing.T) { // TestEvent_Payload_untyped checks that unrecognized events are parsed to an // interface{} value (instead of being discarded or throwing an error), for // forward compatibility with new event types. -func TestEvent_Payload_untyped(t *testing.T) { +func TestActivity_EventPayload_untyped(t *testing.T) { raw := []byte(`{"type": "UnrecognizedEvent","payload":{"field": "val"}}`) var event *Event if err := json.Unmarshal(raw, &event); err != nil { diff --git a/github/activity_star.go b/github/activity_star.go new file mode 100644 index 0000000..3437acd --- /dev/null +++ b/github/activity_star.go @@ -0,0 +1,56 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/url" + "strconv" +) + +// ActivityListStarredOptions specifies the optional parameters to the +// ActivityService.ListStarred method. +type ActivityListStarredOptions struct { + // How to sort the repository list. Possible values are: created, updated, + // pushed, full_name. Default is "full_name". + Sort string + + // Direction in which to sort repositories. Possible values are: asc, desc. + // Default is "asc" when sort is "full_name", otherwise default is "desc". + Direction string + + // For paginated result sets, page of results to retrieve. + Page int +} + +// ListStarred lists all the repos starred by a user. Passing the empty string +// will list the starred repositories for the authenticated user. +// +// GitHub API docs: http://developer.github.com/v3/activity/starring/#list-repositories-being-starred +func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]Repository, error) { + var u string + if user != "" { + u = fmt.Sprintf("users/%v/starred", user) + } else { + u = "user/starred" + } + if opt != nil { + params := url.Values{ + "sort": []string{opt.Sort}, + "direction": []string{opt.Direction}, + "page": []string{strconv.Itoa(opt.Page)}, + } + u += "?" + params.Encode() + } + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, err + } + + repos := new([]Repository) + _, err = s.client.Do(req, repos) + return *repos, err +} diff --git a/github/activity_test.go b/github/activity_star_test.go similarity index 100% rename from github/activity_test.go rename to github/activity_star_test.go diff --git a/github/github.go b/github/github.go index 9e3fc0a..51126f6 100644 --- a/github/github.go +++ b/github/github.go @@ -87,7 +87,6 @@ type Client struct { // Services used for talking to different parts of the API - Events *EventsService Issues *IssuesService Organizations *OrganizationsService PullRequests *PullRequestsService @@ -116,7 +115,6 @@ func NewClient(httpClient *http.Client) *Client { baseURL, _ := url.Parse(defaultBaseURL) c := &Client{client: httpClient, BaseURL: baseURL, UserAgent: userAgent} - c.Events = &EventsService{client: c} c.Issues = &IssuesService{client: c} c.Organizations = &OrganizationsService{client: c} c.PullRequests = &PullRequestsService{client: c}