Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit b86f6fc

Browse files
committed
Add support for Feeds API
Fixes google#191. Change-Id: I2fbcca9913cd20df75e9b5a5272a50879025d526
1 parent 111e26b commit b86f6fc

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed

github/activity.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,58 @@ package github
1212
type ActivityService struct {
1313
client *Client
1414
}
15+
16+
// FeedLink represents a link to a related resource.
17+
type FeedLink struct {
18+
HRef *string `json:"href,omitempty"`
19+
Type *string `json:"type,omitempty"`
20+
}
21+
22+
// Feeds represents timeline resources in Atom format.
23+
type Feeds struct {
24+
TimelineURL *string `json:"timeline_url,omitempty"`
25+
UserURL *string `json:"user_url,omitempty"`
26+
CurrentUserPublicURL *string `json:"current_user_public_url,omitempty"`
27+
CurrentUserURL *string `json:"current_user_url,omitempty"`
28+
CurrentUserActorURL *string `json:"current_user_actor_url,omitempty"`
29+
CurrentUserOrganizationURL *string `json:"current_user_organization_url,omitempty"`
30+
CurrentUserOrganizationURLs []string `json:"current_user_organization_urls,omitempty"`
31+
Links *struct {
32+
Timeline *FeedLink `json:"timeline,omitempty"`
33+
User *FeedLink `json:"user,omitempty"`
34+
CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"`
35+
CurrentUser *FeedLink `json:"current_user,omitempty"`
36+
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
37+
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
38+
CurrentUserOrganizations []FeedLink `json:"current_user_organizations,omitempty"`
39+
} `json:"_links,omitempty"`
40+
}
41+
42+
// ListFeeds lists all the feeds available to the authenticated user.
43+
//
44+
// GitHub provides several timeline resources in Atom format:
45+
// Timeline: The GitHub global public timeline
46+
// User: The public timeline for any user, using URI template
47+
// Current user public: The public timeline for the authenticated user
48+
// Current user: The private timeline for the authenticated user
49+
// Current user actor: The private timeline for activity created by the
50+
// authenticated user
51+
// Current user organizations: The private timeline for the organizations
52+
// the authenticated user is a member of.
53+
//
54+
// Note: Private feeds are only returned when authenticating via Basic Auth
55+
// since current feed URIs use the older, non revocable auth tokens.
56+
func (s *ActivityService) ListFeeds() (*Feeds, *Response, error) {
57+
req, err := s.client.NewRequest("GET", "feeds", nil)
58+
if err != nil {
59+
return nil, nil, err
60+
}
61+
62+
f := &Feeds{}
63+
resp, err := s.client.Do(req, f)
64+
if err != nil {
65+
return nil, resp, err
66+
}
67+
68+
return f, resp, nil
69+
}

github/activity_test.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright 2016 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+
"net/http"
10+
"reflect"
11+
"testing"
12+
)
13+
14+
func TestActivityService_List(t *testing.T) {
15+
setup()
16+
defer teardown()
17+
18+
mux.HandleFunc("/feeds", func(w http.ResponseWriter, r *http.Request) {
19+
testMethod(t, r, "GET")
20+
21+
w.WriteHeader(http.StatusOK)
22+
w.Write(feedsJSON)
23+
})
24+
25+
got, _, err := client.Activity.ListFeeds()
26+
if err != nil {
27+
t.Errorf("Activity.ListFeeds returned error: %v", err)
28+
}
29+
if want := wantFeeds; !reflect.DeepEqual(got, want) {
30+
t.Errorf("Activity.ListFeeds = %+v, want %+v", got, want)
31+
}
32+
}
33+
34+
var feedsJSON = []byte(`{
35+
"timeline_url": "https://github.com/timeline",
36+
"user_url": "https://github.com/{user}",
37+
"current_user_public_url": "https://github.com/defunkt",
38+
"current_user_url": "https://github.com/defunkt.private?token=abc123",
39+
"current_user_actor_url": "https://github.com/defunkt.private.actor?token=abc123",
40+
"current_user_organization_url": "",
41+
"current_user_organization_urls": [
42+
"https://github.com/organizations/github/defunkt.private.atom?token=abc123"
43+
],
44+
"_links": {
45+
"timeline": {
46+
"href": "https://github.com/timeline",
47+
"type": "application/atom+xml"
48+
},
49+
"user": {
50+
"href": "https://github.com/{user}",
51+
"type": "application/atom+xml"
52+
},
53+
"current_user_public": {
54+
"href": "https://github.com/defunkt",
55+
"type": "application/atom+xml"
56+
},
57+
"current_user": {
58+
"href": "https://github.com/defunkt.private?token=abc123",
59+
"type": "application/atom+xml"
60+
},
61+
"current_user_actor": {
62+
"href": "https://github.com/defunkt.private.actor?token=abc123",
63+
"type": "application/atom+xml"
64+
},
65+
"current_user_organization": {
66+
"href": "",
67+
"type": ""
68+
},
69+
"current_user_organizations": [
70+
{
71+
"href": "https://github.com/organizations/github/defunkt.private.atom?token=abc123",
72+
"type": "application/atom+xml"
73+
}
74+
]
75+
}
76+
}`)
77+
78+
var wantFeeds = &Feeds{
79+
TimelineURL: String("https://github.com/timeline"),
80+
UserURL: String("https://github.com/{user}"),
81+
CurrentUserPublicURL: String("https://github.com/defunkt"),
82+
CurrentUserURL: String("https://github.com/defunkt.private?token=abc123"),
83+
CurrentUserActorURL: String("https://github.com/defunkt.private.actor?token=abc123"),
84+
CurrentUserOrganizationURL: String(""),
85+
CurrentUserOrganizationURLs: []string{
86+
"https://github.com/organizations/github/defunkt.private.atom?token=abc123",
87+
},
88+
Links: &struct {
89+
Timeline *FeedLink `json:"timeline,omitempty"`
90+
User *FeedLink `json:"user,omitempty"`
91+
CurrentUserPublic *FeedLink `json:"current_user_public,omitempty"`
92+
CurrentUser *FeedLink `json:"current_user,omitempty"`
93+
CurrentUserActor *FeedLink `json:"current_user_actor,omitempty"`
94+
CurrentUserOrganization *FeedLink `json:"current_user_organization,omitempty"`
95+
CurrentUserOrganizations []FeedLink `json:"current_user_organizations,omitempty"`
96+
}{
97+
Timeline: &FeedLink{
98+
HRef: String("https://github.com/timeline"),
99+
Type: String("application/atom+xml"),
100+
},
101+
User: &FeedLink{
102+
HRef: String("https://github.com/{user}"),
103+
Type: String("application/atom+xml"),
104+
},
105+
CurrentUserPublic: &FeedLink{
106+
HRef: String("https://github.com/defunkt"),
107+
Type: String("application/atom+xml"),
108+
},
109+
CurrentUser: &FeedLink{
110+
HRef: String("https://github.com/defunkt.private?token=abc123"),
111+
Type: String("application/atom+xml"),
112+
},
113+
CurrentUserActor: &FeedLink{
114+
HRef: String("https://github.com/defunkt.private.actor?token=abc123"),
115+
Type: String("application/atom+xml"),
116+
},
117+
CurrentUserOrganization: &FeedLink{
118+
HRef: String(""),
119+
Type: String(""),
120+
},
121+
CurrentUserOrganizations: []FeedLink{
122+
{
123+
HRef: String("https://github.com/organizations/github/defunkt.private.atom?token=abc123"),
124+
Type: String("application/atom+xml"),
125+
},
126+
},
127+
},
128+
}

0 commit comments

Comments
 (0)