Skip to content

Commit 8ee6125

Browse files
committed
Restructured Activity Service and Event files.
1 parent 77ef915 commit 8ee6125

File tree

6 files changed

+65
-69
lines changed

6 files changed

+65
-69
lines changed

github/activity.go

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,10 @@
55

66
package github
77

8-
import (
9-
"fmt"
10-
"net/url"
11-
"strconv"
12-
)
13-
148
// ActivityService handles communication with the activity related
159
// methods of the GitHub API.
1610
//
1711
// GitHub API docs: http://developer.github.com/v3/users/
1812
type ActivityService struct {
19-
client *Client
20-
}
21-
22-
// ActivityListStarredOptions specifies the optional parameters to the
23-
// ActivityService.ListStarred method.
24-
type ActivityListStarredOptions struct {
25-
// How to sort the repository list. Possible values are: created, updated,
26-
// pushed, full_name. Default is "full_name".
27-
Sort string
28-
29-
// Direction in which to sort repositories. Possible values are: asc, desc.
30-
// Default is "asc" when sort is "full_name", otherwise default is "desc".
31-
Direction string
32-
33-
// For paginated result sets, page of results to retrieve.
34-
Page int
35-
}
36-
37-
// ListStarred lists all the repos starred by a user. Passing the empty string
38-
// will list the starred repositories for the authenticated user.
39-
//
40-
// GitHub API docs: http://developer.github.com/v3/activity/starring/#list-repositories-being-starred
41-
func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]Repository, error) {
42-
var u string
43-
if user != "" {
44-
u = fmt.Sprintf("users/%v/starred", user)
45-
} else {
46-
u = "user/starred"
47-
}
48-
if opt != nil {
49-
params := url.Values{
50-
"sort": []string{opt.Sort},
51-
"direction": []string{opt.Direction},
52-
"page": []string{strconv.Itoa(opt.Page)},
53-
}
54-
u += "?" + params.Encode()
55-
}
56-
req, err := s.client.NewRequest("GET", u, nil)
57-
if err != nil {
58-
return nil, err
59-
}
60-
61-
repos := new([]Repository)
62-
_, err = s.client.Do(req, repos)
63-
return *repos, err
13+
client *Client
6414
}

github/events.go renamed to github/activity_events.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ import (
1313
"time"
1414
)
1515

16-
// EventsService provides access to the event related functions
17-
// in the GitHub API.
18-
//
19-
// GitHub API docs: http://developer.github.com/v3/activity/events/
20-
type EventsService struct {
21-
client *Client
22-
}
23-
2416
// Event represents a GitHub event.
2517
type Event struct {
2618
Type string `json:"type,omitempty"`
@@ -66,11 +58,11 @@ type PushEventCommit struct {
6658
Distinct bool `json:"distinct"`
6759
}
6860

69-
// ListPerformedByUser lists the events performed by a user. If publicOnly is
61+
// ListEventsPerformedByUser lists the events performed by a user. If publicOnly is
7062
// true, only public events will be returned.
7163
//
7264
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user
73-
func (s *EventsService) ListPerformedByUser(user string, publicOnly bool, opt *ListOptions) ([]Event, error) {
65+
func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool, opt *ListOptions) ([]Event, error) {
7466
var u string
7567
if publicOnly {
7668
u = fmt.Sprintf("users/%v/events/public", user)

github/events_test.go renamed to github/activity_events_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"testing"
1414
)
1515

16-
func TestEventsService_ListPerformedByUser_all(t *testing.T) {
16+
func TestEventsService_ListEventsPerformedByUser_all(t *testing.T) {
1717
setup()
1818
defer teardown()
1919

@@ -26,7 +26,7 @@ func TestEventsService_ListPerformedByUser_all(t *testing.T) {
2626
})
2727

2828
opt := &ListOptions{Page: 2}
29-
events, err := client.Events.ListPerformedByUser("u", false, opt)
29+
events, err := client.Activity.ListEventsPerformedByUser("u", false, opt)
3030
if err != nil {
3131
t.Errorf("Events.ListPerformedByUser returned error: %v", err)
3232
}
@@ -37,7 +37,7 @@ func TestEventsService_ListPerformedByUser_all(t *testing.T) {
3737
}
3838
}
3939

40-
func TestEventsService_ListPerformedByUser_publicOnly(t *testing.T) {
40+
func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) {
4141
setup()
4242
defer teardown()
4343

@@ -46,7 +46,7 @@ func TestEventsService_ListPerformedByUser_publicOnly(t *testing.T) {
4646
fmt.Fprint(w, `[{"id":"1"},{"id":"2"}]`)
4747
})
4848

49-
events, err := client.Events.ListPerformedByUser("u", true, nil)
49+
events, err := client.Activity.ListEventsPerformedByUser("u", true, nil)
5050
if err != nil {
5151
t.Errorf("Events.ListPerformedByUser returned error: %v", err)
5252
}
@@ -57,7 +57,7 @@ func TestEventsService_ListPerformedByUser_publicOnly(t *testing.T) {
5757
}
5858
}
5959

60-
func TestEvent_Payload_typed(t *testing.T) {
60+
func TestActivity_EventPayload_typed(t *testing.T) {
6161
raw := []byte(`{"type": "PushEvent","payload":{"push_id": 1}}`)
6262
var event *Event
6363
if err := json.Unmarshal(raw, &event); err != nil {
@@ -73,7 +73,7 @@ func TestEvent_Payload_typed(t *testing.T) {
7373
// TestEvent_Payload_untyped checks that unrecognized events are parsed to an
7474
// interface{} value (instead of being discarded or throwing an error), for
7575
// forward compatibility with new event types.
76-
func TestEvent_Payload_untyped(t *testing.T) {
76+
func TestActivity_EventPayload_untyped(t *testing.T) {
7777
raw := []byte(`{"type": "UnrecognizedEvent","payload":{"field": "val"}}`)
7878
var event *Event
7979
if err := json.Unmarshal(raw, &event); err != nil {

github/activity_star.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2013 The go-github AUTHORS. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
6+
package github
7+
8+
import (
9+
"fmt"
10+
"net/url"
11+
"strconv"
12+
)
13+
14+
// ActivityListStarredOptions specifies the optional parameters to the
15+
// ActivityService.ListStarred method.
16+
type ActivityListStarredOptions struct {
17+
// How to sort the repository list. Possible values are: created, updated,
18+
// pushed, full_name. Default is "full_name".
19+
Sort string
20+
21+
// Direction in which to sort repositories. Possible values are: asc, desc.
22+
// Default is "asc" when sort is "full_name", otherwise default is "desc".
23+
Direction string
24+
25+
// For paginated result sets, page of results to retrieve.
26+
Page int
27+
}
28+
29+
// ListStarred lists all the repos starred by a user. Passing the empty string
30+
// will list the starred repositories for the authenticated user.
31+
//
32+
// GitHub API docs: http://developer.github.com/v3/activity/starring/#list-repositories-being-starred
33+
func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]Repository, error) {
34+
var u string
35+
if user != "" {
36+
u = fmt.Sprintf("users/%v/starred", user)
37+
} else {
38+
u = "user/starred"
39+
}
40+
if opt != nil {
41+
params := url.Values{
42+
"sort": []string{opt.Sort},
43+
"direction": []string{opt.Direction},
44+
"page": []string{strconv.Itoa(opt.Page)},
45+
}
46+
u += "?" + params.Encode()
47+
}
48+
req, err := s.client.NewRequest("GET", u, nil)
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
repos := new([]Repository)
54+
_, err = s.client.Do(req, repos)
55+
return *repos, err
56+
}
File renamed without changes.

github/github.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ type Client struct {
8787

8888
// Services used for talking to different parts of the API
8989

90-
Events *EventsService
9190
Issues *IssuesService
9291
Organizations *OrganizationsService
9392
PullRequests *PullRequestsService
@@ -116,7 +115,6 @@ func NewClient(httpClient *http.Client) *Client {
116115
baseURL, _ := url.Parse(defaultBaseURL)
117116

118117
c := &Client{client: httpClient, BaseURL: baseURL, UserAgent: userAgent}
119-
c.Events = &EventsService{client: c}
120118
c.Issues = &IssuesService{client: c}
121119
c.Organizations = &OrganizationsService{client: c}
122120
c.PullRequests = &PullRequestsService{client: c}

0 commit comments

Comments
 (0)