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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/CONTRIBUTING.md +22 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +714 -0
  6. data/Rakefile +22 -0
  7. data/lib/ext/sawyer/relation.rb +10 -0
  8. data/lib/octokit.rb +59 -0
  9. data/lib/octokit/arguments.rb +14 -0
  10. data/lib/octokit/authentication.rb +82 -0
  11. data/lib/octokit/client.rb +238 -0
  12. data/lib/octokit/client/authorizations.rb +244 -0
  13. data/lib/octokit/client/commit_comments.rb +95 -0
  14. data/lib/octokit/client/commits.rb +239 -0
  15. data/lib/octokit/client/contents.rb +162 -0
  16. data/lib/octokit/client/deployments.rb +62 -0
  17. data/lib/octokit/client/downloads.rb +50 -0
  18. data/lib/octokit/client/emojis.rb +18 -0
  19. data/lib/octokit/client/events.rb +151 -0
  20. data/lib/octokit/client/feeds.rb +33 -0
  21. data/lib/octokit/client/gists.rb +233 -0
  22. data/lib/octokit/client/gitignore.rb +43 -0
  23. data/lib/octokit/client/hooks.rb +297 -0
  24. data/lib/octokit/client/integrations.rb +77 -0
  25. data/lib/octokit/client/issues.rb +321 -0
  26. data/lib/octokit/client/labels.rb +156 -0
  27. data/lib/octokit/client/legacy_search.rb +42 -0
  28. data/lib/octokit/client/licenses.rb +45 -0
  29. data/lib/octokit/client/markdown.rb +27 -0
  30. data/lib/octokit/client/meta.rb +21 -0
  31. data/lib/octokit/client/milestones.rb +87 -0
  32. data/lib/octokit/client/notifications.rb +171 -0
  33. data/lib/octokit/client/objects.rb +141 -0
  34. data/lib/octokit/client/organizations.rb +768 -0
  35. data/lib/octokit/client/pages.rb +63 -0
  36. data/lib/octokit/client/projects.rb +314 -0
  37. data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
  38. data/lib/octokit/client/pull_requests.rb +301 -0
  39. data/lib/octokit/client/rate_limit.rb +54 -0
  40. data/lib/octokit/client/reactions.rb +158 -0
  41. data/lib/octokit/client/refs.rb +118 -0
  42. data/lib/octokit/client/releases.rb +163 -0
  43. data/lib/octokit/client/repositories.rb +654 -0
  44. data/lib/octokit/client/repository_invitations.rb +103 -0
  45. data/lib/octokit/client/reviews.rb +174 -0
  46. data/lib/octokit/client/say.rb +19 -0
  47. data/lib/octokit/client/search.rb +76 -0
  48. data/lib/octokit/client/service_status.rb +38 -0
  49. data/lib/octokit/client/source_import.rb +161 -0
  50. data/lib/octokit/client/stats.rb +105 -0
  51. data/lib/octokit/client/statuses.rb +47 -0
  52. data/lib/octokit/client/traffic.rb +69 -0
  53. data/lib/octokit/client/users.rb +354 -0
  54. data/lib/octokit/configurable.rb +147 -0
  55. data/lib/octokit/connection.rb +199 -0
  56. data/lib/octokit/default.rb +166 -0
  57. data/lib/octokit/enterprise_admin_client.rb +40 -0
  58. data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
  59. data/lib/octokit/enterprise_admin_client/license.rb +18 -0
  60. data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
  61. data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
  62. data/lib/octokit/enterprise_admin_client/users.rb +128 -0
  63. data/lib/octokit/enterprise_management_console_client.rb +50 -0
  64. data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
  65. data/lib/octokit/error.rb +286 -0
  66. data/lib/octokit/gist.rb +36 -0
  67. data/lib/octokit/middleware/follow_redirects.rb +131 -0
  68. data/lib/octokit/organization.rb +17 -0
  69. data/lib/octokit/preview.rb +38 -0
  70. data/lib/octokit/rate_limit.rb +33 -0
  71. data/lib/octokit/repo_arguments.rb +19 -0
  72. data/lib/octokit/repository.rb +93 -0
  73. data/lib/octokit/response/feed_parser.rb +21 -0
  74. data/lib/octokit/response/raise_error.rb +21 -0
  75. data/lib/octokit/user.rb +19 -0
  76. data/lib/octokit/version.rb +17 -0
  77. data/lib/octokit/warnable.rb +17 -0
  78. data/octokit.gemspec +22 -0
  79. metadata +160 -0
@@ -0,0 +1,156 @@
1
+ require 'cgi'
2
+
3
+ module Octokit
4
+ class Client
5
+
6
+ # Methods for the Issue Labels API
7
+ #
8
+ # @see https://developer.github.com/v3/issues/labels/
9
+ module Labels
10
+
11
+ # List available labels for a repository
12
+ #
13
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
14
+ # @return [Array<Sawyer::Resource>] A list of the labels across the repository
15
+ # @see https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
16
+ # @example List labels for octokit/octokit.rb
17
+ # Octokit.labels("octokit/octokit.rb")
18
+ def labels(repo, options = {})
19
+ paginate "#{Repository.path repo}/labels", options
20
+ end
21
+
22
+ # Get single label for a repository
23
+ #
24
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
25
+ # @param name [String] Name of the label
26
+ # @return [Sawyer::Resource] A single label from the repository
27
+ # @see https://developer.github.com/v3/issues/labels/#get-a-single-label
28
+ # @example Get the "V3 Addition" label from octokit/octokit.rb
29
+ # Octokit.labels("octokit/octokit.rb", "V3 Addition")
30
+ def label(repo, name, options = {})
31
+ get "#{Repository.path repo}/labels/#{name}", options
32
+ end
33
+
34
+ # Add a label to a repository
35
+ #
36
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
37
+ # @param label [String] A new label
38
+ # @param color [String] A color, in hex, without the leading #
39
+ # @return [Sawyer::Resource] The new label
40
+ # @see https://developer.github.com/v3/issues/labels/#create-a-label
41
+ # @example Add a new label "Version 1.0" with color "#cccccc"
42
+ # Octokit.add_label("octokit/octokit.rb", "Version 1.0", "cccccc")
43
+ def add_label(repo, label, color="ffffff", options = {})
44
+ post "#{Repository.path repo}/labels", options.merge({:name => label, :color => color})
45
+ end
46
+
47
+ # Update a label
48
+ #
49
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
50
+ # @param label [String] The name of the label which will be updated
51
+ # @param options [Hash] A customizable set of options.
52
+ # @option options [String] :name An updated label name
53
+ # @option options [String] :color An updated color value, in hex, without leading #
54
+ # @return [Sawyer::Resource] The updated label
55
+ # @see https://developer.github.com/v3/issues/labels/#update-a-label
56
+ # @example Update the label "Version 1.0" with new color "#cceeaa"
57
+ # Octokit.update_label("octokit/octokit.rb", "Version 1.0", {:color => "cceeaa"})
58
+ def update_label(repo, label, options = {})
59
+ patch "#{Repository.path repo}/labels/#{label}", options
60
+ end
61
+
62
+ # Delete a label from a repository.
63
+ #
64
+ # This deletes the label from the repository, and removes it from all issues.
65
+ #
66
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
67
+ # @param label [String] String name of the label
68
+ # @return [Boolean] Success
69
+ # @see https://developer.github.com/v3/issues/labels/#delete-a-label
70
+ # @example Delete the label "Version 1.0" from the repository.
71
+ # Octokit.delete_label!("octokit/octokit.rb", "Version 1.0")
72
+ def delete_label!(repo, label, options = {})
73
+ boolean_from_response :delete, "#{Repository.path repo}/labels/#{label}", options
74
+ end
75
+
76
+ # Remove a label from an Issue
77
+ #
78
+ # This removes the label from the Issue
79
+ #
80
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
81
+ # @param number [Integer] Number ID of the issue
82
+ # @param label [String] String name of the label
83
+ # @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
84
+ # @see https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
85
+ # @example Remove the label "Version 1.0" from the repository.
86
+ # Octokit.remove_label("octokit/octokit.rb", 23, "Version 1.0")
87
+ def remove_label(repo, number, label, options = {})
88
+ delete "#{Repository.path repo}/issues/#{number}/labels/#{label}", options
89
+ end
90
+
91
+ # Remove all label from an Issue
92
+ #
93
+ # This removes the label from the Issue
94
+ #
95
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
96
+ # @param number [Integer] Number ID of the issue
97
+ # @return [Boolean] Success of operation
98
+ # @see https://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue
99
+ # @example Remove all labels from Issue #23
100
+ # Octokit.remove_all_labels("octokit/octokit.rb", 23)
101
+ def remove_all_labels(repo, number, options = {})
102
+ boolean_from_response :delete, "#{Repository.path repo}/issues/#{number}/labels", options
103
+ end
104
+
105
+ # List labels for a given issue
106
+ #
107
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
108
+ # @param number [Integer] Number ID of the issue
109
+ # @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
110
+ # @see https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
111
+ # @example List labels for octokit/octokit.rb, issue # 1
112
+ # Octokit.labels_for_issue("octokit/octokit.rb", 1)
113
+ def labels_for_issue(repo, number, options = {})
114
+ paginate "#{Repository.path repo}/issues/#{number}/labels", options
115
+ end
116
+
117
+ # Add label(s) to an Issue
118
+ #
119
+ # @param repo [Integer, String, Repository, Hash] A Github repository
120
+ # @param number [Integer] Number ID of the issue
121
+ # @param labels [Array] An array of labels to apply to this Issue
122
+ # @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
123
+ # @see https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue
124
+ # @example Add two labels for octokit/octokit.rb
125
+ # Octokit.add_labels_to_an_issue("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement'])
126
+ def add_labels_to_an_issue(repo, number, labels)
127
+ post "#{Repository.path repo}/issues/#{number}/labels", labels
128
+ end
129
+
130
+ # Replace all labels on an Issue
131
+ #
132
+ # @param repo [Integer, String, Repository, Hash] A Github repository
133
+ # @param number [Integer] Number ID of the issue
134
+ # @param labels [Array] An array of labels to use as replacement
135
+ # @return [Array<Sawyer::Resource>] A list of the labels currently on the issue
136
+ # @see https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
137
+ # @example Replace labels for octokit/octokit.rb Issue #10
138
+ # Octokit.replace_all_labels("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement'])
139
+ def replace_all_labels(repo, number, labels, options = {})
140
+ put "#{Repository.path repo}/issues/#{number}/labels", labels
141
+ end
142
+
143
+ # Get labels for every issue in a milestone
144
+ #
145
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
146
+ # @param number [Integer] Number ID of the milestone
147
+ # @return [Array<Sawyer::Resource>] A list of the labels across the milestone
148
+ # @see http://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
149
+ # @example List all labels for milestone #2 on octokit/octokit.rb
150
+ # Octokit.labels_for_milestone("octokit/octokit.rb", 2)
151
+ def labels_for_milestone(repo, number, options = {})
152
+ paginate "#{Repository.path repo}/milestones/#{number}/labels", options
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,42 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Legacy Search API
5
+ #
6
+ # @see https://developer.github.com/v3/search/
7
+ module LegacySearch
8
+
9
+ # Legacy repository search
10
+ #
11
+ # @see https://developer.github.com/v3/search/#search-repositories
12
+ # @param q [String] Search keyword
13
+ # @return [Array<Sawyer::Resource>] List of repositories found
14
+ def legacy_search_repositories(q, options = {})
15
+ get("legacy/repos/search/#{q}", options)['repositories']
16
+ end
17
+
18
+ # Legacy search issues within a repository
19
+ #
20
+ # @param repo [String, Repository, Hash] A GitHub repository
21
+ # @param search_term [String] The term to search for
22
+ # @param state [String] :state (open) <tt>open</tt> or <tt>closed</tt>.
23
+ # @return [Array<Sawyer::Resource>] A list of issues matching the search term and state
24
+ # @example Search for 'test' in the open issues for sferik/rails_admin
25
+ # Octokit.search_issues("sferik/rails_admin", 'test', 'open')
26
+ def legacy_search_issues(repo, search_term, state='open', options = {})
27
+ get("legacy/issues/search/#{Repository.new(repo)}/#{state}/#{search_term}", options)['issues']
28
+ end
29
+
30
+ # Search for user.
31
+ #
32
+ # @param search [String] User to search for.
33
+ # @return [Array<Sawyer::Resource>] Array of hashes representing users.
34
+ # @see https://developer.github.com/v3/search/#search-users
35
+ # @example
36
+ # Octokit.search_users('pengwynn')
37
+ def legacy_search_users(search, options = {})
38
+ get("legacy/user/search/#{search}", options)['users']
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,45 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for licenses API
5
+ #
6
+ module Licenses
7
+
8
+ # List all licenses
9
+ #
10
+ # @see https://developer.github.com/v3/licenses/#list-all-licenses
11
+ # @return [Array<Sawyer::Resource>] A list of licenses
12
+ # @example
13
+ # Octokit.licenses
14
+ def licenses(options = {})
15
+ options = ensure_api_media_type(:licenses, options)
16
+ paginate "licenses", options
17
+ end
18
+
19
+ # List an individual license
20
+ #
21
+ # @see https://developer.github.com/v3/licenses/#get-an-individual-license
22
+ # @param license_name [String] The license name
23
+ # @return <Sawyer::Resource> An individual license
24
+ # @example
25
+ # Octokit.license 'mit'
26
+ def license(license_name, options = {})
27
+ options = ensure_api_media_type(:licenses, options)
28
+ get "licenses/#{license_name}", options
29
+ end
30
+
31
+ # Returns the contents of the repository’s license file, if one is detected.
32
+ #
33
+ # @see https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license
34
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
35
+ # @option options [String] :ref name of the Commit/Branch/Tag. Defaults to 'master'.
36
+ # @return [Sawyer::Resource] The detail of the license file
37
+ # @example
38
+ # Octokit.license_contents 'benbalter/licensee'
39
+ def repository_license_contents(repo, options = {})
40
+ options = ensure_api_media_type(:licenses, options)
41
+ get "#{Repository.path repo}/license", options
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Markdown API
5
+ #
6
+ # @see https://developer.github.com/v3/markdown/
7
+ module Markdown
8
+
9
+ # Render an arbitrary Markdown document
10
+ #
11
+ # @param text [String] Markdown source
12
+ # @option options [String] (optional) :mode (`markdown` or `gfm`)
13
+ # @option options [String] (optional) :context Repo context
14
+ # @return [String] HTML renderization
15
+ # @see https://developer.github.com/v3/markdown/#render-an-arbitrary-markdown-document
16
+ # @example Render some GFM
17
+ # Octokit.markdown('Fixed in #111', :mode => "gfm", :context => "octokit/octokit.rb")
18
+ def markdown(text, options = {})
19
+ options[:text] = text
20
+ options[:repo] = Repository.new(options[:repo]) if options[:repo]
21
+ options[:accept] = 'application/vnd.github.raw'
22
+
23
+ post "markdown", options
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Meta API
5
+ #
6
+ # @see https://developer.github.com/v3/meta/
7
+ module Meta
8
+
9
+ # Get meta information about GitHub.com, the service.
10
+ # @see https://developer.github.com/v3/meta/#meta
11
+ # @return [Sawyer::Resource] Hash with meta information.
12
+ # @example Get GitHub meta information
13
+ # @client.github_meta
14
+ def meta(options = {})
15
+ get "meta", options
16
+ end
17
+ alias :github_meta :meta
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,87 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Issues Milestones API
5
+ #
6
+ # @see https://developer.github.com/v3/issues/milestones/
7
+ module Milestones
8
+
9
+ # List milestones for a repository
10
+ #
11
+ # @param repository [Integer, String, Repository, Hash] A GitHub repository
12
+ # @param options [Hash] A customizable set of options.
13
+ # @option options [Integer] :milestone Milestone number.
14
+ # @option options [String] :state (open) State: <tt>open</tt>, <tt>closed</tt>, or <tt>all</tt>.
15
+ # @option options [String] :sort (created) Sort: <tt>created</tt>, <tt>updated</tt>, or <tt>comments</tt>.
16
+ # @option options [String] :direction (desc) Direction: <tt>asc</tt> or <tt>desc</tt>.
17
+ # @return [Array<Sawyer::Resource>] A list of milestones for a repository.
18
+ # @see https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
19
+ # @example List milestones for a repository
20
+ # Octokit.list_milestones("octokit/octokit.rb")
21
+ def list_milestones(repository, options = {})
22
+ paginate "#{Repository.path repository}/milestones", options
23
+ end
24
+ alias :milestones :list_milestones
25
+
26
+ # Get a single milestone for a repository
27
+ #
28
+ # @param repository [Integer, String, Repository, Hash] A GitHub repository
29
+ # @param options [Hash] A customizable set of options.
30
+ # @option options [Integer] :milestone Milestone number.
31
+ # @return [Sawyer::Resource] A single milestone from a repository.
32
+ # @see https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
33
+ # @example Get a single milestone for a repository
34
+ # Octokit.milestone("octokit/octokit.rb", 1)
35
+ def milestone(repository, number, options = {})
36
+ get "#{Repository.path repository}/milestones/#{number}", options
37
+ end
38
+
39
+ # Create a milestone for a repository
40
+ #
41
+ # @param repository [Integer, String, Repository, Hash] A GitHub repository
42
+ # @param title [String] A unique title.
43
+ # @param options [Hash] A customizable set of options.
44
+ # @option options [String] :state (open) State: <tt>open</tt> or <tt>closed</tt>.
45
+ # @option options [String] :description A meaningful description
46
+ # @option options [Time] :due_on Set if the milestone has a due date
47
+ # @return [Sawyer::Resource] A single milestone object
48
+ # @see https://developer.github.com/v3/issues/milestones/#create-a-milestone
49
+ # @example Create a milestone for a repository
50
+ # Octokit.create_milestone("octokit/octokit.rb", "0.7.0", {:description => 'Add support for v3 of Github API'})
51
+ def create_milestone(repository, title, options = {})
52
+ post "#{Repository.path repository}/milestones", options.merge({:title => title})
53
+ end
54
+
55
+ # Update a milestone for a repository
56
+ #
57
+ # @param repository [Integer, String, Repository, Hash] A GitHub repository
58
+ # @param number [String, Integer] ID of the milestone
59
+ # @param options [Hash] A customizable set of options.
60
+ # @option options [String] :title A unique title.
61
+ # @option options [String] :state (open) State: <tt>open</tt> or <tt>closed</tt>.
62
+ # @option options [String] :description A meaningful description
63
+ # @option options [Time] :due_on Set if the milestone has a due date
64
+ # @return [Sawyer::Resource] A single milestone object
65
+ # @see https://developer.github.com/v3/issues/milestones/#update-a-milestone
66
+ # @example Update a milestone for a repository
67
+ # Octokit.update_milestone("octokit/octokit.rb", 1, {:description => 'Add support for v3 of Github API'})
68
+ def update_milestone(repository, number, options = {})
69
+ patch "#{Repository.path repository}/milestones/#{number}", options
70
+ end
71
+ alias :edit_milestone :update_milestone
72
+
73
+ # Delete a single milestone for a repository
74
+ #
75
+ # @param repository [Integer, String, Repository, Hash] A GitHub repository
76
+ # @param options [Hash] A customizable set of options.
77
+ # @option options [Integer] :milestone Milestone number.
78
+ # @return [Boolean] Success
79
+ # @see https://developer.github.com/v3/issues/milestones/#delete-a-milestone
80
+ # @example Delete a single milestone from a repository
81
+ # Octokit.delete_milestone("octokit/octokit.rb", 1)
82
+ def delete_milestone(repository, number, options = {})
83
+ boolean_from_response :delete, "#{Repository.path repository}/milestones/#{number}", options
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,171 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Notifications API
5
+ #
6
+ # @see https://developer.github.com/v3/activity/notifications/
7
+ module Notifications
8
+
9
+ # List your notifications
10
+ #
11
+ # @param options [Hash] Optional parameters
12
+ # @option options [Boolean] :all 'true' to show notifications marked as
13
+ # read.
14
+ # @option options [Boolean] :participating 'true' to show only
15
+ # notifications in which the user is directly participating or
16
+ # mentioned.
17
+ # @option options [String] :since Time filters out any notifications
18
+ # updated before the given time. The time should be passed in as UTC in
19
+ # the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
20
+ # @return [Array<Sawyer::Resource>] Array of notifications.
21
+ # @see https://developer.github.com/v3/activity/notifications/#list-your-notifications
22
+ # @example Get users notifications
23
+ # @client.notifications
24
+ # @example Get all notifications since a certain time.
25
+ # @client.notifications({all: true, since: '2012-10-09T23:39:01Z'})
26
+ def notifications(options = {})
27
+ paginate "notifications", options
28
+ end
29
+
30
+ # List your notifications in a repository
31
+ #
32
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
33
+ # @param options [Hash] Optional parameters
34
+ # @option options [Boolean] :all 'true' to show notifications marked as
35
+ # read.
36
+ # @option options [Boolean] :participating 'true' to show only
37
+ # notifications in which the user is directly participating or
38
+ # mentioned.
39
+ # @option options [String] :since Time filters out any notifications
40
+ # updated before the given time. The time should be passed in as UTC in
41
+ # the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
42
+ # @return [Array<Sawyer::Resource>] Array of notifications.
43
+ # @see https://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
44
+ # @example Get your notifications for octokit/octokit.rb
45
+ # @client.repository_notifications('octokit/octokit.rb')
46
+ # @example Get your notifications for octokit/octokit.rb since a time.
47
+ # @client.repository_notifications({since: '2012-10-09T23:39:01Z'})
48
+ def repository_notifications(repo, options = {})
49
+ paginate "#{Repository.path repo}/notifications", options
50
+ end
51
+ alias :repo_notifications :repository_notifications
52
+
53
+ # Mark notifications as read
54
+ #
55
+ # @param options [Hash] Optional parameters
56
+ # @option options [Boolean] :unread Changes the unread status of the
57
+ # threads.
58
+ # @option options [Boolean] :read Inverse of 'unread'.
59
+ # @option options [String] :last_read_at ('Now') Describes the last point
60
+ # that notifications were checked. Anything updated since this time
61
+ # will not be updated. The time should be passed in as UTC in the
62
+ # ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
63
+ # @return [Boolean] True if marked as read, false otherwise
64
+ # @see https://developer.github.com/v3/activity/notifications/#mark-as-read
65
+ #
66
+ # @example
67
+ # @client.mark_notifications_as_read
68
+ def mark_notifications_as_read(options = {})
69
+ request :put, "notifications", options
70
+
71
+ last_response.status == 205
72
+ end
73
+
74
+ # Mark notifications from a specific repository as read
75
+ #
76
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
77
+ # @param options [Hash] Optional parameters
78
+ # @option options [Boolean] :unread Changes the unread status of the
79
+ # threads.
80
+ # @option options [Boolean] :read Inverse of 'unread'.
81
+ # @option options [String] :last_read_at ('Now') Describes the last point
82
+ # that notifications were checked. Anything updated since this time
83
+ # will not be updated. The time should be passed in as UTC in the
84
+ # ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
85
+ # @return [Boolean] True if marked as read, false otherwise
86
+ # @see https://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
87
+ # @example
88
+ # @client.mark_notifications_as_read("octokit/octokit.rb")
89
+ def mark_repository_notifications_as_read(repo, options = {})
90
+ request :put, "#{Repository.path repo}/notifications", options
91
+
92
+ last_response.status == 205
93
+ end
94
+ alias :mark_repo_notifications_as_read :mark_repository_notifications_as_read
95
+
96
+ # List notifications for a specific thread
97
+ #
98
+ # @param thread_id [Integer] Id of the thread.
99
+ # @return [Array<Sawyer::Resource>] Array of notifications.
100
+ # @see https://developer.github.com/v3/activity/notifications/#view-a-single-thread
101
+ #
102
+ # @example
103
+ # @client.notification_thread(1000)
104
+ def thread_notifications(thread_id, options = {})
105
+ get "notifications/threads/#{thread_id}", options
106
+ end
107
+
108
+ # Mark thread as read
109
+ #
110
+ # @param thread_id [Integer] Id of the thread to update.
111
+ # @param options [Hash] Optional parameters.
112
+ # @option options [Boolean] :unread Changes the unread status of the
113
+ # threads.
114
+ # @option options [Boolean] :read Inverse of 'unread'.
115
+ # @return [Boolean] True if updated, false otherwise.
116
+ # @see https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
117
+ # @example
118
+ # @client.mark_thread_as_read(1, :read => false)
119
+ def mark_thread_as_read(thread_id, options = {})
120
+ request :patch, "notifications/threads/#{thread_id}", options
121
+
122
+ last_response.status == 205
123
+ end
124
+
125
+ # Get thread subscription
126
+ #
127
+ # @param thread_id [Integer] Id of the thread.
128
+ # @return [Sawyer::Resource] Subscription.
129
+ # @see https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
130
+ # @example
131
+ # @client.thread_subscription(1)
132
+ def thread_subscription(thread_id, options = {})
133
+ get "notifications/threads/#{thread_id}/subscription", options
134
+ end
135
+
136
+ # Update thread subscription
137
+ #
138
+ # This lets you subscribe to a thread, or ignore it. Subscribing to a
139
+ # thread is unnecessary if the user is already subscribed to the
140
+ # repository. Ignoring a thread will mute all future notifications (until
141
+ # you comment or get @mentioned).
142
+ #
143
+ # @param thread_id [Integer] Id of the thread.
144
+ # @param options
145
+ # @option options [Boolean] :subscribed Determines if notifications
146
+ # should be received from this repository.
147
+ # @option options [Boolean] :ignored Deterimines if all notifications
148
+ # should be blocked from this repository.
149
+ # @return [Sawyer::Resource] Updated subscription.
150
+ # @see https://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
151
+ # @example Subscribe to notifications
152
+ # @client.update_thread_subscription(1, :subscribed => true)
153
+ # @example Ignore notifications from a repo
154
+ # @client.update_thread_subscription(1, :ignored => true)
155
+ def update_thread_subscription(thread_id, options = {})
156
+ put "notifications/threads/#{thread_id}/subscription", options
157
+ end
158
+
159
+ # Delete a thread subscription
160
+ #
161
+ # @param thread_id [Integer] Id of the thread.
162
+ # @return [Boolean] True if delete successful, false otherwise.
163
+ # @see https://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
164
+ # @example
165
+ # @client.delete_thread_subscription(1)
166
+ def delete_thread_subscription(thread_id, options = {})
167
+ boolean_from_response :delete, "notifications/threads/#{thread_id}/subscription", options
168
+ end
169
+ end
170
+ end
171
+ end