Browse Source

Restructured Activity Service and Event files.

Billy Lynch 13 years ago
parent
commit
8ee61256c3
6 changed files with 65 additions and 69 deletions
  1. +1
    -51
      github/activity.go
  2. +2
    -10
      github/activity_events.go
  3. +6
    -6
      github/activity_events_test.go
  4. +56
    -0
      github/activity_star.go
  5. +0
    -0
      github/activity_star_test.go
  6. +0
    -2
      github/github.go

+ 1
- 51
github/activity.go View File

@ -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
}

github/events.go → github/activity_events.go View File


github/events_test.go → github/activity_events_test.go View File


+ 56
- 0
github/activity_star.go View File

@ -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
}

github/activity_test.go → github/activity_star_test.go View File


+ 0
- 2
github/github.go View File

@ -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}


Loading…
Cancel
Save