thumblemonks-evoke_client 0.1.3 → 0.2.0
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/evoke_client.gemspec +5 -3
- data/lib/evoke_client.rb +9 -18
- data/lib/evoke_client/base.rb +23 -0
- data/lib/evoke_client/stub.rb +7 -0
- data/shoulda_macros/rest_client.rb +0 -1
- data/test/evoke_client_test.rb +23 -8
- metadata +5 -3
data/evoke_client.gemspec
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "evoke_client"
|
|
3
|
-
s.version = "0.
|
|
4
|
-
s.date = "2009-06-
|
|
3
|
+
s.version = "0.2.0"
|
|
4
|
+
s.date = "2009-06-07"
|
|
5
5
|
s.summary = "Rest client interface for talking REST to the evoke service"
|
|
6
6
|
s.email = %w[gus@gusg.us]
|
|
7
7
|
s.homepage = "http://github.com/thumblemonks/evoke_client"
|
|
8
8
|
s.description = "Rest client interface for talking REST to the evoke service"
|
|
9
9
|
s.authors = %w[Justin\ Knowlden]
|
|
10
|
-
s.post_install_message = %q{Choosy
|
|
10
|
+
s.post_install_message = %q{Choosy wizards choose Thumble Monks.}
|
|
11
11
|
|
|
12
12
|
s.has_rdoc = false
|
|
13
13
|
s.rdoc_options = ["--main", "README.markdown"]
|
|
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
|
|
|
22
22
|
Rakefile
|
|
23
23
|
evoke_client.gemspec
|
|
24
24
|
lib/evoke_client.rb
|
|
25
|
+
lib/evoke_client/base.rb
|
|
26
|
+
lib/evoke_client/stub.rb
|
|
25
27
|
lib/query_string.rb
|
|
26
28
|
shoulda_macros/rest_client.rb
|
|
27
29
|
]
|
data/lib/evoke_client.rb
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
require 'restclient'
|
|
2
1
|
require 'query_string'
|
|
2
|
+
require 'evoke_client/base'
|
|
3
|
+
require 'evoke_client/stub'
|
|
3
4
|
|
|
4
5
|
class Evoke
|
|
5
6
|
class ConnectionRefused < Exception; end
|
|
6
7
|
|
|
7
8
|
# Configuration
|
|
8
9
|
|
|
10
|
+
def self.test?; @test == true; end
|
|
11
|
+
def self.test=(setting) @test = setting; end
|
|
12
|
+
|
|
9
13
|
def self.host; @host || 'evoke.thumblemonks.com'; end
|
|
10
14
|
def self.host=(host) @host = host; end
|
|
11
15
|
|
|
@@ -19,24 +23,11 @@ class Evoke
|
|
|
19
23
|
# Logic
|
|
20
24
|
|
|
21
25
|
def self.create_or_update!(*args)
|
|
22
|
-
|
|
26
|
+
prepare(*args).save
|
|
23
27
|
end
|
|
24
|
-
|
|
25
|
-
attr_reader :params, :headers
|
|
26
28
|
|
|
27
|
-
def
|
|
28
|
-
|
|
29
|
-
@params = params
|
|
30
|
-
@params[:callback_at] = @params[:callback_at].utc if @params[:callback_at]
|
|
31
|
-
@params[:data] = @params[:data].to_query_string if @params[:data]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def save
|
|
35
|
-
@evoke[params[:guid]].get
|
|
36
|
-
@evoke[params[:guid]].put(@params)
|
|
37
|
-
rescue RestClient::ResourceNotFound
|
|
38
|
-
@evoke.post(@params)
|
|
39
|
-
rescue Errno::ECONNREFUSED
|
|
40
|
-
raise ConnectionRefused, "Connection refused while connecting to #{Evoke.host_and_port}"
|
|
29
|
+
def self.prepare(*args)
|
|
30
|
+
(test? ? EvokeClient::Stub : EvokeClient::Base).new(*args)
|
|
41
31
|
end
|
|
32
|
+
|
|
42
33
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'restclient'
|
|
2
|
+
|
|
3
|
+
module EvokeClient
|
|
4
|
+
class Base
|
|
5
|
+
attr_reader :params, :headers
|
|
6
|
+
|
|
7
|
+
def initialize(params={})
|
|
8
|
+
@evoke = ::RestClient::Resource.new("http://#{Evoke.host_and_port}/callbacks")
|
|
9
|
+
@params = params
|
|
10
|
+
@params[:callback_at] = @params[:callback_at].utc if @params[:callback_at]
|
|
11
|
+
@params[:data] = @params[:data].to_query_string if @params[:data]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def save
|
|
15
|
+
@evoke[params[:guid]].get
|
|
16
|
+
@evoke[params[:guid]].put(@params)
|
|
17
|
+
rescue ::RestClient::ResourceNotFound
|
|
18
|
+
@evoke.post(@params)
|
|
19
|
+
rescue Errno::ECONNREFUSED
|
|
20
|
+
raise Evoke::ConnectionRefused, "Connection refused while connecting to #{Evoke.host_and_port}"
|
|
21
|
+
end
|
|
22
|
+
end # Base
|
|
23
|
+
end # EvokeClient
|
data/test/evoke_client_test.rb
CHANGED
|
@@ -5,11 +5,15 @@ class EvokeTest < Test::Unit::TestCase
|
|
|
5
5
|
@params = {:url => 'foo', :callback_at => Time.now}
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
def teardown
|
|
9
|
+
Evoke.test = false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "preparing an evokation" do
|
|
9
13
|
setup do
|
|
10
14
|
@data = {:foo => 'bar', 'goo' => 'car'}
|
|
11
15
|
@expected_data = "foo=bar&goo=car"
|
|
12
|
-
@evoke = Evoke.
|
|
16
|
+
@evoke = Evoke.prepare(@params.merge(:data => @data))
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
before_should("convert times to UTC") { Time.any_instance.expects(:utc) }
|
|
@@ -25,7 +29,7 @@ class EvokeTest < Test::Unit::TestCase
|
|
|
25
29
|
setup do
|
|
26
30
|
expect_restful_request_failure(:get, ::RestClient::ResourceNotFound)
|
|
27
31
|
expect_restful_request(:post, @params)
|
|
28
|
-
@evoke = Evoke.
|
|
32
|
+
@evoke = Evoke.prepare(@params)
|
|
29
33
|
end
|
|
30
34
|
should("try and post params after not finding a resource") { @evoke.save }
|
|
31
35
|
end
|
|
@@ -34,7 +38,7 @@ class EvokeTest < Test::Unit::TestCase
|
|
|
34
38
|
setup do
|
|
35
39
|
expect_restful_request(:get)
|
|
36
40
|
expect_restful_request(:put, @params)
|
|
37
|
-
@evoke = Evoke.
|
|
41
|
+
@evoke = Evoke.prepare(@params)
|
|
38
42
|
end
|
|
39
43
|
should("try and put params after finding a resource") { @evoke.save }
|
|
40
44
|
end
|
|
@@ -42,8 +46,8 @@ class EvokeTest < Test::Unit::TestCase
|
|
|
42
46
|
|
|
43
47
|
context "create_or_update!" do
|
|
44
48
|
should "initialize instance and call save" do
|
|
45
|
-
fake_evoke =
|
|
46
|
-
|
|
49
|
+
fake_evoke = EvokeClient::Base.new
|
|
50
|
+
EvokeClient::Base.expects(:new).with(@params).returns(fake_evoke)
|
|
47
51
|
fake_evoke.expects(:save)
|
|
48
52
|
Evoke.create_or_update!(@params)
|
|
49
53
|
end
|
|
@@ -51,11 +55,11 @@ class EvokeTest < Test::Unit::TestCase
|
|
|
51
55
|
|
|
52
56
|
context "connection refused" do
|
|
53
57
|
setup do
|
|
54
|
-
|
|
58
|
+
expect_restful_request_failure(:get, Errno::ECONNREFUSED)
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
should "reraise Evoke::ConnectionRefused when saving" do
|
|
58
|
-
assert_raise(Evoke::ConnectionRefused) { Evoke.
|
|
62
|
+
assert_raise(Evoke::ConnectionRefused) { Evoke.prepare({}).save }
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
should "reraise Evoke::ConnectionRefused when storing" do
|
|
@@ -86,4 +90,15 @@ class EvokeTest < Test::Unit::TestCase
|
|
|
86
90
|
end
|
|
87
91
|
end
|
|
88
92
|
|
|
93
|
+
context "when test mode is on" do
|
|
94
|
+
setup do
|
|
95
|
+
Evoke.test = true
|
|
96
|
+
@evoke = Evoke.prepare({})
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
should "expect an EvokeClient::Stub class" do
|
|
100
|
+
assert_kind_of EvokeClient::Stub, @evoke
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
89
104
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thumblemonks-evoke_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Knowlden
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-06-
|
|
12
|
+
date: 2009-06-07 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -37,11 +37,13 @@ files:
|
|
|
37
37
|
- Rakefile
|
|
38
38
|
- evoke_client.gemspec
|
|
39
39
|
- lib/evoke_client.rb
|
|
40
|
+
- lib/evoke_client/base.rb
|
|
41
|
+
- lib/evoke_client/stub.rb
|
|
40
42
|
- lib/query_string.rb
|
|
41
43
|
- shoulda_macros/rest_client.rb
|
|
42
44
|
has_rdoc: false
|
|
43
45
|
homepage: http://github.com/thumblemonks/evoke_client
|
|
44
|
-
post_install_message: Choosy
|
|
46
|
+
post_install_message: Choosy wizards choose Thumble Monks.
|
|
45
47
|
rdoc_options:
|
|
46
48
|
- --main
|
|
47
49
|
- README.markdown
|