restfully 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -0
- data/README.rdoc +67 -29
- data/VERSION +1 -1
- data/bin/restfully +68 -46
- data/examples/grid5000.rb +6 -6
- data/lib/restfully.rb +2 -1
- data/lib/restfully/collection.rb +98 -15
- data/lib/restfully/parsing.rb +2 -2
- data/lib/restfully/resource.rb +5 -5
- data/lib/restfully/session.rb +11 -6
- data/restfully.gemspec +3 -4
- data/spec/collection_spec.rb +44 -39
- data/spec/fixtures/grid5000-sites.json +538 -487
- data/spec/http/error_spec.rb +1 -1
- data/spec/http/headers_spec.rb +1 -1
- data/spec/http/request_spec.rb +1 -1
- data/spec/http/response_spec.rb +1 -1
- data/spec/http/rest_client_adapter_spec.rb +1 -1
- data/spec/link_spec.rb +1 -1
- data/spec/parsing_spec.rb +1 -1
- data/spec/resource_spec.rb +3 -3
- data/spec/restfully_spec.rb +1 -1
- data/spec/session_spec.rb +23 -19
- metadata +3 -3
data/spec/http/error_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/../spec_helper')
|
2
2
|
describe Restfully::HTTP::Error do
|
3
3
|
it "should have a response reader" do
|
4
4
|
response = mock("restfully response", :status => 404, :body => {'title' => 'Not Found', 'message' => 'The requested resource cannot be found.', 'code' => 404})
|
data/spec/http/headers_spec.rb
CHANGED
data/spec/http/request_spec.rb
CHANGED
data/spec/http/response_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/../spec_helper')
|
2
2
|
describe Restfully::HTTP::Adapters::RestClientAdapter do
|
3
3
|
it "should correctly get the resource corresponding to the request" do
|
4
4
|
adapter = Restfully::HTTP::Adapters::RestClientAdapter.new("https://api.grid5000.fr", :username => 'crohr', :password => 'password')
|
data/spec/link_spec.rb
CHANGED
data/spec/parsing_spec.rb
CHANGED
data/spec/resource_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/spec_helper')
|
2
2
|
|
3
3
|
include Restfully
|
4
4
|
|
@@ -29,9 +29,9 @@ describe Resource do
|
|
29
29
|
resource.uri.should == "uri"
|
30
30
|
end
|
31
31
|
it "should have a reader on the raw property" do
|
32
|
-
resource = Resource.new("uri", session=mock("session")
|
32
|
+
resource = Resource.new("uri", session=mock("session"))
|
33
33
|
resource.should_not respond_to(:raw=)
|
34
|
-
resource.raw.should == {}
|
34
|
+
resource.load('raw' => {:a => :b}).raw.should == {:a => :b}
|
35
35
|
end
|
36
36
|
it "should have a reader on the state property" do
|
37
37
|
resource = Resource.new("uri", session=mock("session"))
|
data/spec/restfully_spec.rb
CHANGED
data/spec/session_spec.rb
CHANGED
@@ -1,57 +1,62 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/spec_helper')
|
2
|
+
|
3
|
+
restfully_version = File.read(File.dirname(__FILE__)+'/../VERSION').strip
|
2
4
|
|
3
5
|
include Restfully
|
4
6
|
describe Session do
|
5
7
|
describe "initialization" do
|
6
8
|
it "should have a logger reader" do
|
7
|
-
session = Session.new('https://api.grid5000.fr')
|
9
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr')
|
8
10
|
session.should_not respond_to(:logger=)
|
9
11
|
session.should respond_to(:logger)
|
10
12
|
end
|
11
13
|
it "should have a base_uri reader" do
|
12
|
-
session = Session.new('https://api.grid5000.fr')
|
14
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr')
|
13
15
|
session.should_not respond_to(:base_uri=)
|
14
16
|
session.base_uri.should == 'https://api.grid5000.fr'
|
15
17
|
end
|
16
18
|
it "should have a root_path reader that returns the path of the root resource, relative to the base URI" do
|
17
|
-
session = Session.new('https://api.grid5000.fr/sid', 'root_path' => '/grid5000')
|
19
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr/sid', 'root_path' => '/grid5000')
|
18
20
|
session.should_not respond_to(:root_path=)
|
19
21
|
session.root_path.should == '/grid5000'
|
20
22
|
end
|
21
23
|
it "should set the default root_path to /" do
|
22
|
-
session = Session.new('https://api.grid5000.fr')
|
24
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr')
|
23
25
|
session.root_path.should == '/'
|
24
26
|
end
|
25
27
|
it "should log to NullLogger by default" do
|
26
|
-
NullLogger.should_receive(:new).and_return(logger = mock(NullLogger))
|
27
|
-
session = Session.new('https://api.grid5000.fr')
|
28
|
+
NullLogger.should_receive(:new).and_return(logger = mock(NullLogger, :debug => Proc.new{}))
|
29
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr')
|
28
30
|
session.logger.should == logger
|
29
31
|
end
|
30
32
|
it "should use the given logger" do
|
31
|
-
logger = mock("custom logger")
|
32
|
-
session = Session.new('https://api.grid5000.fr', 'logger' => logger)
|
33
|
+
logger = mock("custom logger", :debug => Proc.new{})
|
34
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr', 'logger' => logger)
|
33
35
|
session.logger.should == logger
|
34
36
|
end
|
35
37
|
it "should set a default Accept HTTP header if no default headers are given" do
|
36
|
-
session = Session.new('https://api.grid5000.fr')
|
38
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr')
|
37
39
|
session.default_headers.should == {
|
40
|
+
"User-Agent"=>"Restfully/#{restfully_version}",
|
38
41
|
'Accept' => 'application/json'
|
39
42
|
}
|
40
43
|
end
|
41
44
|
it "should use the given default headers" do
|
42
|
-
session = Session.new('https://api.grid5000.fr', :default_headers => {:accept => 'application/xml'})
|
45
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr', :default_headers => {:accept => 'application/xml'})
|
43
46
|
session.default_headers.should == {
|
44
|
-
|
47
|
+
"User-Agent"=>"Restfully/#{restfully_version}",
|
48
|
+
"Accept" => 'application/xml'
|
45
49
|
}
|
46
50
|
end
|
47
51
|
it "should correctly initialize the connection" do
|
48
|
-
|
49
|
-
|
52
|
+
mock_logger = mock("logger", :debug => Proc.new{})
|
53
|
+
Restfully.adapter.should_receive(:new).with('https://api.grid5000.fr/sid', :user => 'crohr', :password => 'password', :logger => mock_logger).and_return(connection = mock("restfully connection"))
|
54
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr/sid', 'root_path' => '/grid5000', :user => 'crohr', :password => 'password', :logger => mock_logger)
|
50
55
|
session.connection.should == connection
|
51
56
|
end
|
52
57
|
|
53
58
|
it "should initialize the root resource" do
|
54
|
-
session = Session.new('https://api.grid5000.fr', 'root_path' => '/grid5000', :user => 'crohr', :password => 'password')
|
59
|
+
session = Session.new(:base_uri => 'https://api.grid5000.fr', 'root_path' => '/grid5000', :user => 'crohr', :password => 'password')
|
55
60
|
session.root.should be_a Restfully::Resource
|
56
61
|
session.root.uri.to_s.should == '/grid5000'
|
57
62
|
session.root.should_not be_loaded
|
@@ -60,7 +65,7 @@ describe Session do
|
|
60
65
|
it "should yield the loaded root resource and the session object" do
|
61
66
|
Restfully::Resource.stub!(:new).and_return(root_resource = mock(Restfully::Resource))
|
62
67
|
root_resource.should_receive(:load).and_return(root_resource)
|
63
|
-
Session.new('https://api.grid5000.fr', :root_path => '/grid5000', :user => 'crohr', :password => 'password') do |root, session|
|
68
|
+
Session.new(:base_uri => 'https://api.grid5000.fr', :root_path => '/grid5000', :user => 'crohr', :password => 'password') do |root, session|
|
64
69
|
session.root.should == root
|
65
70
|
root.should == root_resource
|
66
71
|
end
|
@@ -69,8 +74,9 @@ describe Session do
|
|
69
74
|
|
70
75
|
describe "Getting resources" do
|
71
76
|
before(:each) do
|
72
|
-
@session = Session.new('https://api.grid5000.fr/sid', :root_path => '/grid5000', :user => 'crohr', :password => 'password', :default_headers => {})
|
77
|
+
@session = Session.new(:base_uri => 'https://api.grid5000.fr/sid', :root_path => '/grid5000', :user => 'crohr', :password => 'password', :default_headers => {})
|
73
78
|
@request = mock("restfully http request", :uri => mock("uri"), :headers => mock("headers"))
|
79
|
+
@request.should_receive(:add_headers).with("User-Agent"=>"Restfully/#{restfully_version}", "Accept"=>"application/json")
|
74
80
|
@response = mock("restfully http response", :status => 200, :headers => mock("headers"))
|
75
81
|
end
|
76
82
|
it "should create a new Request object and pass it to the connection" do
|
@@ -85,8 +91,6 @@ describe Session do
|
|
85
91
|
end
|
86
92
|
it "should add the session's default headers to the request's headers" do
|
87
93
|
Restfully::HTTP::Request.should_receive(:new).with(URI.parse('http://somehost.com/some/path'), :headers => {}, :query => {}).and_return(@request)
|
88
|
-
@session.default_headers['cache-control'] = 'max-age=0'
|
89
|
-
@request.should_receive(:add_headers).with('cache-control' => 'max-age=0')
|
90
94
|
@session.connection.should_receive(:get).with(@request).and_return(@response)
|
91
95
|
@session.get('http://somehost.com/some/path').should == @response
|
92
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restfully
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Rohr
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-26 00:00:00 +01:00
|
13
13
|
default_executable: restfully
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
requirements: []
|
98
98
|
|
99
99
|
rubyforge_project: restfully
|
100
|
-
rubygems_version: 1.3.
|
100
|
+
rubygems_version: 1.3.5
|
101
101
|
signing_key:
|
102
102
|
specification_version: 3
|
103
103
|
summary: Experimental code for auto-generation of wrappers on top of RESTful APIs that follow some specific conventions.
|