moon 0.0.2 → 0.0.3
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/lib/moon/response.rb +1 -0
- data/lib/moon/response/xml.rb +21 -0
- data/spec/lib/moon/response/xml_spec.rb +33 -0
- metadata +7 -4
data/lib/moon/response.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'xmlsimple'
|
2
|
+
|
3
|
+
# Moon::Response::XML is the base class for all xml responses.
|
4
|
+
class Moon::Response::XML < Moon::Response::Base
|
5
|
+
|
6
|
+
attr_accessor :status
|
7
|
+
attr_accessor :hash
|
8
|
+
|
9
|
+
def initialize(status, root_tag, hash = { })
|
10
|
+
@status, @root_tag, @hash = status, root_tag, hash
|
11
|
+
end
|
12
|
+
|
13
|
+
def headers
|
14
|
+
{ "Content-Type" => "text/xml" }
|
15
|
+
end
|
16
|
+
|
17
|
+
def body
|
18
|
+
XmlSimple.xml_out @hash, "RootName" => @root_tag, "XmlDeclaration" => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
|
2
|
+
|
3
|
+
describe Moon::Response::XML do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@response = described_class.new 201, "root", { "message" => { "content" => "OK", "priority" => "normal" } }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "status" do
|
10
|
+
|
11
|
+
it "should return 201" do
|
12
|
+
@response.status.should == 201
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "headers" do
|
18
|
+
|
19
|
+
it "should return a hash with the right content type" do
|
20
|
+
@response.headers.should == { "Content-Type" => "text/xml" }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "body" do
|
26
|
+
|
27
|
+
it "should return the given hash encoded in json" do
|
28
|
+
@response.body.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>\n <message priority=\"normal\">OK</message>\n</root>\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: moon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Philipp Br\xC3\xBCll"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-23 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: *id005
|
71
|
-
description: A simple rack application library -
|
71
|
+
description: A simple rack application library - alpha release.
|
72
72
|
email: b.phifty@gmail.com
|
73
73
|
executables: []
|
74
74
|
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/moon/response/json/blank.rb
|
106
106
|
- lib/moon/response/json/collection.rb
|
107
107
|
- lib/moon/response/json.rb
|
108
|
+
- lib/moon/response/xml.rb
|
108
109
|
- lib/moon/utility.rb
|
109
110
|
- lib/moon/utility/string.rb
|
110
111
|
- lib/moon/utility/template.rb
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- spec/lib/moon/response/json/blank_spec.rb
|
141
142
|
- spec/lib/moon/response/json/message_spec.rb
|
142
143
|
- spec/lib/moon/response/base_spec.rb
|
144
|
+
- spec/lib/moon/response/xml_spec.rb
|
143
145
|
- spec/lib/moon/response/json_spec.rb
|
144
146
|
- spec/lib/moon/utility/string_spec.rb
|
145
147
|
- spec/lib/moon/utility/template_spec.rb
|
@@ -164,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
166
|
requirements:
|
165
167
|
- - ">="
|
166
168
|
- !ruby/object:Gem::Version
|
167
|
-
hash: -
|
169
|
+
hash: -4097296464974115511
|
168
170
|
segments:
|
169
171
|
- 0
|
170
172
|
version: "0"
|
@@ -204,6 +206,7 @@ test_files:
|
|
204
206
|
- spec/lib/moon/response/json/blank_spec.rb
|
205
207
|
- spec/lib/moon/response/json/message_spec.rb
|
206
208
|
- spec/lib/moon/response/base_spec.rb
|
209
|
+
- spec/lib/moon/response/xml_spec.rb
|
207
210
|
- spec/lib/moon/response/json_spec.rb
|
208
211
|
- spec/lib/moon/utility/string_spec.rb
|
209
212
|
- spec/lib/moon/utility/template_spec.rb
|