Skip to content

Commit bcc94a2

Browse files
committed
Change activity watching api to use new parser. Add create, delete and subscribed? calls. Update docs.
1 parent 6b52650 commit bcc94a2

6 files changed

Lines changed: 143 additions & 34 deletions

File tree

features/activity/watching.feature

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Feature: Watching API
2424
And the response type should be JSON
2525
And the response should not be empty
2626

27-
Scenario: Watching
27+
Scenario: Watching?
2828

2929
Given I want to watching? resource with the following params:
3030
| user | repo |
@@ -48,3 +48,27 @@ Feature: Watching API
4848
When I make request within a cassette named "activity/watching/unwatch"
4949
Then the response status should be 204
5050

51+
Scenario: Subscribed?
52+
53+
Given I want to subscribed? resource with the following params:
54+
| user | repo |
55+
| murek | github_api_test |
56+
When I make request within a cassette named "activity/watching/subscribed"
57+
Then the response should be true
58+
59+
Scenario: Create
60+
61+
Given I want to create resource with the following params:
62+
| user | repo |
63+
| peter-murach | finite_machine |
64+
When I make request within a cassette named "activity/watching/create"
65+
Then the response status should be 200
66+
67+
Scenario: Delete
68+
69+
Given I want to delete resource with the following params:
70+
| user | repo |
71+
| peter-murach | finite_machine |
72+
When I make request within a cassette named "activity/watching/delete"
73+
Then the response status should be 204
74+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions":[{"request":{"method":"put","uri":"https://<BASIC_AUTH>@api.github.com/repos/peter-murach/finite_machine/subscription?access_token=<TOKEN>","body":{"encoding":"UTF-8","base64_string":"e30=\n"},"headers":{"Accept":["application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"],"Accept-Charset":["utf-8"],"User-Agent":["Github Ruby Gem 0.11.3"],"Content-Type":["application/x-www-form-urlencoded"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Sun, 27 Jul 2014 15:00:37 GMT"],"Content-Type":["application/json; charset=utf-8"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4997"],"X-Ratelimit-Reset":["1406476712"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Etag":["\"90c4af909e3f5c0f6e1b087784252a49\""],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"X-Github-Media-Type":["github.v3; format=json"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Content-Length":["239"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"X-Github-Request-Id":["4D649864:7DF6:56403C2:53D51414"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains"],"X-Content-Type-Options":["nosniff"],"X-Served-By":["d818ddef80f4c7d10683dd483558952a"]},"body":{"encoding":"US-ASCII","base64_string":"eyJzdWJzY3JpYmVkIjp0cnVlLCJpZ25vcmVkIjpmYWxzZSwicmVhc29uIjpu\ndWxsLCJjcmVhdGVkX2F0IjoiMjAxNC0wNy0yN1QxNTowMDozN1oiLCJ1cmwi\nOiJodHRwczovL2FwaS5naXRodWIuY29tL3JlcG9zL3BldGVyLW11cmFjaC9m\naW5pdGVfbWFjaGluZS9zdWJzY3JpcHRpb24iLCJyZXBvc2l0b3J5X3VybCI6\nImh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vcmVwb3MvcGV0ZXItbXVyYWNoL2Zp\nbml0ZV9tYWNoaW5lIn0=\n"},"http_version":null},"recorded_at":"Sun, 27 Jul 2014 15:00:37 GMT"}],"recorded_with":"VCR 2.6.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions":[{"request":{"method":"delete","uri":"https://<BASIC_AUTH>@api.github.com/repos/peter-murach/finite_machine/subscription?access_token=<TOKEN>","body":{"encoding":"UTF-8","base64_string":"e30=\n"},"headers":{"Accept":["application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"],"Accept-Charset":["utf-8"],"User-Agent":["Github Ruby Gem 0.11.3"],"Content-Type":["application/x-www-form-urlencoded"]}},"response":{"status":{"code":204,"message":"No Content"},"headers":{"Server":["GitHub.com"],"Date":["Sun, 27 Jul 2014 16:57:09 GMT"],"Status":["204 No Content"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4999"],"X-Ratelimit-Reset":["1406483829"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"X-Github-Request-Id":["4D649864:7B30:58A6A2D:53D52F65"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains"],"X-Content-Type-Options":["nosniff"],"Vary":["Accept-Encoding"],"X-Served-By":["c436b2b44345c72ff906059f604991e7"]},"body":{"encoding":"US-ASCII","base64_string":""},"http_version":null},"recorded_at":"Sun, 27 Jul 2014 16:57:08 GMT"}],"recorded_with":"VCR 2.6.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions":[{"request":{"method":"get","uri":"https://<BASIC_AUTH>@api.github.com/repos/<USER>/github_api_test/subscription?access_token=<TOKEN>","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1"],"Accept-Charset":["utf-8"],"User-Agent":["Github Ruby Gem 0.11.3"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Sun, 27 Jul 2014 14:10:26 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4997"],"X-Ratelimit-Reset":["1406472869"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Etag":["\"441c7bde2694814f2d19fe8202829c0c\""],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"X-Github-Media-Type":["github.v3; format=json"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"X-Github-Request-Id":["4D649864:334B:7146E82:53D50852"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains"],"X-Content-Type-Options":["nosniff"],"X-Served-By":["a1d8c69b807c8e21f06cad9da377d1b0"]},"body":{"encoding":"US-ASCII","base64_string":"eyJzdWJzY3JpYmVkIjp0cnVlLCJpZ25vcmVkIjpmYWxzZSwicmVhc29uIjpu\ndWxsLCJjcmVhdGVkX2F0IjoiMjAwOC0wNC0xMFQwMDowMDowMFoiLCJ1cmwi\nOiJodHRwczovL2FwaS5naXRodWIuY29tL3JlcG9zLzxVU0VSPi9naXRodWJf\nYXBpX3Rlc3Qvc3Vic2NyaXB0aW9uIiwicmVwb3NpdG9yeV91cmwiOiJodHRw\nczovL2FwaS5naXRodWIuY29tL3JlcG9zLzxVU0VSPi9naXRodWJfYXBpX3Rl\nc3QifQ==\n"},"http_version":null},"recorded_at":"Sun, 27 Jul 2014 14:10:26 GMT"}],"recorded_with":"VCR 2.6.0"}

lib/github_api/client/activity/watching.rb

Lines changed: 114 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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
92174
end # Github

spec/github/client/activity/watching/watching_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe Github::Client::Activity::Watching, '#list' do
5+
describe Github::Client::Activity::Watching, '#watching?' do
66
let(:user) { 'peter-murach' }
77
let(:repo) { 'github' }
88
let(:request_path) { "/user/subscriptions/#{user}/#{repo}" }

0 commit comments

Comments
 (0)