octodoggy 4.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/CONTRIBUTING.md +22 -0
- data/LICENSE.md +20 -0
- data/README.md +714 -0
- data/Rakefile +22 -0
- data/lib/ext/sawyer/relation.rb +10 -0
- data/lib/octokit.rb +59 -0
- data/lib/octokit/arguments.rb +14 -0
- data/lib/octokit/authentication.rb +82 -0
- data/lib/octokit/client.rb +238 -0
- data/lib/octokit/client/authorizations.rb +244 -0
- data/lib/octokit/client/commit_comments.rb +95 -0
- data/lib/octokit/client/commits.rb +239 -0
- data/lib/octokit/client/contents.rb +162 -0
- data/lib/octokit/client/deployments.rb +62 -0
- data/lib/octokit/client/downloads.rb +50 -0
- data/lib/octokit/client/emojis.rb +18 -0
- data/lib/octokit/client/events.rb +151 -0
- data/lib/octokit/client/feeds.rb +33 -0
- data/lib/octokit/client/gists.rb +233 -0
- data/lib/octokit/client/gitignore.rb +43 -0
- data/lib/octokit/client/hooks.rb +297 -0
- data/lib/octokit/client/integrations.rb +77 -0
- data/lib/octokit/client/issues.rb +321 -0
- data/lib/octokit/client/labels.rb +156 -0
- data/lib/octokit/client/legacy_search.rb +42 -0
- data/lib/octokit/client/licenses.rb +45 -0
- data/lib/octokit/client/markdown.rb +27 -0
- data/lib/octokit/client/meta.rb +21 -0
- data/lib/octokit/client/milestones.rb +87 -0
- data/lib/octokit/client/notifications.rb +171 -0
- data/lib/octokit/client/objects.rb +141 -0
- data/lib/octokit/client/organizations.rb +768 -0
- data/lib/octokit/client/pages.rb +63 -0
- data/lib/octokit/client/projects.rb +314 -0
- data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
- data/lib/octokit/client/pull_requests.rb +301 -0
- data/lib/octokit/client/rate_limit.rb +54 -0
- data/lib/octokit/client/reactions.rb +158 -0
- data/lib/octokit/client/refs.rb +118 -0
- data/lib/octokit/client/releases.rb +163 -0
- data/lib/octokit/client/repositories.rb +654 -0
- data/lib/octokit/client/repository_invitations.rb +103 -0
- data/lib/octokit/client/reviews.rb +174 -0
- data/lib/octokit/client/say.rb +19 -0
- data/lib/octokit/client/search.rb +76 -0
- data/lib/octokit/client/service_status.rb +38 -0
- data/lib/octokit/client/source_import.rb +161 -0
- data/lib/octokit/client/stats.rb +105 -0
- data/lib/octokit/client/statuses.rb +47 -0
- data/lib/octokit/client/traffic.rb +69 -0
- data/lib/octokit/client/users.rb +354 -0
- data/lib/octokit/configurable.rb +147 -0
- data/lib/octokit/connection.rb +199 -0
- data/lib/octokit/default.rb +166 -0
- data/lib/octokit/enterprise_admin_client.rb +40 -0
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
- data/lib/octokit/enterprise_admin_client/license.rb +18 -0
- data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
- data/lib/octokit/enterprise_admin_client/users.rb +128 -0
- data/lib/octokit/enterprise_management_console_client.rb +50 -0
- data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
- data/lib/octokit/error.rb +286 -0
- data/lib/octokit/gist.rb +36 -0
- data/lib/octokit/middleware/follow_redirects.rb +131 -0
- data/lib/octokit/organization.rb +17 -0
- data/lib/octokit/preview.rb +38 -0
- data/lib/octokit/rate_limit.rb +33 -0
- data/lib/octokit/repo_arguments.rb +19 -0
- data/lib/octokit/repository.rb +93 -0
- data/lib/octokit/response/feed_parser.rb +21 -0
- data/lib/octokit/response/raise_error.rb +21 -0
- data/lib/octokit/user.rb +19 -0
- data/lib/octokit/version.rb +17 -0
- data/lib/octokit/warnable.rb +17 -0
- data/octokit.gemspec +22 -0
- metadata +160 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Repository Statistics API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/statistics/
|
7
|
+
module Stats
|
8
|
+
|
9
|
+
# Get contributors list with additions, deletions, and commit counts
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
12
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
13
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
14
|
+
# @return [Array<Sawyer::Resource>] Array of contributor stats
|
15
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-contributors-list-with-additions-deletions-and-commit-counts
|
16
|
+
# @example Get contributor stats for octokit
|
17
|
+
# @client.contributors_stats('octokit/octokit.rb')
|
18
|
+
def contributors_stats(repo, options = {})
|
19
|
+
get_stats(repo, "contributors", options)
|
20
|
+
end
|
21
|
+
alias :contributor_stats :contributors_stats
|
22
|
+
|
23
|
+
# Get the last year of commit activity data
|
24
|
+
#
|
25
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
26
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
27
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
28
|
+
# @return [Array<Sawyer::Resource>] The last year of commit activity grouped by
|
29
|
+
# week. The days array is a group of commits per day, starting on Sunday.
|
30
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity-data
|
31
|
+
# @example Get commit activity for octokit
|
32
|
+
# @client.commit_activity_stats('octokit/octokit.rb')
|
33
|
+
def commit_activity_stats(repo, options = {})
|
34
|
+
get_stats(repo, "commit_activity", options)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get the number of additions and deletions per week
|
38
|
+
#
|
39
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
40
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
41
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
42
|
+
# @return [Array<Sawyer::Resource>] Weekly aggregate of the number of additions
|
43
|
+
# and deletions pushed to a repository.
|
44
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-number-of-additions-and-deletions-per-week
|
45
|
+
# @example Get code frequency stats for octokit
|
46
|
+
# @client.code_frequency_stats('octokit/octokit.rb')
|
47
|
+
def code_frequency_stats(repo, options = {})
|
48
|
+
get_stats(repo, "code_frequency", options)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get the weekly commit count for the repo owner and everyone else
|
52
|
+
#
|
53
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
54
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
55
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
56
|
+
# @return [Sawyer::Resource] Total commit counts for the owner and total commit
|
57
|
+
# counts in all. all is everyone combined, including the owner in the last
|
58
|
+
# 52 weeks. If you’d like to get the commit counts for non-owners, you can
|
59
|
+
# subtract all from owner.
|
60
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-weekly-commit-count-for-the-repository-owner-and-everyone-else
|
61
|
+
# @example Get weekly commit counts for octokit
|
62
|
+
# @client.participation_stats("octokit/octokit.rb")
|
63
|
+
def participation_stats(repo, options = {})
|
64
|
+
get_stats(repo, "participation", options)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get the number of commits per hour in each day
|
68
|
+
#
|
69
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
70
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
71
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
72
|
+
# @return [Array<Array>] Arrays containing the day number, hour number, and
|
73
|
+
# number of commits
|
74
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-number-of-commits-per-hour-in-each-day
|
75
|
+
# @example Get octokit punch card
|
76
|
+
# @octokit.punch_card_stats
|
77
|
+
def punch_card_stats(repo, options = {})
|
78
|
+
get_stats(repo, "punch_card", options)
|
79
|
+
end
|
80
|
+
alias :punch_card :punch_card_stats
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
# @private Get stats for a repository
|
85
|
+
#
|
86
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
87
|
+
# @param metric [String] The metrics you are looking for
|
88
|
+
# @return [Array<Sawyer::Resource> or nil] Stats in metric-specific format, or nil if not yet calculated.
|
89
|
+
# @see https://developer.github.com/v3/repos/statistics/
|
90
|
+
def get_stats(repo, metric, options = {})
|
91
|
+
if retry_timeout = options.delete(:retry_timeout)
|
92
|
+
retry_wait = options.delete(:retry_wait) || 0.5
|
93
|
+
timeout = Time.now + retry_timeout
|
94
|
+
end
|
95
|
+
loop do
|
96
|
+
data = get("#{Repository.path repo}/stats/#{metric}", options)
|
97
|
+
return data if last_response.status == 200
|
98
|
+
return nil unless retry_timeout
|
99
|
+
return nil if Time.now >= timeout
|
100
|
+
sleep retry_wait if retry_wait
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Commit Statuses API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/statuses/
|
7
|
+
module Statuses
|
8
|
+
|
9
|
+
# List all statuses for a given commit
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
12
|
+
# @param sha [String] The SHA1 for the commit
|
13
|
+
# @return [Array<Sawyer::Resource>] A list of statuses
|
14
|
+
# @see https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
|
15
|
+
def statuses(repo, sha, options = {})
|
16
|
+
get "#{Repository.path repo}/statuses/#{sha}", options
|
17
|
+
end
|
18
|
+
alias :list_statuses :statuses
|
19
|
+
|
20
|
+
# Get the combined status for a ref
|
21
|
+
#
|
22
|
+
# @param repo [Integer, String, Repository, Hash] a GitHub repository
|
23
|
+
# @param ref [String] A Sha or Ref to fetch the status of
|
24
|
+
# @return [Sawyer::Resource] The combined status for the commit
|
25
|
+
# @see https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
|
26
|
+
def combined_status(repo, ref, options = {})
|
27
|
+
get "#{Repository.path repo}/commits/#{ref}/status", options
|
28
|
+
end
|
29
|
+
alias :status :combined_status
|
30
|
+
|
31
|
+
# Create status for a commit
|
32
|
+
#
|
33
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
34
|
+
# @param sha [String] The SHA1 for the commit
|
35
|
+
# @param state [String] The state: pending, success, failure, error
|
36
|
+
# @option options [String] :context A context to differentiate this status from others
|
37
|
+
# @option options [String] :target_url A link to more details about this status
|
38
|
+
# @option options [String] :description A short human-readable description of this status
|
39
|
+
# @return [Sawyer::Resource] A status
|
40
|
+
# @see https://developer.github.com/v3/repos/statuses/#create-a-status
|
41
|
+
def create_status(repo, sha, state, options = {})
|
42
|
+
options.merge!(:state => state)
|
43
|
+
post "#{Repository.path repo}/statuses/#{sha}", options
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Traffic API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/traffic/
|
7
|
+
module Traffic
|
8
|
+
|
9
|
+
# Get the top 10 referrers over the last 14 days
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
12
|
+
# @return [Array<Sawyer::Resource>] List of referrers and stats
|
13
|
+
# @see https://developer.github.com/v3/repos/traffic/#list-referrers
|
14
|
+
# @example
|
15
|
+
# @client.top_referrers('octokit/octokit.rb')
|
16
|
+
def top_referrers(repo, options = {})
|
17
|
+
opts = ensure_api_media_type(:traffic, options)
|
18
|
+
get "#{Repository.path repo}/traffic/popular/referrers", opts
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get the top 10 popular contents over the last 14 days
|
22
|
+
#
|
23
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
24
|
+
# @return [Array<Sawyer::Resource>] List of popular contents
|
25
|
+
# @see https://developer.github.com/v3/repos/traffic/#list-paths
|
26
|
+
# @example
|
27
|
+
# @client.top_paths('octokit/octokit.rb')
|
28
|
+
def top_paths(repo, options = {})
|
29
|
+
opts = ensure_api_media_type(:traffic, options)
|
30
|
+
get "#{Repository.path repo}/traffic/popular/paths", opts
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get the total number of views and breakdown per day or week for the
|
34
|
+
# last 14 days
|
35
|
+
#
|
36
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub Repository
|
37
|
+
# @option options [String] :per ('day') Views per. <tt>day</tt> or
|
38
|
+
# <tt>week</tt>
|
39
|
+
# @return [Sawyer::Resource] Breakdown of view stats
|
40
|
+
# @see https://developer.github.com/v3/repos/traffic/#views
|
41
|
+
# @example Views per day
|
42
|
+
# @client.views('octokit/octokit.rb')
|
43
|
+
# @example Views per week
|
44
|
+
# @client.views('octokit/octokit.rb', per: 'week')
|
45
|
+
def views(repo, options = {})
|
46
|
+
opts = ensure_api_media_type(:traffic, options)
|
47
|
+
get "#{Repository.path repo}/traffic/views", opts
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get the total number of clones and breakdown per day or week for the
|
51
|
+
# last 14 days
|
52
|
+
#
|
53
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub Repository
|
54
|
+
# @option options [String] :per ('day') Views per. <tt>day</tt> or
|
55
|
+
# <tt>week</tt>
|
56
|
+
# @return [Sawyer::Resource] Breakdown of clone stats
|
57
|
+
# @see https://developer.github.com/v3/repos/traffic/#clones
|
58
|
+
# @example Clones per day
|
59
|
+
# @client.clones('octokit/octokit.rb')
|
60
|
+
# @example Clones per week
|
61
|
+
# @client.clones('octokit/octokit.rb', per: 'week')
|
62
|
+
def clones(repo, options = {})
|
63
|
+
opts = ensure_api_media_type(:traffic, options)
|
64
|
+
get "#{Repository.path repo}/traffic/clones", opts
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,354 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Users API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/users/
|
7
|
+
module Users
|
8
|
+
|
9
|
+
# List all GitHub users
|
10
|
+
#
|
11
|
+
# This provides a list of every user, in the order that they signed up
|
12
|
+
# for GitHub.
|
13
|
+
#
|
14
|
+
# @param options [Hash] Optional options.
|
15
|
+
# @option options [Integer] :since The integer ID of the last User that
|
16
|
+
# you’ve seen.
|
17
|
+
#
|
18
|
+
# @see https://developer.github.com/v3/users/#get-all-users
|
19
|
+
#
|
20
|
+
# @return [Array<Sawyer::Resource>] List of GitHub users.
|
21
|
+
def all_users(options = {})
|
22
|
+
paginate "users", options
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get a single user
|
26
|
+
#
|
27
|
+
# @param user [Integer, String] GitHub user login or id.
|
28
|
+
# @return [Sawyer::Resource]
|
29
|
+
# @see https://developer.github.com/v3/users/#get-a-single-user
|
30
|
+
# @see https://developer.github.com/v3/users/#get-the-authenticated-user
|
31
|
+
# @example
|
32
|
+
# Octokit.user("sferik")
|
33
|
+
def user(user=nil, options = {})
|
34
|
+
get User.path(user), options
|
35
|
+
end
|
36
|
+
|
37
|
+
# Retrieve the access_token.
|
38
|
+
#
|
39
|
+
# @param code [String] Authorization code generated by GitHub.
|
40
|
+
# @param app_id [String] Client Id we received when our application was registered with GitHub. Defaults to client_id.
|
41
|
+
# @param app_secret [String] Client Secret we received when our application was registered with GitHub. Defaults to client_secret.
|
42
|
+
# @return [Sawyer::Resource] Hash holding the access token.
|
43
|
+
# @see https://developer.github.com/v3/oauth/#web-application-flow
|
44
|
+
# @example
|
45
|
+
# Octokit.exchange_code_for_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'})
|
46
|
+
def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {})
|
47
|
+
options.merge!({
|
48
|
+
:code => code,
|
49
|
+
:client_id => app_id,
|
50
|
+
:client_secret => app_secret,
|
51
|
+
:headers => {
|
52
|
+
:content_type => 'application/json',
|
53
|
+
:accept => 'application/json'
|
54
|
+
}
|
55
|
+
})
|
56
|
+
post "#{web_endpoint}login/oauth/access_token", options
|
57
|
+
end
|
58
|
+
|
59
|
+
# Validate user username and password
|
60
|
+
#
|
61
|
+
# @param options [Hash] User credentials
|
62
|
+
# @option options [String] :login GitHub login
|
63
|
+
# @option options [String] :password GitHub password
|
64
|
+
# @return [Boolean] True if credentials are valid
|
65
|
+
def validate_credentials(options = {})
|
66
|
+
!self.class.new(options).user.nil?
|
67
|
+
rescue Octokit::Unauthorized
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
# Update the authenticated user
|
72
|
+
#
|
73
|
+
# @param options [Hash] A customizable set of options.
|
74
|
+
# @option options [String] :name
|
75
|
+
# @option options [String] :email Publically visible email address.
|
76
|
+
# @option options [String] :blog
|
77
|
+
# @option options [String] :company
|
78
|
+
# @option options [String] :location
|
79
|
+
# @option options [Boolean] :hireable
|
80
|
+
# @option options [String] :bio
|
81
|
+
# @return [Sawyer::Resource]
|
82
|
+
# @see https://developer.github.com/v3/users/#update-the-authenticated-user
|
83
|
+
# @example
|
84
|
+
# Octokit.update_user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)
|
85
|
+
def update_user(options)
|
86
|
+
patch "user", options
|
87
|
+
end
|
88
|
+
|
89
|
+
# Get a user's followers.
|
90
|
+
#
|
91
|
+
# @param user [Integer, String] GitHub user login or id of the user whose
|
92
|
+
# list of followers you are getting.
|
93
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing users
|
94
|
+
# followers.
|
95
|
+
# @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user
|
96
|
+
# @example
|
97
|
+
# Octokit.followers('pengwynn')
|
98
|
+
def followers(user=login, options = {})
|
99
|
+
paginate "#{User.path user}/followers", options
|
100
|
+
end
|
101
|
+
|
102
|
+
# Get list of users a user is following.
|
103
|
+
#
|
104
|
+
# @param user [Intger, String] GitHub user login or id of the user who you
|
105
|
+
# are getting the list of the people they follow.
|
106
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing users a
|
107
|
+
# user is following.
|
108
|
+
# @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
|
109
|
+
# @example
|
110
|
+
# Octokit.following('pengwynn')
|
111
|
+
def following(user=login, options = {})
|
112
|
+
paginate "#{User.path user}/following", options
|
113
|
+
end
|
114
|
+
|
115
|
+
# Check if you are following a user. Alternatively, check if a given user
|
116
|
+
# is following a target user.
|
117
|
+
#
|
118
|
+
# Requries an authenticated client.
|
119
|
+
#
|
120
|
+
# @overload follows?(target)
|
121
|
+
# @param target [String] GitHub login of the user that you want to
|
122
|
+
# check if you are following.
|
123
|
+
# @overload follows?(user, target)
|
124
|
+
# @param user [Integer, String] GitHub user login or id of first user
|
125
|
+
# @param target [String] GitHub login of the target user
|
126
|
+
# @return [Boolean] True following target user, false otherwise.
|
127
|
+
# @see https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user
|
128
|
+
# @see https://developer.github.com/v3/users/followers/#check-if-one-user-follows-another
|
129
|
+
# @example
|
130
|
+
# @client.follows?('pengwynn')
|
131
|
+
# @example
|
132
|
+
# @client.follows?('catsby', 'pengwynn')
|
133
|
+
def follows?(*args)
|
134
|
+
target = args.pop
|
135
|
+
user = args.first
|
136
|
+
boolean_from_response :get, "#{User.path user}/following/#{target}"
|
137
|
+
end
|
138
|
+
|
139
|
+
# Follow a user.
|
140
|
+
#
|
141
|
+
# Requires authenticatied client.
|
142
|
+
#
|
143
|
+
# @param user [String] Username of the user to follow.
|
144
|
+
# @return [Boolean] True if follow was successful, false otherwise.
|
145
|
+
# @see https://developer.github.com/v3/users/followers/#follow-a-user
|
146
|
+
# @example
|
147
|
+
# @client.follow('holman')
|
148
|
+
def follow(user, options = {})
|
149
|
+
boolean_from_response :put, "user/following/#{user}", options
|
150
|
+
end
|
151
|
+
|
152
|
+
# Unfollow a user.
|
153
|
+
#
|
154
|
+
# Requires authenticated client.
|
155
|
+
#
|
156
|
+
# @param user [String] Username of the user to unfollow.
|
157
|
+
# @return [Boolean] True if unfollow was successful, false otherwise.
|
158
|
+
# @see https://developer.github.com/v3/users/followers/#unfollow-a-user
|
159
|
+
# @example
|
160
|
+
# @client.unfollow('holman')
|
161
|
+
def unfollow(user, options = {})
|
162
|
+
boolean_from_response :delete, "user/following/#{user}", options
|
163
|
+
end
|
164
|
+
|
165
|
+
# Get list of repos starred by a user.
|
166
|
+
#
|
167
|
+
# @param user [Integer, String] GitHub user login of the user to get the
|
168
|
+
# list of their starred repositories.
|
169
|
+
# @param options [Hash] Optional options
|
170
|
+
# @option options [String] :sort (created) Sort: <tt>created</tt> or <tt>updated</tt>.
|
171
|
+
# @option options [String] :direction (desc) Direction: <tt>asc</tt> or <tt>desc</tt>.
|
172
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing repositories starred by user.
|
173
|
+
# @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
|
174
|
+
# @example
|
175
|
+
# Octokit.starred('pengwynn')
|
176
|
+
def starred(user=login, options = {})
|
177
|
+
paginate user_path(user, 'starred'), options
|
178
|
+
end
|
179
|
+
|
180
|
+
# Check if you are starring a repo.
|
181
|
+
#
|
182
|
+
# Requires authenticated client.
|
183
|
+
#
|
184
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
185
|
+
# @return [Boolean] True if you are following the repo, false otherwise.
|
186
|
+
# @see https://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository
|
187
|
+
# @example
|
188
|
+
# @client.starred?('pengwynn/octokit')
|
189
|
+
def starred?(repo, options = {})
|
190
|
+
boolean_from_response :get, "user/starred/#{Repository.new(repo)}", options
|
191
|
+
end
|
192
|
+
|
193
|
+
# Get a public key.
|
194
|
+
#
|
195
|
+
# Note, when using dot notation to retrieve the values, ruby will return
|
196
|
+
# the hash key for the public keys value instead of the actual value, use
|
197
|
+
# symbol or key string to retrieve the value. See example.
|
198
|
+
#
|
199
|
+
# Requires authenticated client.
|
200
|
+
#
|
201
|
+
# @param key_id [Integer] Key to retreive.
|
202
|
+
# @return [Sawyer::Resource] Hash representing the key.
|
203
|
+
# @see https://developer.github.com/v3/users/keys/#get-a-single-public-key
|
204
|
+
# @example
|
205
|
+
# @client.key(1)
|
206
|
+
# @example Retrieve public key contents
|
207
|
+
# public_key = @client.key(1)
|
208
|
+
# public_key.key
|
209
|
+
# # => Error
|
210
|
+
#
|
211
|
+
# public_key[:key]
|
212
|
+
# # => "ssh-rsa AAA..."
|
213
|
+
#
|
214
|
+
# public_key['key']
|
215
|
+
# # => "ssh-rsa AAA..."
|
216
|
+
def key(key_id, options = {})
|
217
|
+
get "user/keys/#{key_id}", options
|
218
|
+
end
|
219
|
+
|
220
|
+
# Get list of public keys for user.
|
221
|
+
#
|
222
|
+
# Requires authenticated client.
|
223
|
+
#
|
224
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing public keys.
|
225
|
+
# @see https://developer.github.com/v3/users/keys/#list-your-public-keys
|
226
|
+
# @example
|
227
|
+
# @client.keys
|
228
|
+
def keys(options = {})
|
229
|
+
paginate "user/keys", options
|
230
|
+
end
|
231
|
+
|
232
|
+
# Get list of public keys for user.
|
233
|
+
#
|
234
|
+
# @param user [Integer, String] GitHub user login or id.
|
235
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing public keys.
|
236
|
+
# @see https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
|
237
|
+
# @example
|
238
|
+
# @client.user_keys('pengwynn')
|
239
|
+
def user_keys(user, options = {})
|
240
|
+
# TODO: Roll this into .keys
|
241
|
+
paginate "#{User.path user}/keys", options
|
242
|
+
end
|
243
|
+
|
244
|
+
# Add public key to user account.
|
245
|
+
#
|
246
|
+
# Requires authenticated client.
|
247
|
+
#
|
248
|
+
# @param title [String] Title to give reference to the public key.
|
249
|
+
# @param key [String] Public key.
|
250
|
+
# @return [Sawyer::Resource] Hash representing the newly added public key.
|
251
|
+
# @see https://developer.github.com/v3/users/keys/#create-a-public-key
|
252
|
+
# @example
|
253
|
+
# @client.add_key('Personal projects key', 'ssh-rsa AAA...')
|
254
|
+
def add_key(title, key, options = {})
|
255
|
+
post "user/keys", options.merge({:title => title, :key => key})
|
256
|
+
end
|
257
|
+
|
258
|
+
# Update a public key
|
259
|
+
#
|
260
|
+
# Requires authenticated client
|
261
|
+
#
|
262
|
+
# @param key_id [Integer] Id of key to update.
|
263
|
+
# @param options [Hash] Hash containing attributes to update.
|
264
|
+
# @option options [String] :title
|
265
|
+
# @option options [String] :key
|
266
|
+
# @return [Sawyer::Resource] Hash representing the updated public key.
|
267
|
+
#
|
268
|
+
# @deprecated This method is no longer supported in the API
|
269
|
+
# @see https://developer.github.com/v3/users/keys/#update-a-public-key
|
270
|
+
# @see https://developer.github.com/changes/2014-02-24-finer-grained-scopes-for-ssh-keys/
|
271
|
+
# @example
|
272
|
+
# @client.update_key(1, :title => 'new title', :key => "ssh-rsa BBB")
|
273
|
+
def update_key(key_id, options = {})
|
274
|
+
patch "user/keys/#{key_id}", options
|
275
|
+
end
|
276
|
+
|
277
|
+
# Remove a public key from user account.
|
278
|
+
#
|
279
|
+
# Requires authenticated client.
|
280
|
+
#
|
281
|
+
# @param id [String] Id of the public key to remove.
|
282
|
+
# @return [Boolean] True if removal was successful, false otherwise.
|
283
|
+
# @see https://developer.github.com/v3/users/keys/#delete-a-public-key
|
284
|
+
# @example
|
285
|
+
# @client.remove_key(1)
|
286
|
+
def remove_key(id, options = {})
|
287
|
+
boolean_from_response :delete, "user/keys/#{id}", options
|
288
|
+
end
|
289
|
+
|
290
|
+
# List email addresses for a user.
|
291
|
+
#
|
292
|
+
# Requires authenticated client.
|
293
|
+
#
|
294
|
+
# @return [Array<String>] Array of email addresses.
|
295
|
+
# @see https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
|
296
|
+
# @example
|
297
|
+
# @client.emails
|
298
|
+
def emails(options = {})
|
299
|
+
paginate "user/emails", options
|
300
|
+
end
|
301
|
+
|
302
|
+
# Add email address to user.
|
303
|
+
#
|
304
|
+
# Requires authenticated client.
|
305
|
+
#
|
306
|
+
# @param email [String] Email address to add to the user.
|
307
|
+
# @return [Array<String>] Array of all email addresses of the user.
|
308
|
+
# @see https://developer.github.com/v3/users/emails/#add-email-addresses
|
309
|
+
# @example
|
310
|
+
# @client.add_email('new_email@user.com')
|
311
|
+
def add_email(email, options = {})
|
312
|
+
email = Array(email)
|
313
|
+
post "user/emails", email
|
314
|
+
end
|
315
|
+
|
316
|
+
# Remove email from user.
|
317
|
+
#
|
318
|
+
# Requires authenticated client.
|
319
|
+
#
|
320
|
+
# @param email [String] Email address to remove.
|
321
|
+
# @return [Array<String>] Array of all email addresses of the user.
|
322
|
+
# @see https://developer.github.com/v3/users/emails/#delete-email-addresses
|
323
|
+
# @example
|
324
|
+
# @client.remove_email('old_email@user.com')
|
325
|
+
def remove_email(email)
|
326
|
+
email = Array(email)
|
327
|
+
boolean_from_response :delete, "user/emails", email
|
328
|
+
end
|
329
|
+
|
330
|
+
# List repositories being watched by a user.
|
331
|
+
#
|
332
|
+
# @param user [Integer, String] GitHub user login or id.
|
333
|
+
# @return [Array<Sawyer::Resource>] Array of repositories.
|
334
|
+
# @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
|
335
|
+
# @example
|
336
|
+
# @client.subscriptions("pengwynn")
|
337
|
+
def subscriptions(user=login, options = {})
|
338
|
+
paginate user_path(user, 'subscriptions'), options
|
339
|
+
end
|
340
|
+
alias :watched :subscriptions
|
341
|
+
|
342
|
+
end
|
343
|
+
|
344
|
+
private
|
345
|
+
# convenience method for constructing a user specific path, if the user is logged in
|
346
|
+
def user_path(user, path)
|
347
|
+
if user == login && user_authenticated?
|
348
|
+
"user/#{path}"
|
349
|
+
else
|
350
|
+
"#{User.path user}/#{path}"
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|