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
6package github
7
8import "context"
9
10// ActivityService handles communication with the activity related
11// methods of the GitHub API.
12//
13// GitHub API docs: https://developer.github.com/v3/activity/
14type ActivityService service
15
16// FeedLink represents a link to a related resource.
17type FeedLink struct {
18	HRef *string `json:"href,omitempty"`
19	Type *string `json:"type,omitempty"`
20}
21
22// Feeds represents timeline resources in Atom format.
23type 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.
56func (s *ActivityService) ListFeeds(ctx context.Context) (*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(ctx, req, f)
64	if err != nil {
65		return nil, resp, err
66	}
67
68	return f, resp, nil
69}
70