@@ -4,37 +4,43 @@ module Github
44 # Watching a Repository registers the user to receive notificactions on new
55 # discussions, as well as events in the user’s activity feed.
66 class Client ::Activity ::Watching < API
7-
8- # List repo watchers
7+ # List repository watchers
8+ #
9+ # @see https://developer.github.com/v3/activity/watching/#list-watchers
910 #
10- # = Examples
11- # github = Github.new :user => 'user-name', :repo => 'repo-name'
12- # github.activity.watching.list
13- # github.activity.watching.list { |watcher| ... }
11+ # @example
12+ # github = Github.new
13+ # github.activity.watching.list user: 'user-name', repo: 'repo-name'
14+ # github.activity.watching.list user: 'user-naem', repo: 'repo-name' { |watcher| ... }
1415 #
16+ # @api public
1517 def list ( *args )
16- arguments ( args , : required => [ :user , :repo ] )
18+ arguments ( args , required : [ :user , :repo ] )
1719
18- response = get_request ( "/repos/#{ user } /#{ repo } /subscribers" , arguments . params )
20+ response = get_request ( "/repos/#{ arguments . user } /#{ arguments . repo } /subscribers" , arguments . params )
1921 return response unless block_given?
2022 response . each { |el | yield el }
2123 end
2224 alias :all :list
2325
2426 # List repos being watched by a user
2527 #
26- # = Examples
27- # github = Github.new
28- # github.activity.watching.watched :user => 'user-name'
28+ # @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
29+ #
30+ # @example
31+ # github = Github.new
32+ # github.activity.watching.watched user: 'user-name'
2933 #
3034 # List repos being watched by the authenticated user
3135 #
32- # = Examples
33- # github = Github.new : oauth_token => '...'
34- # github.activity.watching.watched
36+ # @example
37+ # github = Github.new oauth_token: '...'
38+ # github.activity.watching.watched
3539 #
40+ # @api public
3641 def watched ( *args )
37- params = arguments ( args ) . params
42+ arguments ( args )
43+ params = arguments . params
3844
3945 response = if ( user_name = params . delete ( 'user' ) )
4046 get_request ( "/users/#{ user_name } /subscriptions" , params )
@@ -45,17 +51,87 @@ def watched(*args)
4551 response . each { |el | yield el }
4652 end
4753
54+ # Check if you are subscribed to a repository
55+ #
56+ # @see https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
57+ #
58+ # @example
59+ # github = Github.new
60+ # github.activity.watching.subscribed? 'user-name', 'repo-name'
61+ #
62+ # @example
63+ # github.activity.watching.subscribed? user: 'user-name', repo: 'repo-name'
64+ #
65+ # @api public
66+ def subscribed? ( *args )
67+ arguments ( args , required : [ :user , :repo ] )
68+
69+ get_request ( "/repos/#{ arguments . user } /#{ arguments . repo } /subscription" , arguments . params )
70+ true
71+ rescue Github ::Error ::NotFound
72+ false
73+ end
74+
75+ # Create subscription to a repository
76+ #
77+ # @see https://developer.github.com/v3/activity/watching/#set-a-repository-subscription
78+ #
79+ # @param [Hash] params
80+ # @option params [Boolean] :subscribed
81+ # Determines if notifications should be received from this repository.
82+ # @option params [Boolean] :ignored
83+ # Determines if all notifications should be blocked from this repository.
84+ #
85+ # @example
86+ # github = Github.new
87+ # github.activity.watching.create 'user-name', 'repo-name'
88+ #
89+ # @example
90+ # github.activity.watching.create user: 'user-name', repo: 'repo-name'
91+ #
92+ # @api public
93+ def create ( *args )
94+ arguments ( args , required : [ :user , :repo ] )
95+
96+ put_request ( "/repos/#{ arguments . user } /#{ arguments . repo } /subscription" , arguments . params )
97+ end
98+ alias_method :subscribe , :create
99+
100+ # Delete a repository subscription
101+ #
102+ # @see https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
103+ #
104+ # @example
105+ # github = Github.new oauth_token: '...'
106+ # github.activity.watching.delete 'user-name', 'repo-name'
107+ #
108+ # @example
109+ # github.activity.watching.delete user: 'user-name', repo: 'repo-name'
110+ #
111+ # @api public
112+ def delete ( *args )
113+ arguments ( args , required : [ :user , :repo ] )
114+
115+ delete_request ( "/repos/#{ arguments . user } /#{ arguments . repo } /subscription" , arguments . params )
116+ end
117+ alias_method :unsubscribe , :delete
118+
48119 # Check if you are watching a repository
49120 #
50- # Returns <tt>true</tt> if this repo is watched by you, <tt>false</tt> otherwise
51- # = Examples
52- # github = Github.new
53- # github.activity.watching.watching? 'user-name', 'repo-name'
121+ # @see https://developer.github.com/v3/activity/watching/#check-if-you-are-watching-a-repository-legacy
122+ #
123+ # @example
124+ # github = Github.new
125+ # github.activity.watching.watching? 'user-name', 'repo-name'
126+ #
127+ # @return [Boolean]
128+ # Returns true if this repo is watched by you, false otherwise.
54129 #
130+ # @api public
55131 def watching? ( *args )
56- arguments ( args , : required => [ :user , :repo ] )
132+ arguments ( args , required : [ :user , :repo ] )
57133
58- get_request ( "/user/subscriptions/#{ user } /#{ repo } " , arguments . params )
134+ get_request ( "/user/subscriptions/#{ arguments . user } /#{ arguments . repo } " , arguments . params )
59135 true
60136 rescue Github ::Error ::NotFound
61137 false
@@ -65,28 +141,34 @@ def watching?(*args)
65141 #
66142 # You need to be authenticated to watch a repository
67143 #
68- # = Examples
69- # github = Github.new
70- # github.activity.watching.watch 'user-name', 'repo-name'
144+ # @see https://developer.github.com/v3/activity/watching/#watch-a-repository-legacy
71145 #
146+ # @example
147+ # github = Github.new
148+ # github.activity.watching.watch 'user-name', 'repo-name'
149+ #
150+ # @api public
72151 def watch ( *args )
73- arguments ( args , : required => [ :user , :repo ] )
152+ arguments ( args , required : [ :user , :repo ] )
74153
75- put_request ( "/user/subscriptions/#{ user } /#{ repo } " , arguments . params )
154+ put_request ( "/user/subscriptions/#{ arguments . user } /#{ arguments . repo } " , arguments . params )
76155 end
77156
78157 # Stop watching a repository
79158 #
80159 # You need to be authenticated to stop watching a repository.
81- # = Examples
82- # github = Github.new
83- # github.activity.watching.unwatch 'user-name', 'repo-name'
84160 #
161+ # @see https://developer.github.com/v3/activity/watching/#stop-watching-a-repository-legacy
162+ #
163+ # @example
164+ # github = Github.new
165+ # github.activity.watching.unwatch 'user-name', 'repo-name'
166+ #
167+ # @api public
85168 def unwatch ( *args )
86- arguments ( args , : required => [ :user , :repo ] )
169+ arguments ( args , required : [ :user , :repo ] )
87170
88- delete_request ( "/user/subscriptions/#{ user } /#{ repo } " , arguments . params )
171+ delete_request ( "/user/subscriptions/#{ arguments . user } /#{ arguments . repo } " , arguments . params )
89172 end
90-
91173 end # Activity::Watching
92174end # Github
0 commit comments