evoke_client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +11 -3
- data/Rakefile +8 -9
- data/evoke_client.gemspec +15 -13
- data/lib/evoke_client.rb +5 -30
- data/lib/evoke_client/base.rb +55 -18
- data/lib/evoke_client/mock.rb +76 -0
- data/test/configuration_test.rb +13 -0
- data/test/create_or_update_test.rb +33 -0
- data/test/create_test.rb +48 -0
- data/test/destroy_test.rb +32 -0
- data/test/find_test.rb +31 -0
- data/test/teststrap.rb +3 -0
- data/test/update_test.rb +49 -0
- metadata +15 -12
- data/lib/evoke_client/stub.rb +0 -7
- data/lib/query_string.rb +0 -16
- data/shoulda_macros/rest_client.rb +0 -16
- data/test/evoke_client_test.rb +0 -104
- data/test/test_helper.rb +0 -11
data/README.markdown
CHANGED
@@ -4,8 +4,16 @@ evoke-client is a simple rest-client utility for allowing your application to co
|
|
4
4
|
|
5
5
|
### Usage
|
6
6
|
|
7
|
-
evoke = Evoke.new(:url => 'http://example.com/users/unsubscribe', :callback_at => (Time.now + 86400))
|
8
|
-
evoke.save
|
7
|
+
# evoke = Evoke.new(:url => 'http://example.com/users/unsubscribe', :callback_at => (Time.now + 86400))
|
8
|
+
# evoke.save
|
9
|
+
|
10
|
+
Evoke.configure(...)
|
11
|
+
callback = Evoke::Callback.new(:url => 'http://example.com/users/unsubscribe', :callback_at => (Time.now + 86400))
|
12
|
+
callback.save
|
13
|
+
|
14
|
+
callback = Evoke::Callback.find(guid)
|
15
|
+
callback.destroy
|
16
|
+
callback.update
|
9
17
|
|
10
18
|
# What happens if save fails
|
11
19
|
|
@@ -27,7 +35,7 @@ To modify host and port, just set the following:
|
|
27
35
|
|
28
36
|
These should be automatically installed when you install evoke_client
|
29
37
|
|
30
|
-
* [
|
38
|
+
* [httparty](http://github.com/jnunemaker/httparty/)
|
31
39
|
|
32
40
|
## License
|
33
41
|
|
data/Rakefile
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
3
|
|
5
4
|
desc 'Default task: run all tests'
|
6
5
|
task :default => [:test]
|
7
6
|
|
8
|
-
task(:set_test_env) { ENV['APP_ENV'] ||= 'test' }
|
9
|
-
|
10
|
-
task(:environment) { }
|
11
|
-
|
12
|
-
task :test => [:set_test_env]
|
13
7
|
desc 'Run all tests'
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
task :test do
|
9
|
+
$:.concat ['./lib', './test']
|
10
|
+
Dir.glob("./test/*_test.rb").each { |test| require test }
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Open an irb session preloaded with this library"
|
14
|
+
task :console do
|
15
|
+
exec "irb -rubygems -I./lib -r evoke_client"
|
17
16
|
end
|
data/evoke_client.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "evoke_client"
|
3
|
-
s.version = "0.2.
|
4
|
-
s.date = "2009-
|
5
|
-
s.summary = "
|
3
|
+
s.version = "0.2.1"
|
4
|
+
s.date = "2009-10-07"
|
5
|
+
s.summary = "Tool for interfacing with the Evoke web service"
|
6
6
|
s.email = %w[gus@gusg.us]
|
7
7
|
s.homepage = "http://github.com/thumblemonks/evoke_client"
|
8
|
-
s.description = "
|
8
|
+
s.description = "Tool for interfacing with the Evoke web service. See http://github.com/thumblemonks/evoke"
|
9
9
|
s.authors = %w[Justin\ Knowlden]
|
10
10
|
s.post_install_message = %q{Choosy wizards choose Thumble Monks.}
|
11
11
|
|
@@ -13,23 +13,25 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.rdoc_options = ["--main", "README.markdown"]
|
14
14
|
s.extra_rdoc_files = ["README.markdown"]
|
15
15
|
|
16
|
-
s.add_dependency("
|
16
|
+
s.add_dependency("httparty", [">= 0.4.4"])
|
17
17
|
|
18
|
-
# run git ls-files to get an updated list
|
19
18
|
s.files = %w[
|
20
19
|
MIT-LICENSE
|
21
20
|
README.markdown
|
22
|
-
Rakefile
|
23
21
|
evoke_client.gemspec
|
24
22
|
lib/evoke_client.rb
|
25
23
|
lib/evoke_client/base.rb
|
26
|
-
lib/evoke_client/
|
27
|
-
lib/query_string.rb
|
28
|
-
shoulda_macros/rest_client.rb
|
24
|
+
lib/evoke_client/mock.rb
|
29
25
|
]
|
30
|
-
|
26
|
+
|
31
27
|
s.test_files = %w[
|
32
|
-
|
33
|
-
test/
|
28
|
+
Rakefile
|
29
|
+
test/configuration_test.rb
|
30
|
+
test/create_or_update_test.rb
|
31
|
+
test/create_test.rb
|
32
|
+
test/destroy_test.rb
|
33
|
+
test/find_test.rb
|
34
|
+
test/teststrap.rb
|
35
|
+
test/update_test.rb
|
34
36
|
]
|
35
37
|
end
|
data/lib/evoke_client.rb
CHANGED
@@ -1,33 +1,8 @@
|
|
1
|
-
require 'query_string'
|
2
1
|
require 'evoke_client/base'
|
3
|
-
require '
|
2
|
+
require 'httparty'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def self.test?; @test == true; end
|
11
|
-
def self.test=(setting) @test = setting; end
|
12
|
-
|
13
|
-
def self.host; @host || 'evoke.thumblemonks.com'; end
|
14
|
-
def self.host=(host) @host = host; end
|
15
|
-
|
16
|
-
def self.port; @port; end
|
17
|
-
def self.port=(port) @port = port; end
|
18
|
-
|
19
|
-
def self.host_and_port
|
20
|
-
[host, port].compact.join(':')
|
21
|
-
end
|
22
|
-
|
23
|
-
# Logic
|
24
|
-
|
25
|
-
def self.create_or_update!(*args)
|
26
|
-
prepare(*args).save
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.prepare(*args)
|
30
|
-
(test? ? EvokeClient::Stub : EvokeClient::Base).new(*args)
|
31
|
-
end
|
32
|
-
|
4
|
+
Evoke::Callback.instance_eval do
|
5
|
+
include HTTParty
|
6
|
+
base_uri "http://localhost:3000"
|
7
|
+
format :json
|
33
8
|
end
|
data/lib/evoke_client/base.rb
CHANGED
@@ -1,23 +1,60 @@
|
|
1
|
-
|
1
|
+
module Evoke
|
2
|
+
class RecordError < Exception; end
|
3
|
+
class RecordInvalid < RecordError; end
|
4
|
+
class RecordNotFound < RecordError; end
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
+
def self.configure(base_uri)
|
7
|
+
Evoke::Callback.base_uri(base_uri)
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
class Callback
|
11
|
+
def self.find(guid)
|
12
|
+
callback = get("/callbacks/#{guid}")
|
13
|
+
callback.empty? ? nil : new(callback.merge(:new_record => false))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create_or_update(data)
|
17
|
+
callback = (find(data["guid"]) || new(data)).update_attributes(data)
|
18
|
+
callback.save
|
19
|
+
callback
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(data)
|
23
|
+
@new_record = determine_if_new_record(data.delete(:new_record))
|
24
|
+
@data = data
|
25
|
+
end
|
26
|
+
|
27
|
+
def new_record?; @new_record; end
|
28
|
+
|
29
|
+
def update_attributes(new_data)
|
30
|
+
@data = @data.merge(new_data)
|
31
|
+
self
|
12
32
|
end
|
13
33
|
|
14
34
|
def save
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
|
35
|
+
args = (new_record? ? [:post, "/callbacks"] : [:put, "/callbacks/#{guid}"]) + [{:query => @data}]
|
36
|
+
handle_response(self.class.send(*args)) { |response| @data = response }
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
handle_response(self.class.delete("/callbacks/#{guid}")) { |response| nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_missing(method, *args, &block)
|
44
|
+
@data.include?(method.to_s) ? @data[method.to_s] : super
|
45
|
+
end
|
46
|
+
private
|
47
|
+
def handle_response(response, &block)
|
48
|
+
case response.code
|
49
|
+
when 404 then raise(Evoke::RecordNotFound)
|
50
|
+
when 422 then raise(Evoke::RecordInvalid, response["errors"])
|
51
|
+
when 200..201 then yield(response)
|
52
|
+
else raise(Evoke::RecordError, "#{response.code} - #{response.message}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def determine_if_new_record(condition)
|
57
|
+
condition.nil? || condition
|
58
|
+
end
|
59
|
+
end # Callback
|
60
|
+
end # Evoke
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'evoke_client/base'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module Evoke
|
5
|
+
module HTTMockParty
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def base_uri(uri=nil)
|
12
|
+
@base_uri = uri if uri
|
13
|
+
@base_uri
|
14
|
+
end
|
15
|
+
|
16
|
+
def format(fmt=nil)
|
17
|
+
@format = fmt if fmt
|
18
|
+
@format
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The mock part. Your code will call these methods and get a real HTTParty::Response
|
23
|
+
|
24
|
+
def get(path, query={}) HTTMockParty.router("get").dispatch(path, query); end
|
25
|
+
def post(path, query={}) HTTMockParty.router("post").dispatch(path, query); end
|
26
|
+
def put(path, query={}) HTTMockParty.router("put").dispatch(path, query); end
|
27
|
+
def delete(path, query={}) HTTMockParty.router("delete").dispatch(path, query); end
|
28
|
+
end # ClassMethods
|
29
|
+
|
30
|
+
#
|
31
|
+
# The shunt part. Setting up routers for responses
|
32
|
+
|
33
|
+
def self.get(path, query={}) router("get").maps(path, query); end
|
34
|
+
def self.post(path, query={}) router("post").maps(path, query); end
|
35
|
+
def self.put(path, query={}) router("put").maps(path, query); end
|
36
|
+
def self.delete(path, query={}) router("delete").maps(path, query); end
|
37
|
+
|
38
|
+
class Router
|
39
|
+
def initialize; @routes = {}; end
|
40
|
+
def maps(*args) @routes[args.inspect] = Responder.new; end
|
41
|
+
def dispatch(*args) @routes[args.inspect].process; end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Responder
|
45
|
+
def process
|
46
|
+
HTTParty::Response.new(@delegate || "", @body, @code, @message, @headers)
|
47
|
+
end
|
48
|
+
|
49
|
+
def ok; status(200, "Ok"); end
|
50
|
+
def created; status(201, "Created"); end
|
51
|
+
def not_found; status(404, "Not Found"); end
|
52
|
+
def unprocessable_entity; status(422, "Unprocessable Entity"); end
|
53
|
+
def internal_server_error; status(500, "Internal Server Error"); end
|
54
|
+
|
55
|
+
def responds(delegate, body="", code=nil, message=nil, headers={})
|
56
|
+
@delegate, @body, @code, @message, @headers = delegate, body, code, message, headers
|
57
|
+
self
|
58
|
+
end
|
59
|
+
private
|
60
|
+
def status(code, message)
|
61
|
+
@code, @message = code, message
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def self.routers; @routers ||= {}; end
|
68
|
+
def self.router(method) routers[method] ||= Router.new; end
|
69
|
+
end # HTTMockParty
|
70
|
+
end # Evoke
|
71
|
+
|
72
|
+
Evoke::Callback.instance_eval do
|
73
|
+
include Evoke::HTTMockParty
|
74
|
+
base_uri "http://test:3000"
|
75
|
+
format :json
|
76
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "configuring evoke client" do
|
4
|
+
context "with defaults" do
|
5
|
+
asserts("base_uri") { Evoke::Callback.base_uri }.equals("http://test:3000")
|
6
|
+
asserts("format") { Evoke::Callback.format }.equals(:json)
|
7
|
+
end # with defaults
|
8
|
+
|
9
|
+
context "with custom base_uri" do
|
10
|
+
setup { Evoke.configure("http://yo.ma.ma:3000/") }
|
11
|
+
asserts("base_uri") { Evoke::Callback.base_uri }.equals("http://yo.ma.ma:3000/")
|
12
|
+
end
|
13
|
+
end # configuring evoke client
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "create or update" do
|
4
|
+
|
5
|
+
context "when callback does not exist" do
|
6
|
+
setup do
|
7
|
+
Evoke::HTTMockParty.get('/callbacks/poster').not_found
|
8
|
+
Evoke::HTTMockParty.post('/callbacks', :query => {"guid" => "poster"}).
|
9
|
+
responds({"url" => "http://poster"}).created
|
10
|
+
Evoke::Callback.create_or_update({"guid" => "poster"})
|
11
|
+
end
|
12
|
+
|
13
|
+
should "post to callbacks and update itself accordingly" do
|
14
|
+
topic.url
|
15
|
+
end.equals("http://poster")
|
16
|
+
end # when callback does not exist
|
17
|
+
|
18
|
+
context "when callback does exist" do
|
19
|
+
setup do
|
20
|
+
Evoke::HTTMockParty.get('/callbacks/putter').
|
21
|
+
responds({"url" => "http://putter", "guid" => "putter"}).ok
|
22
|
+
Evoke::HTTMockParty.put('/callbacks/putter',
|
23
|
+
:query => {"guid" => "putter", "url" => "http://putter.back"}).
|
24
|
+
responds({"url" => "http://putter.new"}).ok
|
25
|
+
Evoke::Callback.create_or_update({"guid" => "putter", "url" => "http://putter.back"})
|
26
|
+
end
|
27
|
+
|
28
|
+
should "put to callbacks and update itself accordingly" do
|
29
|
+
topic.url
|
30
|
+
end.equals("http://putter.new")
|
31
|
+
end # when callback does exist
|
32
|
+
|
33
|
+
end # create or update
|
data/test/create_test.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "creating a callback" do
|
4
|
+
|
5
|
+
context "with valid data" do
|
6
|
+
setup do
|
7
|
+
good_response = {"url" => "http://foo.bar"}
|
8
|
+
Evoke::HTTMockParty.post('/callbacks', :query => {"url" => "http://good"}).
|
9
|
+
responds(good_response).created
|
10
|
+
callback = Evoke::Callback.new("url" => "http://good")
|
11
|
+
callback.save
|
12
|
+
callback
|
13
|
+
end
|
14
|
+
|
15
|
+
asserts("url is populated from returned values") do
|
16
|
+
topic.url
|
17
|
+
end.equals("http://foo.bar")
|
18
|
+
|
19
|
+
end # with valid data
|
20
|
+
|
21
|
+
context "with invalid data" do
|
22
|
+
|
23
|
+
setup do
|
24
|
+
bad_response = {"errors" => ["blah"]}
|
25
|
+
Evoke::HTTMockParty.post('/callbacks', :query => {"url" => "http://bad"}).
|
26
|
+
responds(bad_response).unprocessable_entity
|
27
|
+
Evoke::Callback.new("url" => "http://bad")
|
28
|
+
end
|
29
|
+
|
30
|
+
should "raise error and include save errors in exception message" do
|
31
|
+
topic.save
|
32
|
+
end.raises(Evoke::RecordInvalid, ["blah"])
|
33
|
+
|
34
|
+
end # with valid data
|
35
|
+
|
36
|
+
context "with some unknown error code" do
|
37
|
+
|
38
|
+
setup do
|
39
|
+
Evoke::HTTMockParty.post('/callbacks', :query => {"url" => "http://unknown"}).internal_server_error
|
40
|
+
Evoke::Callback.new("url" => "http://unknown")
|
41
|
+
end
|
42
|
+
|
43
|
+
should "raise and error with 500 response code message" do
|
44
|
+
topic.save
|
45
|
+
end.raises(Evoke::RecordError, "500 - Internal Server Error")
|
46
|
+
|
47
|
+
end # with valid data
|
48
|
+
end # creating a callback
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "destroying a callback" do
|
4
|
+
context "that actually exists" do
|
5
|
+
setup do
|
6
|
+
Evoke::HTTMockParty.delete('/callbacks/good').ok
|
7
|
+
Evoke::Callback.new("guid" => "good")
|
8
|
+
end
|
9
|
+
|
10
|
+
asserts("nil is returned from destroy") { topic.destroy }.nil
|
11
|
+
end # that actually exists
|
12
|
+
|
13
|
+
context "that causes some failure" do
|
14
|
+
setup do
|
15
|
+
Evoke::HTTMockParty.delete('/callbacks/bad').responds({"errors" => ["sucka"]}).unprocessable_entity
|
16
|
+
Evoke::Callback.new("guid" => "bad")
|
17
|
+
end
|
18
|
+
|
19
|
+
asserts "error is raised with errors in exception message" do
|
20
|
+
topic.destroy
|
21
|
+
end.raises(Evoke::RecordInvalid, ["sucka"])
|
22
|
+
end # that causes some failure
|
23
|
+
|
24
|
+
context "that does not exist" do
|
25
|
+
setup do
|
26
|
+
Evoke::HTTMockParty.delete('/callbacks/what').not_found
|
27
|
+
Evoke::Callback.new("guid" => "what")
|
28
|
+
end
|
29
|
+
|
30
|
+
should("raise an error") { topic.destroy }.raises(Evoke::RecordNotFound)
|
31
|
+
end # that does not exist
|
32
|
+
end # destroying a callback
|
data/test/find_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "finding a callback" do
|
4
|
+
context "that exists" do
|
5
|
+
setup do
|
6
|
+
good_data = {"url" => "http://foo.bar", "http_method" => "get"}
|
7
|
+
Evoke::HTTMockParty.get('/callbacks/a1b2c3').responds(good_data).ok
|
8
|
+
Evoke::Callback.find('a1b2c3')
|
9
|
+
end
|
10
|
+
|
11
|
+
should("return a Callback object") { topic }.kind_of(Evoke::Callback)
|
12
|
+
should("not be a new record") { !topic.new_record? }
|
13
|
+
|
14
|
+
asserts("url attribute is accessible as method") do
|
15
|
+
topic.url
|
16
|
+
end.equals("http://foo.bar")
|
17
|
+
|
18
|
+
asserts("http_method attribute is accessible as method") do
|
19
|
+
topic.http_method
|
20
|
+
end.equals("get")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "that does not exist" do
|
24
|
+
setup do
|
25
|
+
Evoke::HTTMockParty.get('/callbacks/blah').not_found
|
26
|
+
Evoke::Callback.find('blah')
|
27
|
+
end
|
28
|
+
|
29
|
+
asserts("result") { topic }.nil
|
30
|
+
end
|
31
|
+
end # finding a callback
|
data/test/teststrap.rb
ADDED
data/test/update_test.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "updating attributes of a callback" do
|
4
|
+
setup do
|
5
|
+
callback = Evoke::Callback.new("guid" => "meme", "url" => "http://foo.bar", "http_method" => "get")
|
6
|
+
callback.update_attributes("guid" => "mom", "url" => "http://a.b")
|
7
|
+
callback
|
8
|
+
end
|
9
|
+
|
10
|
+
asserts("guid updated") { topic.guid }.equals("mom")
|
11
|
+
asserts("url updated") { topic.url }.equals("http://a.b")
|
12
|
+
asserts("http_method is unchanged") { topic.http_method }.equals("get")
|
13
|
+
end # updating attributes of a callback
|
14
|
+
|
15
|
+
context "updating a callback" do
|
16
|
+
|
17
|
+
context "that actually exists" do
|
18
|
+
setup do
|
19
|
+
Evoke::HTTMockParty.put('/callbacks/good', :query => {"guid" => "good", "url" => "http://a.b"}).
|
20
|
+
responds({"url" => "http://foo.bar"}).ok
|
21
|
+
callback = Evoke::Callback.new("guid" => "good", "url" => "http://a.b", :new_record => false)
|
22
|
+
callback.save
|
23
|
+
callback
|
24
|
+
end
|
25
|
+
|
26
|
+
asserts("url is updated from results") { topic.url }.equals("http://foo.bar")
|
27
|
+
end # that actually exists
|
28
|
+
|
29
|
+
context "that causes some failure" do
|
30
|
+
setup do
|
31
|
+
Evoke::HTTMockParty.put('/callbacks/bad', :query => {"guid" => "bad"}).
|
32
|
+
responds({"errors" => ["mutha"]}).unprocessable_entity
|
33
|
+
Evoke::Callback.new("guid" => "bad", :new_record => false)
|
34
|
+
end
|
35
|
+
|
36
|
+
should("raise an error") { topic.save }.raises(Evoke::RecordInvalid)
|
37
|
+
should("include errors in exception message") { topic.save }.raises(Evoke::RecordInvalid, "mutha")
|
38
|
+
end # that causes some failure
|
39
|
+
|
40
|
+
context "that does not exist" do
|
41
|
+
setup do
|
42
|
+
Evoke::HTTMockParty.put('/callbacks/what', :query => {"guid" => "what"}).not_found
|
43
|
+
Evoke::Callback.new("guid" => "what", :new_record => false)
|
44
|
+
end
|
45
|
+
|
46
|
+
should("raise an error") { topic.save }.raises(Evoke::RecordNotFound)
|
47
|
+
end # that does not exist
|
48
|
+
|
49
|
+
end # updating a callback
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evoke_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Knowlden
|
@@ -9,20 +9,20 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: httparty
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.4.4
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description: Tool for interfacing with the Evoke web service. See http://github.com/thumblemonks/evoke
|
26
26
|
email:
|
27
27
|
- gus@gusg.us
|
28
28
|
executables: []
|
@@ -34,13 +34,10 @@ extra_rdoc_files:
|
|
34
34
|
files:
|
35
35
|
- MIT-LICENSE
|
36
36
|
- README.markdown
|
37
|
-
- Rakefile
|
38
37
|
- evoke_client.gemspec
|
39
38
|
- lib/evoke_client.rb
|
40
39
|
- lib/evoke_client/base.rb
|
41
|
-
- lib/evoke_client/
|
42
|
-
- lib/query_string.rb
|
43
|
-
- shoulda_macros/rest_client.rb
|
40
|
+
- lib/evoke_client/mock.rb
|
44
41
|
has_rdoc: true
|
45
42
|
homepage: http://github.com/thumblemonks/evoke_client
|
46
43
|
licenses: []
|
@@ -69,7 +66,13 @@ rubyforge_project:
|
|
69
66
|
rubygems_version: 1.3.5
|
70
67
|
signing_key:
|
71
68
|
specification_version: 3
|
72
|
-
summary:
|
69
|
+
summary: Tool for interfacing with the Evoke web service
|
73
70
|
test_files:
|
74
|
-
-
|
75
|
-
- test/
|
71
|
+
- Rakefile
|
72
|
+
- test/configuration_test.rb
|
73
|
+
- test/create_or_update_test.rb
|
74
|
+
- test/create_test.rb
|
75
|
+
- test/destroy_test.rb
|
76
|
+
- test/find_test.rb
|
77
|
+
- test/teststrap.rb
|
78
|
+
- test/update_test.rb
|
data/lib/evoke_client/stub.rb
DELETED
data/lib/query_string.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module EvokeClient
|
2
|
-
module Hash
|
3
|
-
def to_query_string
|
4
|
-
map do |key, val|
|
5
|
-
"#{key}=#{val}"
|
6
|
-
end.join('&')
|
7
|
-
end
|
8
|
-
end # Hash
|
9
|
-
|
10
|
-
module String
|
11
|
-
alias_method :to_query_string, :to_s
|
12
|
-
end # String
|
13
|
-
end # EvokeClient
|
14
|
-
|
15
|
-
Hash.instance_eval { include EvokeClient::Hash }
|
16
|
-
String.instance_eval { include EvokeClient::String }
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module EvokeClient
|
2
|
-
module RestClient
|
3
|
-
module Shoulda
|
4
|
-
def expect_restful_request(method, *args)
|
5
|
-
::RestClient::Resource.any_instance.expects(method).with(*args)
|
6
|
-
end
|
7
|
-
|
8
|
-
def expect_restful_request_failure(method, *raises)
|
9
|
-
::RestClient::Resource.any_instance.expects(method).raises(*raises)
|
10
|
-
end
|
11
|
-
|
12
|
-
end # Shoulda
|
13
|
-
end # RestClient
|
14
|
-
end # EvokeClient
|
15
|
-
|
16
|
-
Test::Unit::TestCase.instance_eval { include EvokeClient::RestClient::Shoulda }
|
data/test/evoke_client_test.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class EvokeTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@params = {:url => 'foo', :callback_at => Time.now}
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown
|
9
|
-
Evoke.test = false
|
10
|
-
end
|
11
|
-
|
12
|
-
context "preparing an evokation" do
|
13
|
-
setup do
|
14
|
-
@data = {:foo => 'bar', 'goo' => 'car'}
|
15
|
-
@expected_data = "foo=bar&goo=car"
|
16
|
-
@evoke = Evoke.prepare(@params.merge(:data => @data))
|
17
|
-
end
|
18
|
-
|
19
|
-
before_should("convert times to UTC") { Time.any_instance.expects(:utc) }
|
20
|
-
|
21
|
-
should "convert data to a single escaped parameter string" do
|
22
|
-
assert_match /foo=bar&?/, @evoke.params[:data]
|
23
|
-
assert_match /goo=car&?/, @evoke.params[:data]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "saving" do
|
28
|
-
context "a new callback" do
|
29
|
-
setup do
|
30
|
-
expect_restful_request_failure(:get, ::RestClient::ResourceNotFound)
|
31
|
-
expect_restful_request(:post, @params)
|
32
|
-
@evoke = Evoke.prepare(@params)
|
33
|
-
end
|
34
|
-
should("try and post params after not finding a resource") { @evoke.save }
|
35
|
-
end
|
36
|
-
|
37
|
-
context "an existing callback" do
|
38
|
-
setup do
|
39
|
-
expect_restful_request(:get)
|
40
|
-
expect_restful_request(:put, @params)
|
41
|
-
@evoke = Evoke.prepare(@params)
|
42
|
-
end
|
43
|
-
should("try and put params after finding a resource") { @evoke.save }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "create_or_update!" do
|
48
|
-
should "initialize instance and call save" do
|
49
|
-
fake_evoke = EvokeClient::Base.new
|
50
|
-
EvokeClient::Base.expects(:new).with(@params).returns(fake_evoke)
|
51
|
-
fake_evoke.expects(:save)
|
52
|
-
Evoke.create_or_update!(@params)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "connection refused" do
|
57
|
-
setup do
|
58
|
-
expect_restful_request_failure(:get, Errno::ECONNREFUSED)
|
59
|
-
end
|
60
|
-
|
61
|
-
should "reraise Evoke::ConnectionRefused when saving" do
|
62
|
-
assert_raise(Evoke::ConnectionRefused) { Evoke.prepare({}).save }
|
63
|
-
end
|
64
|
-
|
65
|
-
should "reraise Evoke::ConnectionRefused when storing" do
|
66
|
-
assert_raise(Evoke::ConnectionRefused) { Evoke.create_or_update!({}) }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "host and port:" do
|
71
|
-
context "when unchanged" do
|
72
|
-
setup do
|
73
|
-
Evoke.host = nil
|
74
|
-
Evoke.port = nil
|
75
|
-
end
|
76
|
-
should("return default host") { assert_equal 'evoke.thumblemonks.com', Evoke.host }
|
77
|
-
should("return default port") { assert_nil Evoke.port }
|
78
|
-
should("return default host and port") { assert_equal 'evoke.thumblemonks.com', Evoke.host_and_port }
|
79
|
-
end
|
80
|
-
|
81
|
-
context "when changed" do
|
82
|
-
setup do
|
83
|
-
Evoke.host = 'example.com'
|
84
|
-
Evoke.port = 4567
|
85
|
-
end
|
86
|
-
|
87
|
-
should("return specified host") { assert_equal 'example.com', Evoke.host }
|
88
|
-
should("return specified port") { assert_equal 4567, Evoke.port }
|
89
|
-
should("return specified host and port") { assert_equal 'example.com:4567', Evoke.host_and_port }
|
90
|
-
end
|
91
|
-
end
|
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
|
-
|
104
|
-
end
|
data/test/test_helper.rb
DELETED