Skip to content

Commit 78df961

Browse files
committed
Change activity notifications api to use new parser. Update docs.
1 parent 7c1129a commit 78df961

2 files changed

Lines changed: 89 additions & 62 deletions

File tree

lib/github_api/client/activity/notifications.rb

Lines changed: 88 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,38 @@ class Client::Activity::Notifications < API
77
#
88
# List all notifications for the current user, grouped by repository.
99
#
10-
# = Parameters
11-
# * <tt>:all</tt> - Optional boolean - true to show notifications marked as read.
12-
# * <tt>:participating</tt> - Optional boolean - true to show only
13-
# notifications in which the user is directly
14-
# participating or mentioned.
15-
# * <tt>:since</tt> - Optional string - filters out any notifications updated
16-
# before the given time. The time should be passed in as
17-
# UTC in the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
18-
# Example: “2012-10-09T23:39:01Z”.
19-
#
20-
# = Examples
21-
# github = Github.new oauth_token: 'token'
22-
# github.activity.notifications.list
10+
# @see https://developer.github.com/v3/activity/notifications/#list-your-notifications
11+
#
12+
# @param [Hash] params
13+
# @option params [Boolean] :all
14+
# If true, show notifications marked as read.
15+
# Default: false
16+
# @option params [Boolean] :participating
17+
# If true, only shows notifications in which the user
18+
# is directly participating or mentioned. Default: false
19+
# @option params [String] :since
20+
# Filters out any notifications updated before the given time.
21+
# This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
22+
# Default: Time.now
23+
#
24+
# @example
25+
# github = Github.new oauth_token: 'token'
26+
# github.activity.notifications.list
2327
#
2428
# List your notifications in a repository
2529
#
26-
# = Examples
30+
# @see https://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
31+
#
32+
# @example
2733
# github = Github.new
2834
# github.activity.notifications.list user: 'user-name', repo: 'repo-name'
2935
#
36+
# @api public
3037
def list(*args)
31-
params = arguments(args) do
32-
sift %w[ all participating since user repo]
33-
end.params
38+
arguments(args) do
39+
permit %w[ all participating since user repo]
40+
end
41+
params = arguments.params
3442

3543
response = if ( (user_name = params.delete("user")) &&
3644
(repo_name = params.delete("repo")) )
@@ -45,15 +53,18 @@ def list(*args)
4553

4654
# View a single thread
4755
#
48-
# = Examples
56+
# @see https://developer.github.com/v3/activity/notifications/#view-a-single-thread
57+
#
58+
# @example
4959
# github = Github.new oauth_token: 'token'
5060
# github.activity.notifications.get 'thread_id'
5161
# github.activity.notifications.get 'thread_id' { |thread| ... }
5262
#
63+
# @api public
5364
def get(*args)
54-
arguments(args, :required => [:thread_id])
65+
arguments(args, required: [:id])
5566

56-
response = get_request("/notifications/threads/#{thread_id}", arguments.params)
67+
response = get_request("/notifications/threads/#{arguments.id}", arguments.params)
5768
return response unless block_given?
5869
response.each { |el| yield el }
5970
end
@@ -63,41 +74,45 @@ def get(*args)
6374
#
6475
# Marking a notification as “read” removes it from the default view on GitHub.com.
6576
#
66-
# = Parameters
77+
# @see https://developer.github.com/v3/activity/notifications/#mark-as-read
6778
#
68-
# * <tt>:unread</tt> - boolean - Changes the unread status of the threads.
69-
# * <tt>:read</tt> - boolean - Inverse of "unread"
70-
# * <tt>:last_read_at</tt> - optional string time - describes the last point
71-
# that notifications were checked. Anything updated
72-
# since this time will not be updated. Default: Now.
73-
# Expected in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
74-
# Example: “2012-10-09T23:39:01Z”.
79+
# @param [Hash] params
80+
# @option params [String] :last_read_at
81+
# Describes the last point that notifications were checked.
82+
# Anything updated since this time will not be updated.
83+
# This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
84+
# Default: Time.now
7585
#
76-
# = Examples
86+
# @example
7787
# github = Github.new oauth_token: 'token'
78-
# github.activity.notifications.mark read: true
88+
# github.activity.notifications.mark
7989
#
8090
# Mark notifications as read in a repository
8191
#
82-
# = Examples
83-
# github.activity.notifications.mark user: 'user-name', repo: 'repo-name',
84-
# read: true
92+
# @see https://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
93+
#
94+
# @example
95+
# github.activity.notifications.mark user: 'user-name', repo: 'repo-name'
8596
#
8697
# Mark a thread as read
8798
#
88-
# = Examples
89-
# github.activity.notifications.mark thread_id: 'id', read: true
99+
# @see https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
100+
#
101+
# @example
102+
# github.activity.notifications.mark id: 'thread-id'
90103
#
104+
# @api public
91105
def mark(*args)
92-
params = arguments(args) do
93-
sift %w[ unread read last_read_at user repo thread_id]
94-
end.params
106+
arguments(args) do
107+
permit %w[ unread read last_read_at user repo id]
108+
end
109+
params = arguments.params
95110

96111
if ( (user_name = params.delete("user")) &&
97112
(repo_name = params.delete("repo")) )
98113

99114
put_request("/repos/#{user_name}/#{repo_name}/notifications", params)
100-
elsif (thread_id = params.delete("thread_id"))
115+
elsif (thread_id = params.delete("id"))
101116
patch_request("/notifications/threads/#{thread_id}", params)
102117
else
103118
put_request("/notifications", params)
@@ -106,14 +121,20 @@ def mark(*args)
106121

107122
# Check to see if the current user is subscribed to a thread.
108123
#
109-
# = Examples
124+
# @see https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
125+
#
126+
# @example
110127
# github = Github.new oauth_token: 'token'
111128
# github.activity.notifications.subscribed? 'thread-id'
112129
#
130+
# @example
131+
# github.activity.notifications.subscribed? id: 'thread-id'
132+
#
133+
# @api public
113134
def subscribed?(*args)
114-
arguments(args, :required => [:thread_id])
135+
arguments(args, required: [:id])
115136

116-
get_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
137+
get_request("/notifications/threads/#{arguments.id}/subscription", arguments.params)
117138
end
118139

119140
# Create a thread subscription
@@ -123,35 +144,41 @@ def subscribed?(*args)
123144
# a thread will mute all future notifications (until you comment or get
124145
# @mentioned).
125146
#
126-
# = Parameters
127-
# * <tt>:subscribed</tt> - boolean - determines if notifications should be
128-
# received from this thread.
129-
# * <tt>:ignored</tt> - boolean - deterimines if all notifications should be
130-
# blocked from this thread.
131-
# = Examples
132-
# github = Github.new oauth_token: 'token'
133-
# github.activity.notifications.create 'thread-id',
134-
# 'subscribed': true
135-
# 'ignored': false
147+
# @see https://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
148+
#
149+
# @param [Hash] params
150+
# @option params [Boolean] :subscribed
151+
# Determines if notifications should be received from this thread
152+
# @option params [Boolean] :ignored
153+
# Determines if all notifications should be blocked from this thread
154+
#
155+
# @example
156+
# github = Github.new oauth_token: 'token'
157+
# github.activity.notifications.create 'thread-id',
158+
# subscribed: true
159+
# ignored: false
136160
#
161+
# @api public
137162
def create(*args)
138-
arguments(args, :required => [:thread_id])
163+
arguments(args, required: [:id])
139164

140-
put_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
165+
put_request("/notifications/threads/#{arguments.id}/subscription", arguments.params)
141166
end
142167

143168
# Delete a thread subscription
144169
#
145-
# = Examples
146-
# github = Github.new oauth_token: 'token'
147-
# github.activity.notifications.delete 'thread_id'
170+
# @see https://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
171+
#
172+
# @example
173+
# github = Github.new oauth_token: 'token'
174+
# github.activity.notifications.delete 'thread_id'
148175
#
176+
# @api public
149177
def delete(*args)
150-
arguments(args, :required => [:thread_id])
178+
arguments(args, required: [:id])
151179

152-
delete_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
180+
delete_request("/notifications/threads/#{arguments.id}/subscription", arguments.params)
153181
end
154182
alias :remove :delete
155-
156-
end # Activity::Notifications
183+
end # Client::Activity::Notifications
157184
end # Github

spec/github/client/activity/notifications/mark_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
}
6666

6767
it 'should get the resource' do
68-
subject.mark inputs.merge(:thread_id => thread_id)
68+
subject.mark inputs.merge(:id => thread_id)
6969
a_patch(request_path).
7070
with(:body => inputs, :query => {:access_token => OAUTH_TOKEN}).
7171
should have_been_made

0 commit comments

Comments
 (0)