osub 0.0.5 → 0.0.6
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.
- data/lib/osub/subscription.rb +74 -0
- data/lib/osub/version.rb +1 -1
- data/lib/osub.rb +1 -2
- metadata +60 -48
- data/lib/osub/subscriber.rb +0 -93
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
require 'ostatus'
|
5
|
+
require 'hmac-sha1'
|
6
|
+
|
7
|
+
module OSub
|
8
|
+
class Subscription
|
9
|
+
attr_reader :callback_url
|
10
|
+
attr_reader :topic_url
|
11
|
+
|
12
|
+
def initialize(callback_url, topic_url, secret = nil, token = nil)
|
13
|
+
@tokens = []
|
14
|
+
if token != nil
|
15
|
+
@tokens << token
|
16
|
+
end
|
17
|
+
|
18
|
+
secret = "" if secret == nil
|
19
|
+
@secret = secret.to_s
|
20
|
+
|
21
|
+
@callback_url = callback_url
|
22
|
+
@topic_url = topic_url
|
23
|
+
end
|
24
|
+
|
25
|
+
# Actively searches for hubs by talking to publisher directly
|
26
|
+
def hubs
|
27
|
+
OStatus::Feed.from_url(topic_url).hubs
|
28
|
+
end
|
29
|
+
|
30
|
+
# Subscribe to the topic through the given hub.
|
31
|
+
def subscribe(hub_url, async = false, token = nil)
|
32
|
+
if token != nil
|
33
|
+
@tokens << token.to_s
|
34
|
+
end
|
35
|
+
change_subscription(:subscribe, hub_url, async, token)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Unsubscribe to the topic through the given hub.
|
39
|
+
def unsubscribe(hub_url, async = false, token = nil)
|
40
|
+
if token != nil
|
41
|
+
@tokens << token.to_s
|
42
|
+
end
|
43
|
+
change_subscription(:unsubscribe, hub_url, async, token)
|
44
|
+
end
|
45
|
+
|
46
|
+
def change_subscription(mode, hub_url, async, token)
|
47
|
+
res = Net::HTTP.post_form(URI.parse(hub_url),
|
48
|
+
{ 'hub.mode' => mode.to_s,
|
49
|
+
'hub.callback' => @callback_url,
|
50
|
+
'hub.verify' => async ? 'async' : 'sync',
|
51
|
+
'hub.verify_token' => token,
|
52
|
+
'hub.lease_seconds' => '',
|
53
|
+
'hub.secret' => @secret,
|
54
|
+
'hub.topic' => @topic_url})
|
55
|
+
end
|
56
|
+
|
57
|
+
def verify_subscription(token)
|
58
|
+
result = @tokens.index(token) != nil
|
59
|
+
@tokens.delete(token)
|
60
|
+
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
64
|
+
def verify_content(body, signature)
|
65
|
+
hmac = HMAC::SHA1.hexdigest(@secret, body)
|
66
|
+
check = "sha1=" + hmac
|
67
|
+
check == signature
|
68
|
+
end
|
69
|
+
|
70
|
+
def perform_challenge(challenge_code)
|
71
|
+
{:body => challenge_code, :status => 200}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/osub/version.rb
CHANGED
data/lib/osub.rb
CHANGED
metadata
CHANGED
@@ -1,86 +1,98 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: osub
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Hackers of the Severed Hand
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2011-04-03 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: ruby-hmac
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
22
|
prerelease: false
|
24
|
-
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
38
31
|
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ostatus
|
39
35
|
prerelease: false
|
40
|
-
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
37
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
46
|
description: This is a simple implementation of a subscriber in the PubSubHubbub protocol.
|
47
|
-
email:
|
47
|
+
email:
|
48
48
|
- hotsh@xomb.org
|
49
49
|
executables: []
|
50
|
+
|
50
51
|
extensions: []
|
52
|
+
|
51
53
|
extra_rdoc_files: []
|
52
|
-
|
54
|
+
|
55
|
+
files:
|
53
56
|
- .gitignore
|
54
57
|
- Gemfile
|
55
58
|
- LICENSE
|
56
59
|
- Rakefile
|
57
60
|
- lib/osub.rb
|
58
|
-
- lib/osub/subscriber.rb
|
59
61
|
- lib/osub/subscribers.rb
|
62
|
+
- lib/osub/subscription.rb
|
60
63
|
- lib/osub/version.rb
|
61
64
|
- osub.gemspec
|
65
|
+
has_rdoc: true
|
62
66
|
homepage: http://github.com/hotsh/osub
|
63
67
|
licenses: []
|
68
|
+
|
64
69
|
post_install_message:
|
65
70
|
rdoc_options: []
|
66
|
-
|
71
|
+
|
72
|
+
require_paths:
|
67
73
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
75
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
83
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
80
90
|
requirements: []
|
91
|
+
|
81
92
|
rubyforge_project: osub
|
82
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.3.7
|
83
94
|
signing_key:
|
84
95
|
specification_version: 3
|
85
96
|
summary: This is a simple implementation of a subscriber in the PubSubHubbub protocol.
|
86
97
|
test_files: []
|
98
|
+
|
data/lib/osub/subscriber.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
require 'ostatus'
|
5
|
-
require 'hmac-sha1'
|
6
|
-
|
7
|
-
module OSub
|
8
|
-
class Subscription
|
9
|
-
attr_reader :callback_url
|
10
|
-
attr_reader :topic_url
|
11
|
-
|
12
|
-
def initialize(callback_url, topic_url, secret = nil)
|
13
|
-
@tokens = []
|
14
|
-
|
15
|
-
secret = "" if secret == nil
|
16
|
-
@secret = secret.to_s
|
17
|
-
|
18
|
-
@callback_url = callback_url
|
19
|
-
@topic_url = topic_url
|
20
|
-
end
|
21
|
-
|
22
|
-
# Actively searches for hubs by talking to publisher directly
|
23
|
-
def hubs
|
24
|
-
OStatus::Feed.from_url(topic_url).hubs
|
25
|
-
end
|
26
|
-
|
27
|
-
# Subscribe to the topic through the given hub.
|
28
|
-
def subscribe(hub_url, token = nil)
|
29
|
-
if token != nil
|
30
|
-
@tokens << token.to_s
|
31
|
-
end
|
32
|
-
change_subscription(:subscribe, hub_url, token)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Unsubscribe to the topic through the given hub.
|
36
|
-
def unsubscribe(hub_url, token = nil)
|
37
|
-
if token != nil
|
38
|
-
@tokens << token.to_s
|
39
|
-
end
|
40
|
-
change_subscription(:unsubscribe, hub_url, token)
|
41
|
-
end
|
42
|
-
|
43
|
-
def change_subscription(mode, hub_url, token, redirect_limit = 10)
|
44
|
-
hub_uri = URI.parse(hub_url)
|
45
|
-
|
46
|
-
req = Net::HTTP::Post.new(hub_uri.request_uri)
|
47
|
-
req.set_form_data({
|
48
|
-
'hub.mode' => mode.to_s,
|
49
|
-
'hub.callback' => @callback_url,
|
50
|
-
'hub.verify' => async ? 'async' : 'sync',
|
51
|
-
'hub.verify_token' => token,
|
52
|
-
'hub.lease_seconds' => '',
|
53
|
-
'hub.secret' => @secret,
|
54
|
-
'hub.topic' => @topic_url
|
55
|
-
})
|
56
|
-
|
57
|
-
http = Net::HTTP.new(hub_uri.hostname, hub_uri.port)
|
58
|
-
if hub_uri.scheme == 'https'
|
59
|
-
http.use_ssl = true
|
60
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
61
|
-
end
|
62
|
-
|
63
|
-
response = http.request(req)
|
64
|
-
|
65
|
-
if response.is_a?(Net::HTTPRedirection) && redirect_limit > 0
|
66
|
-
location = response['location']
|
67
|
-
self.change_subscription(mode, hub_url, token, redirect_limit - 1)
|
68
|
-
else
|
69
|
-
response
|
70
|
-
end
|
71
|
-
|
72
|
-
rescue OpenSSL::SSL::SSLError
|
73
|
-
return nil
|
74
|
-
end
|
75
|
-
|
76
|
-
def verify_subscription(token)
|
77
|
-
result = @tokens.index(token) != nil
|
78
|
-
@tokens.delete(token)
|
79
|
-
|
80
|
-
result
|
81
|
-
end
|
82
|
-
|
83
|
-
def verify_content(body, signature)
|
84
|
-
hmac = HMAC::SHA1.hexdigest(@secret, body)
|
85
|
-
check = "sha1=" + hmac
|
86
|
-
check == signature
|
87
|
-
end
|
88
|
-
|
89
|
-
def perform_challenge(challenge_code)
|
90
|
-
{:body => challenge_code, :status => 200}
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|