crohr-restfully 0.1.1 → 0.2.1
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/README.rdoc +70 -2
- data/Rakefile +38 -9
- data/TODO.rdoc +3 -0
- data/VERSION +1 -1
- data/bin/restfully +8 -8
- data/examples/grid5000.rb +2 -1
- data/lib/restfully/collection.rb +12 -16
- data/lib/restfully/error.rb +4 -0
- data/lib/restfully/http/adapters/abstract_adapter.rb +30 -0
- data/lib/restfully/http/adapters/patron_adapter.rb +16 -0
- data/lib/restfully/http/adapters/rest_client_adapter.rb +31 -0
- data/lib/restfully/http/error.rb +20 -0
- data/lib/restfully/http/headers.rb +20 -0
- data/lib/restfully/http/request.rb +24 -0
- data/lib/restfully/http/response.rb +19 -0
- data/lib/restfully/http.rb +9 -0
- data/lib/restfully/parsing.rb +7 -7
- data/lib/restfully/resource.rb +15 -18
- data/lib/restfully/session.rb +41 -41
- data/lib/restfully.rb +12 -5
- data/restfully.gemspec +29 -5
- data/spec/collection_spec.rb +73 -17
- data/spec/fixtures/grid5000-sites.json +489 -0
- data/spec/http/error_spec.rb +18 -0
- data/spec/http/headers_spec.rb +17 -0
- data/spec/http/request_spec.rb +45 -0
- data/spec/http/response_spec.rb +15 -0
- data/spec/http/rest_client_adapter_spec.rb +33 -0
- data/spec/parsing_spec.rb +25 -0
- data/spec/resource_spec.rb +109 -60
- data/spec/restfully_spec.rb +9 -1
- data/spec/session_spec.rb +97 -13
- data/spec/spec_helper.rb +3 -1
- metadata +27 -4
data/lib/restfully.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'restfully/error'
|
2
|
+
require 'restfully/parsing'
|
3
|
+
require 'restfully/http'
|
4
|
+
require 'restfully/http/adapters/rest_client_adapter'
|
6
5
|
require 'restfully/extensions'
|
7
6
|
require 'restfully/session'
|
8
7
|
require 'restfully/special_hash'
|
@@ -10,3 +9,11 @@ require 'restfully/special_array'
|
|
10
9
|
require 'restfully/link'
|
11
10
|
require 'restfully/resource'
|
12
11
|
require 'restfully/collection'
|
12
|
+
|
13
|
+
|
14
|
+
module Restfully
|
15
|
+
class << self
|
16
|
+
attr_accessor :adapter
|
17
|
+
end
|
18
|
+
self.adapter = Restfully::HTTP::Adapters::RestClientAdapter
|
19
|
+
end
|
data/restfully.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{restfully}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril Rohr"]
|
12
|
-
s.date = %q{2009-09-
|
12
|
+
s.date = %q{2009-09-17}
|
13
13
|
s.default_executable = %q{restfully}
|
14
14
|
s.description = %q{Experimental code for auto-generation of wrappers on top of RESTful APIs that follow HATEOAS principles and provide OPTIONS methods and/or Allow headers.}
|
15
15
|
s.email = %q{cyril.rohr@gmail.com}
|
@@ -24,12 +24,22 @@ Gem::Specification.new do |s|
|
|
24
24
|
"LICENSE",
|
25
25
|
"README.rdoc",
|
26
26
|
"Rakefile",
|
27
|
+
"TODO.rdoc",
|
27
28
|
"VERSION",
|
28
29
|
"bin/restfully",
|
29
30
|
"examples/grid5000.rb",
|
30
31
|
"lib/restfully.rb",
|
31
32
|
"lib/restfully/collection.rb",
|
33
|
+
"lib/restfully/error.rb",
|
32
34
|
"lib/restfully/extensions.rb",
|
35
|
+
"lib/restfully/http.rb",
|
36
|
+
"lib/restfully/http/adapters/abstract_adapter.rb",
|
37
|
+
"lib/restfully/http/adapters/patron_adapter.rb",
|
38
|
+
"lib/restfully/http/adapters/rest_client_adapter.rb",
|
39
|
+
"lib/restfully/http/error.rb",
|
40
|
+
"lib/restfully/http/headers.rb",
|
41
|
+
"lib/restfully/http/request.rb",
|
42
|
+
"lib/restfully/http/response.rb",
|
33
43
|
"lib/restfully/link.rb",
|
34
44
|
"lib/restfully/parsing.rb",
|
35
45
|
"lib/restfully/resource.rb",
|
@@ -38,7 +48,14 @@ Gem::Specification.new do |s|
|
|
38
48
|
"lib/restfully/special_hash.rb",
|
39
49
|
"restfully.gemspec",
|
40
50
|
"spec/collection_spec.rb",
|
51
|
+
"spec/fixtures/grid5000-sites.json",
|
52
|
+
"spec/http/error_spec.rb",
|
53
|
+
"spec/http/headers_spec.rb",
|
54
|
+
"spec/http/request_spec.rb",
|
55
|
+
"spec/http/response_spec.rb",
|
56
|
+
"spec/http/rest_client_adapter_spec.rb",
|
41
57
|
"spec/link_spec.rb",
|
58
|
+
"spec/parsing_spec.rb",
|
42
59
|
"spec/resource_spec.rb",
|
43
60
|
"spec/restfully_spec.rb",
|
44
61
|
"spec/session_spec.rb",
|
@@ -48,11 +65,18 @@ Gem::Specification.new do |s|
|
|
48
65
|
s.homepage = %q{http://github.com/crohr/restfully}
|
49
66
|
s.rdoc_options = ["--charset=UTF-8"]
|
50
67
|
s.require_paths = ["lib"]
|
68
|
+
s.rubyforge_project = %q{restfully}
|
51
69
|
s.rubygems_version = %q{1.3.2}
|
52
70
|
s.summary = %q{Experimental code for auto-generation of wrappers on top of RESTful APIs that follow some specific conventions.}
|
53
71
|
s.test_files = [
|
54
72
|
"spec/collection_spec.rb",
|
73
|
+
"spec/http/error_spec.rb",
|
74
|
+
"spec/http/headers_spec.rb",
|
75
|
+
"spec/http/request_spec.rb",
|
76
|
+
"spec/http/response_spec.rb",
|
77
|
+
"spec/http/rest_client_adapter_spec.rb",
|
55
78
|
"spec/link_spec.rb",
|
79
|
+
"spec/parsing_spec.rb",
|
56
80
|
"spec/resource_spec.rb",
|
57
81
|
"spec/restfully_spec.rb",
|
58
82
|
"spec/session_spec.rb",
|
@@ -65,11 +89,11 @@ Gem::Specification.new do |s|
|
|
65
89
|
s.specification_version = 3
|
66
90
|
|
67
91
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
68
|
-
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
|
92
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.0"])
|
69
93
|
else
|
70
|
-
s.add_dependency(%q<rest-client>, [">= 0"])
|
94
|
+
s.add_dependency(%q<rest-client>, [">= 1.0"])
|
71
95
|
end
|
72
96
|
else
|
73
|
-
s.add_dependency(%q<rest-client>, [">= 0"])
|
97
|
+
s.add_dependency(%q<rest-client>, [">= 1.0"])
|
74
98
|
end
|
75
99
|
end
|
data/spec/collection_spec.rb
CHANGED
@@ -15,23 +15,79 @@ describe Collection do
|
|
15
15
|
collection.should respond_to(:length)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
|
19
|
+
|
20
|
+
describe "loading" do
|
21
|
+
before(:all) do
|
22
|
+
@raw = fixture("grid5000-sites.json")
|
23
|
+
@response_200 = Restfully::HTTP::Response.new(200, {'Content-Type' => 'application/json;charset=utf-8', 'Content-Length' => @raw.length}, @raw)
|
24
|
+
@logger = Logger.new(STDOUT)
|
25
|
+
end
|
26
|
+
it "should not load if already loaded and no :reload" do
|
27
|
+
collection = Collection.new("uri", mock("session"))
|
28
|
+
collection.should_receive(:loaded?).and_return(true)
|
29
|
+
collection.load(:reload => false).should == collection
|
30
|
+
end
|
31
|
+
it "should load when :reload param is true [already loaded]" do
|
32
|
+
collection = Collection.new("uri", session=mock("session", :logger => Logger.new(STDOUT)))
|
33
|
+
collection.should_receive(:loaded?).and_return(true)
|
34
|
+
session.should_receive(:get).and_return(@response_200)
|
35
|
+
collection.load(:reload => true).should == collection
|
36
|
+
end
|
37
|
+
it "should load when force_reload is true [not loaded]" do
|
38
|
+
collection = Collection.new("uri", session=mock("session", :logger => Logger.new(STDOUT)))
|
39
|
+
collection.should_receive(:loaded?).and_return(false)
|
40
|
+
session.should_receive(:get).and_return(@response_200)
|
41
|
+
collection.load(:reload => true).should == collection
|
42
|
+
end
|
43
|
+
it "should force reload when query parameters are given" do
|
44
|
+
collection = Collection.new("uri", session=mock("session", :logger => Logger.new(STDOUT)))
|
45
|
+
session.should_receive(:get).and_return(@response_200)
|
46
|
+
collection.load(:query => {:q1 => 'v1'}).should == collection
|
47
|
+
end
|
48
|
+
it "should not initialize resources lacking a self link" do
|
49
|
+
collection = Collection.new("uri", session = mock("session", :get => mock("restfully response", :body => {
|
50
|
+
'rennes' => {
|
51
|
+
'links' => [
|
52
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/versions', 'resolvable' => false, 'title' => 'versions'}
|
53
|
+
],
|
54
|
+
'uid' => 'rennes'
|
55
|
+
}
|
56
|
+
}), :logger => @logger))
|
57
|
+
Resource.should_not_receive(:new)
|
58
|
+
collection.load
|
59
|
+
collection['rennes'].should be_nil
|
60
|
+
end
|
61
|
+
it "should initialize resources having a self link" do
|
62
|
+
collection = Collection.new("uri", session = mock("session", :get => mock("restfully response", :body => {
|
63
|
+
'rennes' => {
|
64
|
+
'links' => [
|
65
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes'},
|
66
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/versions', 'resolvable' => false, 'title' => 'versions'}
|
67
|
+
],
|
68
|
+
'uid' => 'rennes'
|
69
|
+
}
|
70
|
+
}), :logger => @logger))
|
71
|
+
Resource.should_receive(:new).with('/grid5000/sites/rennes', session, :raw => {
|
72
|
+
'links' => [
|
73
|
+
{'rel' => 'self', 'href' => '/grid5000/sites/rennes'},
|
74
|
+
{'rel' => 'collection', 'href' => '/grid5000/sites/rennes/versions', 'resolvable' => false, 'title' => 'versions'}
|
75
|
+
],
|
76
|
+
'uid' => 'rennes'
|
77
|
+
}).and_return(resource=mock("restfully resource"))
|
78
|
+
resource.should_receive(:load).and_return(resource)
|
79
|
+
collection.load
|
80
|
+
collection['rennes'].should == resource
|
81
|
+
end
|
82
|
+
it "should correctly initialize its resources [integration test]" do
|
83
|
+
collection = Collection.new("uri", session=mock("session", :logger => Logger.new(STDOUT), :get => @response_200))
|
84
|
+
collection.load
|
85
|
+
collection.should be_loaded
|
86
|
+
collection.uri.should == "uri"
|
87
|
+
collection['rennes'].uid.should == 'rennes'
|
88
|
+
collection['rennes'].type.should == 'site'
|
89
|
+
collection.keys.should =~ ['rennes', 'lille', 'bordeaux', 'nancy', 'sophia', 'toulouse', 'lyon', 'grenoble', 'orsay']
|
90
|
+
end
|
34
91
|
end
|
35
|
-
it "should force reload when query parameters are given"
|
36
92
|
|
37
93
|
end
|