github_api 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/github_api/core_ext/hash.rb +4 -0
- data/lib/github_api/repos.rb +5 -3
- data/lib/github_api/repos/pub_sub_hubbub.rb +93 -3
- data/lib/github_api/version.rb +2 -2
- data/spec/github/core_ext/hash_spec.rb +10 -0
- data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
- data/spec/spec_helper.rb +8 -8
- metadata +4 -3
data/README.rdoc
CHANGED
data/lib/github_api/repos.rb
CHANGED
@@ -12,7 +12,8 @@ module Github
|
|
12
12
|
:Forks => 'forks',
|
13
13
|
:Hooks => 'hooks',
|
14
14
|
:Keys => 'keys',
|
15
|
-
:Watching => 'watching'
|
15
|
+
:Watching => 'watching',
|
16
|
+
:PubSubHubbub => 'pub_sub_hubbub'
|
16
17
|
|
17
18
|
include Github::Repos::Collaborators
|
18
19
|
include Github::Repos::Commits
|
@@ -21,6 +22,7 @@ module Github
|
|
21
22
|
include Github::Repos::Hooks
|
22
23
|
include Github::Repos::Keys
|
23
24
|
include Github::Repos::Watching
|
25
|
+
include Github::Repos::PubSubHubbub
|
24
26
|
|
25
27
|
DEFAULT_REPO_OPTIONS = {
|
26
28
|
"homepage" => "https://github.com",
|
@@ -28,7 +30,7 @@ module Github
|
|
28
30
|
"has_issues" => true,
|
29
31
|
"has_wiki" => true,
|
30
32
|
"has_downloads" => true
|
31
|
-
}
|
33
|
+
}.freeze
|
32
34
|
|
33
35
|
VALID_REPO_OPTIONS = %w[
|
34
36
|
name
|
@@ -40,7 +42,7 @@ module Github
|
|
40
42
|
has_downloads
|
41
43
|
].freeze
|
42
44
|
|
43
|
-
VALID_REPO_TYPES = %w[ all public private member ]
|
45
|
+
VALID_REPO_TYPES = %w[ all public private member ].freeze
|
44
46
|
|
45
47
|
# Creates new Repositories API
|
46
48
|
def initialize(options = {})
|
@@ -3,10 +3,100 @@
|
|
3
3
|
module Github
|
4
4
|
class Repos
|
5
5
|
module PubSubHubbub
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
|
7
|
+
# Subscribe to existing topic through pubsubhubbub
|
8
|
+
#
|
9
|
+
# = Parameters
|
10
|
+
# * topic - Required string - The URI of the GitHub repository to subscribe to. The path must be in the format of /:user/:repo/events/:event.
|
11
|
+
# * callback - Required string - The URI to receive the updates to the topic.
|
12
|
+
#
|
13
|
+
# = Examples
|
14
|
+
# @github = Github.new :oauth_token => '...'
|
15
|
+
# @github.subscribe 'https://github.com/:user/:repo/events/push',
|
16
|
+
# 'github://Email?address=peter-murach@gmail.com',
|
17
|
+
# :verify => 'sync',
|
18
|
+
# :secret => '...'
|
19
|
+
#
|
20
|
+
def subscribe(topic, callback, params={})
|
21
|
+
_validate_presence_of topic, callback
|
22
|
+
_normalize_params_keys(params)
|
23
|
+
_merge_action!("subscribe", topic, callback, params)
|
24
|
+
|
25
|
+
post("/hub", params)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Unsubscribe from existing topic though pubsubhubbub
|
29
|
+
#
|
30
|
+
#
|
31
|
+
def unsubscribe(topic, callback, params={})
|
32
|
+
_validate_presence_of topic, callback
|
33
|
+
_normalize_params_keys(params)
|
34
|
+
_merge_action!("unsubscribe", topic, callback, params)
|
35
|
+
|
36
|
+
post("/hub", params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Subscribe repository to service hook through pubsubhubbub
|
40
|
+
#
|
41
|
+
# = Parameters
|
42
|
+
# * repo-name - Required string,
|
43
|
+
# * service-name - Required string
|
44
|
+
# * <tt>:event</tt> - Required hash key for the type of event. The default event is <tt>push</tt>
|
45
|
+
#
|
46
|
+
# = Examples
|
47
|
+
# @github = Github.new :oauth_token => '...'
|
48
|
+
# @github.repos.subscribe_service 'user-name', 'repo-name', 'campfire',
|
49
|
+
# :subdomain => 'github',
|
50
|
+
# :room => 'Commits',
|
51
|
+
# :token => 'abc123',
|
52
|
+
# :event => 'watch'
|
53
|
+
#
|
54
|
+
def subscribe_service(user_name, repo_name, service_name, params={})
|
55
|
+
_validate_presence_of user_name, repo_name, service_name
|
56
|
+
_normalize_params_keys(params)
|
57
|
+
event = params.delete('event') || 'push'
|
58
|
+
topic = "https://github.com/#{user_name}/#{repo_name}/events/#{event}"
|
59
|
+
callback = "github://#{service_name}?#{params.serialize}"
|
60
|
+
|
61
|
+
subscribe(topic, callback)
|
9
62
|
end
|
63
|
+
alias :subscribe_repository :subscribe_service
|
64
|
+
|
65
|
+
# Subscribe repository to service hook through pubsubhubbub
|
66
|
+
#
|
67
|
+
# = Parameters
|
68
|
+
# * repo-name - Required string,
|
69
|
+
# * service-name - Required string
|
70
|
+
# * <tt>:event</tt> - Optional hash key for the type of event. The default event is <tt>push</tt>
|
71
|
+
#
|
72
|
+
# = Examples
|
73
|
+
# @github = Github.new :oauth_token => '...'
|
74
|
+
# @github.repos.unsubscribe_service 'user-name', 'repo-name', 'campfire'
|
75
|
+
#
|
76
|
+
def unsubscribe_service(user_name, repo_name, service_name, params={})
|
77
|
+
_validate_presence_of user_name, repo_name, service_name
|
78
|
+
_normalize_params_keys(params)
|
79
|
+
event = params.delete('event') || 'push'
|
80
|
+
topic = "https://github.com/#{user_name}/#{repo_name}/events/#{event}"
|
81
|
+
callback = "github://#{service_name}"
|
82
|
+
|
83
|
+
unsubscribe(topic, callback)
|
84
|
+
end
|
85
|
+
alias :unsubscribe_repository :unsubscribe_service
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def _merge_action!(action, topic, callback, params) # :nodoc:
|
90
|
+
options = {
|
91
|
+
"hub.mode" => action.to_s,
|
92
|
+
"hub.topic" => topic.to_s,
|
93
|
+
"hub.callback" => callback,
|
94
|
+
"hub.verify" => params.delete('verify') || 'sync',
|
95
|
+
"hub.secret" => params.delete('secret') || ''
|
96
|
+
}
|
97
|
+
params.merge! options
|
98
|
+
end
|
99
|
+
|
10
100
|
end # PubSubHubbub
|
11
101
|
end # Repos
|
12
102
|
end # Github
|
data/lib/github_api/version.rb
CHANGED
@@ -4,6 +4,8 @@ describe Hash do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
Github.new
|
7
|
+
@hash = { :a => 1, :b => 2, :c => 'e'}
|
8
|
+
@serialized = "a=1&b=2&c=e"
|
7
9
|
@nested_hash = { 'a' => { 'b' => {'c' => 1 } } }
|
8
10
|
@symbols = { :a => { :b => { :c => 1 } } }
|
9
11
|
end
|
@@ -24,6 +26,10 @@ describe Hash do
|
|
24
26
|
@nested_hash.should respond_to :symbolize_keys
|
25
27
|
end
|
26
28
|
|
29
|
+
it "should respond to serialize" do
|
30
|
+
@nested_hash.should respond_to :serialize
|
31
|
+
end
|
32
|
+
|
27
33
|
it "should remove key from the hash" do
|
28
34
|
@nested_hash.except('a').should be_empty
|
29
35
|
end
|
@@ -31,4 +37,8 @@ describe Hash do
|
|
31
37
|
it "should convert nested keys to symbols" do
|
32
38
|
@nested_hash.symbolize_keys!.should == @symbols
|
33
39
|
end
|
40
|
+
|
41
|
+
it "should serialize hash" do
|
42
|
+
@hash.serialize.should == @serialized
|
43
|
+
end
|
34
44
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Github::Repos::PubSubHubbub do
|
4
|
+
|
5
|
+
let(:github) { Github.new }
|
6
|
+
let(:topic) { "https://github.com/peter-murach/github/events/push"}
|
7
|
+
let(:callback) { "github://campfire?subdomain=github&room=Commits&token=abc123" }
|
8
|
+
let(:hub_inputs) {
|
9
|
+
{
|
10
|
+
"hub.mode" => 'subscribe',
|
11
|
+
"hub.topic" => topic,
|
12
|
+
"hub.callback" => callback,
|
13
|
+
"hub.verify" => 'sync',
|
14
|
+
"hub.secret" => ''
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
describe "subscribe" do
|
19
|
+
context "success" do
|
20
|
+
before do
|
21
|
+
github.oauth_token = OAUTH_TOKEN
|
22
|
+
stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).
|
23
|
+
to_return(:body => '', :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
github.oauth_token = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should subscribe to hub" do
|
31
|
+
github.repos.subscribe topic, callback
|
32
|
+
a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "failure" do
|
37
|
+
before do
|
38
|
+
github.oauth_token = OAUTH_TOKEN
|
39
|
+
stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).
|
40
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should fail to subscribe to hub" do
|
44
|
+
expect {
|
45
|
+
github.repos.subscribe topic, callback
|
46
|
+
}.to raise_error(Github::ResourceNotFound)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "unsubscribe" do
|
52
|
+
context "success" do
|
53
|
+
before do
|
54
|
+
github.oauth_token = OAUTH_TOKEN
|
55
|
+
stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs.merge("hub.mode" => 'unsubscribe')).
|
56
|
+
to_return(:body => '', :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
57
|
+
end
|
58
|
+
|
59
|
+
after do
|
60
|
+
github.oauth_token = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should subscribe to hub" do
|
64
|
+
github.repos.unsubscribe topic, callback
|
65
|
+
a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "failure" do
|
70
|
+
before do
|
71
|
+
github.oauth_token = OAUTH_TOKEN
|
72
|
+
stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs.merge("hub.mode" => 'unsubscribe')).
|
73
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should fail to subscribe to hub" do
|
77
|
+
expect {
|
78
|
+
github.repos.unsubscribe topic, callback
|
79
|
+
}.to raise_error(Github::ResourceNotFound)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end # Github::Repos::PubSubHubbub
|
data/spec/spec_helper.rb
CHANGED
@@ -15,35 +15,35 @@ RSpec.configure do |config|
|
|
15
15
|
config.include WebMock::API
|
16
16
|
end
|
17
17
|
|
18
|
-
def stub_get(path, endpoint = Github.endpoint)
|
18
|
+
def stub_get(path, endpoint = Github.endpoint.to_s)
|
19
19
|
stub_request(:get, endpoint + path)
|
20
20
|
end
|
21
21
|
|
22
|
-
def stub_post(path, endpoint = Github.endpoint)
|
22
|
+
def stub_post(path, endpoint = Github.endpoint.to_s)
|
23
23
|
stub_request(:post, endpoint + path)
|
24
24
|
end
|
25
25
|
|
26
|
-
def stub_patch(path, endpoint = Github.endpoint)
|
26
|
+
def stub_patch(path, endpoint = Github.endpoint.to_s)
|
27
27
|
stub_request(:patch, endpoint + path)
|
28
28
|
end
|
29
29
|
|
30
|
-
def stub_put(path, endpoint = Github.endpoint)
|
30
|
+
def stub_put(path, endpoint = Github.endpoint.to_s)
|
31
31
|
stub_request(:put, endpoint + path)
|
32
32
|
end
|
33
33
|
|
34
|
-
def stub_delete(path, endpoint = Github.endpoint)
|
34
|
+
def stub_delete(path, endpoint = Github.endpoint.to_s)
|
35
35
|
stub_request(:delete, endpoint + path)
|
36
36
|
end
|
37
37
|
|
38
|
-
def a_get(path, endpoint = Github.endpoint)
|
38
|
+
def a_get(path, endpoint = Github.endpoint.to_s)
|
39
39
|
a_request(:get, endpoint + path)
|
40
40
|
end
|
41
41
|
|
42
|
-
def a_post(path, endpoint = Github.endpoint)
|
42
|
+
def a_post(path, endpoint = Github.endpoint.to_s)
|
43
43
|
a_request(:post, endpoint + path)
|
44
44
|
end
|
45
45
|
|
46
|
-
def a_patch(path, endpoint = Github.endpoint)
|
46
|
+
def a_patch(path, endpoint = Github.endpoint.to_s)
|
47
47
|
a_request(:patch, endpoint + path)
|
48
48
|
end
|
49
49
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Piotr Murach
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-10-
|
17
|
+
date: 2011-10-23 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -285,6 +285,7 @@ files:
|
|
285
285
|
- spec/github/repos/forks_spec.rb
|
286
286
|
- spec/github/repos/hooks_spec.rb
|
287
287
|
- spec/github/repos/keys_spec.rb
|
288
|
+
- spec/github/repos/pub_sub_hubbub_spec.rb
|
288
289
|
- spec/github/repos/watching_spec.rb
|
289
290
|
- spec/github/repos_spec.rb
|
290
291
|
- spec/github_spec.rb
|