wase_endpoint 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/README.rdoc +16 -3
- data/VERSION +1 -1
- data/example/my_endpoint.rb +10 -1
- data/lib/wase_endpoint.rb +2 -2
- data/lib/wase_endpoint/message.rb +16 -1
- data/lib/wase_endpoint/twitterer.rb +3 -0
- data/spec/wase_endpoint_message_spec.rb +38 -8
- data/spec/wase_endpoint_twitterer_spec.rb +12 -2
- data/wase_endpoint.gemspec +57 -0
- metadata +3 -2
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
*.log
|
1
|
+
*.log
|
2
|
+
pkg/
|
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ WaseEndpoint is a library for building daemons that act as WASE Endpoints for th
|
|
6
6
|
|
7
7
|
WaseEndpoint is hosted by http://gemcutter.com. Please make sure you have added them to your gem sources.
|
8
8
|
|
9
|
-
$ sudo gem install
|
9
|
+
$ sudo gem install wase_endpoint
|
10
10
|
|
11
11
|
== Usage
|
12
12
|
|
@@ -21,9 +21,18 @@ Your endpoint logic:
|
|
21
21
|
|
22
22
|
class MyEndpoint < WaseEndpoint
|
23
23
|
|
24
|
-
#
|
24
|
+
# This where our logic goes.
|
25
|
+
# A json encoded String is the only argument. You can deal with this however
|
26
|
+
# you want. The JSON library is already loaded should you wish to use it.
|
27
|
+
# Return another String, or a Hash containing the String and the program
|
28
|
+
# counter increment you wish to use.
|
25
29
|
def secret_sauce(raw_json)
|
30
|
+
|
31
|
+
# Just pass it back. Program counter increment will be 1.
|
26
32
|
raw_json
|
33
|
+
|
34
|
+
# Or pass it back with a custom program counter.
|
35
|
+
# { :data => raw_json, :increment => 2}
|
27
36
|
end
|
28
37
|
|
29
38
|
end
|
@@ -39,11 +48,15 @@ The init file:
|
|
39
48
|
:logfile => 'my_endpoint.log',
|
40
49
|
:sleep_period => 60 )
|
41
50
|
|
51
|
+
Now running the init file will start your daemon. The PID will be returned to allow you to monitor it or kill it later.
|
52
|
+
|
53
|
+
ruby init.rb
|
54
|
+
|
42
55
|
That's it! I also included a basic sinatra server in 'server.rb' that can be used as an input/output/program-listing node.
|
43
56
|
|
44
57
|
== Problems, Comments, Suggestions?
|
45
58
|
|
46
|
-
Issues can be tracked on github:
|
59
|
+
Issues can be tracked on github: http://github.com/dougal/wase_endpoint/issues
|
47
60
|
|
48
61
|
All of the above are most welcome. mailto:dougal.s@gmail.com
|
49
62
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/example/my_endpoint.rb
CHANGED
@@ -3,9 +3,18 @@ require 'wase_endpoint'
|
|
3
3
|
|
4
4
|
class MyEndpoint < WaseEndpoint
|
5
5
|
|
6
|
-
#
|
6
|
+
# This where our logic goes.
|
7
|
+
# A json encoded String is the only argument. You can deal with this however
|
8
|
+
# you want. The JSON library is already loaded should you wish to use it.
|
9
|
+
# Return another String, or a Hash containing the String and the program
|
10
|
+
# counter increment you wish to use.
|
7
11
|
def secret_sauce(raw_json)
|
12
|
+
|
13
|
+
# Just pass it back. Program counter increment will be 1.
|
8
14
|
raw_json
|
15
|
+
|
16
|
+
# Or pass it back with a custom program counter.
|
17
|
+
# { :data => raw_json, :increment => 2}
|
9
18
|
end
|
10
19
|
|
11
20
|
end
|
data/lib/wase_endpoint.rb
CHANGED
@@ -42,14 +42,14 @@ class WaseEndpoint
|
|
42
42
|
messages.each do |message|
|
43
43
|
program_listing = message.fetch_program_listing
|
44
44
|
if message.program_counter >= program_listing.size
|
45
|
-
|
45
|
+
raise IndexError, 'Program counter has gone too far'
|
46
46
|
end
|
47
47
|
|
48
48
|
# Here's where your magic happens.
|
49
49
|
message.send_input(secret_sauce(message.fetch_output))
|
50
50
|
|
51
51
|
# Tell the next endpoint.
|
52
|
-
@twitterer.send(program_listing[message.
|
52
|
+
@twitterer.send(program_listing[message.new_program_counter], message.new_program_counter, message.program_listing_uri, message.output_uri)
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -14,6 +14,7 @@ class WaseEndpoint
|
|
14
14
|
@output_uri = output_uri.strip
|
15
15
|
@input_uri = input_uri.strip if input_uri
|
16
16
|
@input_uri_1 = input_uri_1.strip if input_uri_1
|
17
|
+
@increment = 1
|
17
18
|
end
|
18
19
|
|
19
20
|
def ==(other)
|
@@ -28,7 +29,17 @@ class WaseEndpoint
|
|
28
29
|
RestClient.get('http://' + @output_uri)
|
29
30
|
end
|
30
31
|
|
32
|
+
# Accepts either a String of raw data, or a Hash of data and a program
|
33
|
+
# counter increment.
|
34
|
+
# An Exception will be thrown if this increment is negative.
|
31
35
|
def send_input(input)
|
36
|
+
|
37
|
+
if input.is_a?(Hash)
|
38
|
+
@increment = input[:increment]
|
39
|
+
raise ArgumentError, 'You cannot have negative program counter increments' if @increment < 0
|
40
|
+
input = input[:data]
|
41
|
+
end
|
42
|
+
|
32
43
|
input_uri = 'http://' + (@input_uri || @output_uri)
|
33
44
|
|
34
45
|
# RestClient can't follow a redirect for put, so we'll expand it.
|
@@ -38,6 +49,10 @@ class WaseEndpoint
|
|
38
49
|
RestClient.put(expanded_input_uri, input)
|
39
50
|
end
|
40
51
|
|
52
|
+
def new_program_counter
|
53
|
+
@program_counter + @increment
|
54
|
+
end
|
55
|
+
|
41
56
|
end
|
42
57
|
|
43
|
-
end
|
58
|
+
end
|
@@ -5,6 +5,9 @@ class WaseEndpoint
|
|
5
5
|
twitter_http_auth = Twitter::HTTPAuth.new(username, password)
|
6
6
|
@twitter_client = Twitter::Base.new(twitter_http_auth)
|
7
7
|
|
8
|
+
# Call the test api method to validate the authentication.
|
9
|
+
@twitter_client.help
|
10
|
+
|
8
11
|
# The oldest message ID could be stored here, but since twitter IDs
|
9
12
|
# aren't always time-linear, comparing the messages is safer.
|
10
13
|
@all_messages = []
|
@@ -50,15 +50,45 @@ describe WaseEndpoint::Message do
|
|
50
50
|
@message.fetch_output.should == '[58, 92, 12, 18, 76]'
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
describe "sending input data" do
|
54
|
+
|
55
|
+
it "should send the input data using the expanded output URI" do
|
56
|
+
mock_net_http = mock(Net::HTTP)
|
57
|
+
mock_net_http.should_receive(:head).with('/2uhGcl').and_return({'Location' => 'http://example.com/'})
|
58
|
+
Net::HTTP.should_receive(:new).with('bit.ly').and_return(mock_net_http)
|
59
|
+
RestClient.should_receive(:put).with('http://example.com/', '[1, 2, 3, 4]')
|
60
|
+
|
61
|
+
@message.send_input('[1, 2, 3, 4]')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should throw an error on negative program counter increment" do
|
65
|
+
Net::HTTP.stub(:new).and_return(mock(Net::HTTP, :head => 'http://example.com'))
|
66
|
+
RestClient.stub(:put)
|
67
|
+
|
68
|
+
lambda {
|
69
|
+
@message.send_input({:data => 'foo', :increment => -1})
|
70
|
+
}.should raise_error(ArgumentError, 'You cannot have negative program counter increments')
|
71
|
+
end
|
58
72
|
|
59
|
-
@message.send_input('[1, 2, 3, 4]')
|
60
73
|
end
|
61
|
-
|
74
|
+
|
75
|
+
|
76
|
+
describe "incrementing the program counter" do
|
77
|
+
|
78
|
+
it "should be one" do
|
79
|
+
@message.new_program_counter.should == 1
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should should be two" do
|
83
|
+
Net::HTTP.stub(:new).and_return(mock(Net::HTTP, :head => 'http://example.com'))
|
84
|
+
RestClient.stub(:put)
|
85
|
+
@message.send_input({:data => 'foo', :increment => 2})
|
86
|
+
|
87
|
+
@message.new_program_counter.should == 2
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
62
92
|
end
|
63
93
|
|
64
94
|
describe "with one input URI" do
|
@@ -76,7 +106,7 @@ describe WaseEndpoint::Message do
|
|
76
106
|
@message.input_uri_1.should be_nil
|
77
107
|
end
|
78
108
|
|
79
|
-
it "should send the input data using the expanded
|
109
|
+
it "should send the input data using the expanded input URI" do
|
80
110
|
mock_net_http = mock(Net::HTTP)
|
81
111
|
mock_net_http.should_receive(:head).with('/3kl0xs').and_return({'Location' => 'http://example.com/'})
|
82
112
|
Net::HTTP.should_receive(:new).with('bit.ly').and_return(mock_net_http)
|
@@ -12,6 +12,16 @@ describe WaseEndpoint::Twitterer do
|
|
12
12
|
WaseEndpoint::Twitterer.new(username, password)
|
13
13
|
end
|
14
14
|
|
15
|
+
it "should validate the authentication with the help method" do
|
16
|
+
username ='foo'
|
17
|
+
password = 'bar'
|
18
|
+
Twitter::HTTPAuth.stub(:new)
|
19
|
+
Twitter::Base.stub(:new).and_return(mock_twitter_base)
|
20
|
+
mock_twitter_base.should_receive(:help)
|
21
|
+
|
22
|
+
@twitterer = WaseEndpoint::Twitterer.new(username, password)
|
23
|
+
end
|
24
|
+
|
15
25
|
describe "fetching messages" do
|
16
26
|
|
17
27
|
before(:all) do
|
@@ -72,8 +82,8 @@ describe WaseEndpoint::Twitterer do
|
|
72
82
|
@auth_mock ||= mock(Twitter::HTTPAuth)
|
73
83
|
end
|
74
84
|
|
75
|
-
def mock_twitter_base
|
76
|
-
@base_mock ||= mock(Twitter::Base)
|
85
|
+
def mock_twitter_base(stubs = {:help => true})
|
86
|
+
@base_mock ||= mock(Twitter::Base, stubs)
|
77
87
|
end
|
78
88
|
|
79
89
|
def mock_mash(message_id)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{wase_endpoint}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Douglas F Shearer"]
|
12
|
+
s.date = %q{2009-11-06}
|
13
|
+
s.description = %q{WaseEndpoint is a library for building daemons that act as WASE Endpoints for http://bit.ly/3qRMbv}
|
14
|
+
s.email = %q{dougal.s@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"example/init.rb",
|
24
|
+
"example/my_endpoint.rb",
|
25
|
+
"example/server.rb",
|
26
|
+
"lib/wase_endpoint.rb",
|
27
|
+
"lib/wase_endpoint/message.rb",
|
28
|
+
"lib/wase_endpoint/twitterer.rb",
|
29
|
+
"spec/spec_helper.rb",
|
30
|
+
"spec/wase_endpoint_message_spec.rb",
|
31
|
+
"spec/wase_endpoint_spec.rb",
|
32
|
+
"spec/wase_endpoint_twitterer_spec.rb",
|
33
|
+
"wase_endpoint.gemspec"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/dougal/wase_endpoint}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{WaseEndpoint is a library for building daemons that act as WASE Endpoints for http://bit.ly/3qRMbv}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/wase_endpoint_message_spec.rb",
|
43
|
+
"spec/wase_endpoint_spec.rb",
|
44
|
+
"spec/wase_endpoint_twitterer_spec.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
else
|
53
|
+
end
|
54
|
+
else
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wase_endpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas F Shearer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-06 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- spec/wase_endpoint_message_spec.rb
|
37
37
|
- spec/wase_endpoint_spec.rb
|
38
38
|
- spec/wase_endpoint_twitterer_spec.rb
|
39
|
+
- wase_endpoint.gemspec
|
39
40
|
has_rdoc: true
|
40
41
|
homepage: http://github.com/dougal/wase_endpoint
|
41
42
|
licenses: []
|