restfully 0.7.1.rc1 → 0.7.1.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/restfully/http/response.rb +4 -0
- data/lib/restfully/media_type/application_vnd_bonfire_xml.rb +11 -2
- data/lib/restfully/session.rb +4 -0
- data/lib/restfully/version.rb +1 -1
- data/spec/restfully/collection_spec.rb +0 -1
- data/spec/restfully/media_type/application_vnd_bonfire_xml_spec.rb +15 -1
- metadata +4 -4
@@ -135,7 +135,12 @@ module Restfully
|
|
135
135
|
when Restfully::Resource
|
136
136
|
dump_object({"href" => object.uri.to_s}, parent)
|
137
137
|
when Hash
|
138
|
-
|
138
|
+
object.stringify_keys!
|
139
|
+
if object.has_key?("href") || (
|
140
|
+
# or object.keys == ["name"] && parent.parent &&
|
141
|
+
# parent.parent.parent
|
142
|
+
["save_as"].include?(parent.name)
|
143
|
+
)
|
139
144
|
# only attributes
|
140
145
|
object.each{|kattr,vattr|
|
141
146
|
parent.attributes[kattr.to_s] = vattr
|
@@ -149,9 +154,13 @@ module Restfully
|
|
149
154
|
end
|
150
155
|
end
|
151
156
|
when Array
|
157
|
+
i = 0
|
158
|
+
parent['id'] = i.to_s
|
152
159
|
dump_object(object[0], parent)
|
153
160
|
object[1..-1].each{|item|
|
161
|
+
i+=1
|
154
162
|
node = XML::Node.new(parent.name)
|
163
|
+
node['id'] = i.to_s
|
155
164
|
dump_object(item, node)
|
156
165
|
parent.parent << node
|
157
166
|
}
|
@@ -178,7 +187,7 @@ module Restfully
|
|
178
187
|
end
|
179
188
|
|
180
189
|
def represents?(id)
|
181
|
-
property("id") == id.to_s || property("name") == id.to_s
|
190
|
+
property("id") == id.to_s || property("name") == id.to_s || links.find{|l| l.self? && l.href.to_s.split("/").last == id.to_s}
|
182
191
|
end
|
183
192
|
|
184
193
|
def complete?
|
data/lib/restfully/session.rb
CHANGED
@@ -119,14 +119,18 @@ module Restfully
|
|
119
119
|
code, head, body = resource.send(request.method, request.body || {})
|
120
120
|
|
121
121
|
response = Restfully::HTTP::Response.new(self, code, head, body)
|
122
|
+
logger.debug response.inspect
|
123
|
+
response
|
122
124
|
end
|
123
125
|
|
124
126
|
# Process a Restfully::HTTP::Response.
|
125
127
|
def process(response, request)
|
126
128
|
case code=response.code
|
127
129
|
when 200
|
130
|
+
logger.debug "Building response..."
|
128
131
|
Resource.new(self, response, request).build
|
129
132
|
when 201,202
|
133
|
+
logger.debug "Following redirection to: #{response.head['Location'].inspect}"
|
130
134
|
get response.head['Location'], :head => request.head
|
131
135
|
when 204
|
132
136
|
true
|
data/lib/restfully/version.rb
CHANGED
@@ -38,7 +38,6 @@ describe Restfully::Collection do
|
|
38
38
|
items = []
|
39
39
|
@resource.load.each{|i| items << i}
|
40
40
|
items.all?{|i| i.kind_of?(Restfully::Resource)}.should be_true
|
41
|
-
pp items
|
42
41
|
items[0].relationships.map(&:to_s).sort.should == ["parent", "self"]
|
43
42
|
items[0]['uid'].should == 376505
|
44
43
|
end
|
@@ -154,7 +154,21 @@ describe Restfully::MediaType::ApplicationVndBonfireXml do
|
|
154
154
|
@expected_compute_hash,
|
155
155
|
:serialization => {"__type__" => "compute"}
|
156
156
|
)
|
157
|
-
serialized.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<compute xmlns=\"http://api.bonfire-project.eu/doc/schemas/occi\">\n <startup href=\"file:///path/to/startup-script/sh\"/>\n <name>Compute name</name>\n <instance_type>small</instance_type>\n <link href=\"/locations/fr-inria\" rel=\"location\" type=\"application/vnd.bonfire+xml\"/>\n <link href=\"/locations/uk-epcc/computes/1\" rel=\"self\"/>\n <context>\n <bonfire_credentials>crohr:p4ssw0rd</bonfire_credentials>\n <monitoring_ip>123.123.123.2</monitoring_ip>\n </context>\n <nic>\n <device>eth0</device>\n <mac>AA:AA:AA:AA</mac>\n <network href=\"/locations/fr-inria/networks/1\"/>\n <ip>123.123.123.123</ip>\n </nic>\n <nic>\n <device>eth1</device>\n <mac>BB:BB:BB:BB</mac>\n <network href=\"/locations/fr-inria/networks/2\"/>\n <ip>123.123.124.2</ip>\n </nic>\n <description>Compute description</description>\n <disk>\n <type>OS</type>\n <storage href=\"/locations/fr-inria/storages/1\"/>\n <target>sda</target>\n </disk>\n <disk>\n <type>CDROM</type>\n <storage href=\"/locations/fr-inria/storages/2\"/>\n <target>sdc</target>\n </disk>\n <state>ACTIVE</state>\n</compute>\n"
|
157
|
+
serialized.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<compute xmlns=\"http://api.bonfire-project.eu/doc/schemas/occi\">\n <startup href=\"file:///path/to/startup-script/sh\"/>\n <name>Compute name</name>\n <instance_type>small</instance_type>\n <link id=\"0\" href=\"/locations/fr-inria\" rel=\"location\" type=\"application/vnd.bonfire+xml\"/>\n <link id=\"1\" href=\"/locations/uk-epcc/computes/1\" rel=\"self\"/>\n <context>\n <bonfire_credentials>crohr:p4ssw0rd</bonfire_credentials>\n <monitoring_ip>123.123.123.2</monitoring_ip>\n </context>\n <nic id=\"0\">\n <device>eth0</device>\n <mac>AA:AA:AA:AA</mac>\n <network href=\"/locations/fr-inria/networks/1\"/>\n <ip>123.123.123.123</ip>\n </nic>\n <nic id=\"1\">\n <device>eth1</device>\n <mac>BB:BB:BB:BB</mac>\n <network href=\"/locations/fr-inria/networks/2\"/>\n <ip>123.123.124.2</ip>\n </nic>\n <description>Compute description</description>\n <disk id=\"0\">\n <type>OS</type>\n <storage href=\"/locations/fr-inria/storages/1\"/>\n <target>sda</target>\n </disk>\n <disk id=\"1\">\n <type>CDROM</type>\n <storage href=\"/locations/fr-inria/storages/2\"/>\n <target>sdc</target>\n </disk>\n <state>ACTIVE</state>\n</compute>\n"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should correctly deal with SAVE_AS elements" do
|
161
|
+
serialized = Restfully::MediaType::ApplicationVndBonfireXml.serialize(
|
162
|
+
{
|
163
|
+
:name => "whatever",
|
164
|
+
:disk => [{
|
165
|
+
:storage => {"href" => "/somewhere"},
|
166
|
+
:save_as => {:name => "name of storage"}
|
167
|
+
}]
|
168
|
+
},
|
169
|
+
:serialization => {"__type__" => "compute"}
|
170
|
+
)
|
171
|
+
serialized.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<compute xmlns=\"http://api.bonfire-project.eu/doc/schemas/occi\">\n <name>whatever</name>\n <disk id=\"0\">\n <save_as name=\"name of storage\"/>\n <storage href=\"/somewhere\"/>\n </disk>\n</compute>\n"
|
158
172
|
end
|
159
173
|
end
|
160
174
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restfully
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424105
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
9
|
- 1
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 0.7.1.
|
11
|
+
- 2
|
12
|
+
version: 0.7.1.rc2
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Cyril Rohr
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-05-
|
20
|
+
date: 2011-05-13 00:00:00 +02:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|