glennr_opensrs 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +33 -0
- data/LICENSE +20 -0
- data/README.rdoc +97 -0
- data/Rakefile +40 -0
- data/lib/opensrs.rb +8 -0
- data/lib/opensrs/response.rb +29 -0
- data/lib/opensrs/server.rb +77 -0
- data/lib/opensrs/version.rb +5 -0
- data/lib/opensrs/xml_processor.rb +77 -0
- data/lib/opensrs/xml_processor/libxml.rb +60 -0
- data/lib/opensrs/xml_processor/nokogiri.rb +59 -0
- data/opensrs.gemspec +76 -0
- data/spec/opensrs/server_spec.rb +109 -0
- data/spec/opensrs/version_spec.rb +9 -0
- data/spec/opensrs/xml_processor/libxml_spec.rb +254 -0
- data/spec/opensrs/xml_processor/nokogiri_spec.rb +228 -0
- data/spec/spec_helper.rb +6 -0
- metadata +182 -0
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
describe OpenSRS::XmlProcessor::Nokogiri do
|
5
|
+
describe ".build" do
|
6
|
+
it "should create XML for a nested hash" do
|
7
|
+
attributes = {:foo => {:bar => 'baz'}}
|
8
|
+
xml = OpenSRS::XmlProcessor::Nokogiri.build(attributes)
|
9
|
+
xml.should eq %{<?xml version=\"1.0\"?>\n<OPS_envelope>\n <header>\n <version>0.9</version>\n </header>\n <body>\n <data_block>\n <dt_assoc>\n <item key=\"foo\">\n <dt_assoc>\n <item key=\"bar\">baz</item>\n </dt_assoc>\n </item>\n </dt_assoc>\n </data_block>\n </body>\n</OPS_envelope>\n}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.encode_data' do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@builder = ::Nokogiri::XML::Builder.new
|
17
|
+
@doc = @builder.doc
|
18
|
+
end
|
19
|
+
|
20
|
+
context "on a 3 element array" do
|
21
|
+
before(:each) do
|
22
|
+
@e = OpenSRS::XmlProcessor::Nokogiri.encode_data([1,2,3], @doc)
|
23
|
+
end
|
24
|
+
|
25
|
+
it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
|
26
|
+
it { @e.name.should eql('dt_array') }
|
27
|
+
|
28
|
+
it { @e.should have(3).children }
|
29
|
+
it { @e.children[0].name.should eql("item") }
|
30
|
+
it { @e.children[1].name.should eql("item") }
|
31
|
+
it { @e.children[2].name.should eql("item") }
|
32
|
+
|
33
|
+
it { @e.children[0].attributes["key"].value.should eql("0") }
|
34
|
+
it { @e.children[1].attributes["key"].value.should eql("1") }
|
35
|
+
it { @e.children[2].attributes["key"].value.should eql("2") }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "on a hash" do
|
39
|
+
before(:each) do
|
40
|
+
@e = OpenSRS::XmlProcessor::Nokogiri.encode_data({:name => "kitteh"}, @doc)
|
41
|
+
end
|
42
|
+
|
43
|
+
it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
|
44
|
+
it { @e.name.should eql('dt_assoc') }
|
45
|
+
|
46
|
+
it { @e.should have(1).children }
|
47
|
+
it { @e.children[0].name.should eql('item') }
|
48
|
+
it { @e.children[0].attributes["key"].value.should eql('name') }
|
49
|
+
end
|
50
|
+
|
51
|
+
context "on a nested hash" do
|
52
|
+
before(:each) do
|
53
|
+
@e = OpenSRS::XmlProcessor::Nokogiri.encode_data({:suggestion => {:maximum => "10"}}, @doc)
|
54
|
+
@suggestion = @e.children[0]
|
55
|
+
@dt_assoc = @suggestion.children[0]
|
56
|
+
end
|
57
|
+
|
58
|
+
it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
|
59
|
+
it { @e.name.should == 'dt_assoc' }
|
60
|
+
|
61
|
+
context "<item> child" do
|
62
|
+
it { @e.should have(1).children }
|
63
|
+
it { @suggestion.name.should eql('item') }
|
64
|
+
it { @suggestion.attributes["key"].value.should eql('suggestion') }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "suggesion children" do
|
68
|
+
it { @suggestion.should have(1).children }
|
69
|
+
it { @dt_assoc.name.should eql('dt_assoc') }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "dt_assoc children" do
|
73
|
+
before(:each) do
|
74
|
+
@maximum = @dt_assoc.children[0]
|
75
|
+
end
|
76
|
+
it { @dt_assoc.should have(1).children }
|
77
|
+
it { @maximum.name.should eql('item') }
|
78
|
+
it { @maximum.attributes["key"].value.should eql('maximum') }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "produces a scalar" do
|
83
|
+
it { OpenSRS::XmlProcessor::Nokogiri.encode_data("cheezburger").to_s.should eql("cheezburger") }
|
84
|
+
it { OpenSRS::XmlProcessor::Nokogiri.encode_data("<smile>").to_s.should eql("<smile>") }
|
85
|
+
|
86
|
+
it { OpenSRS::XmlProcessor::Nokogiri.encode_data(12345).to_s.should eql("12345") }
|
87
|
+
it { OpenSRS::XmlProcessor::Nokogiri.encode_data(Date.parse("2010/02/12")).to_s.should eql("2010-02-12") }
|
88
|
+
it { OpenSRS::XmlProcessor::Nokogiri.encode_data(:name).to_s.should eql("name") }
|
89
|
+
it { OpenSRS::XmlProcessor::Nokogiri.encode_data(true).to_s.should eql("true") }
|
90
|
+
it { OpenSRS::XmlProcessor::Nokogiri.encode_data(false).to_s.should eql("false") }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '.parse' do
|
95
|
+
|
96
|
+
context "when scaler values" do
|
97
|
+
before(:each) do
|
98
|
+
xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
|
99
|
+
<!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
|
100
|
+
<OPS_envelope>
|
101
|
+
<header>
|
102
|
+
<version>1.0</version>
|
103
|
+
</header>
|
104
|
+
<body>
|
105
|
+
<data_block>
|
106
|
+
<dt_scalar>Tom Jones</dt_scalar>
|
107
|
+
</data_block>
|
108
|
+
</body>
|
109
|
+
</OPS_envelope>}
|
110
|
+
@response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
|
111
|
+
end
|
112
|
+
|
113
|
+
it { @response.should eql("Tom Jones") }
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when associative arrays with arrays of values" do
|
117
|
+
before(:each) do
|
118
|
+
xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
|
119
|
+
<!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
|
120
|
+
<OPS_envelope>
|
121
|
+
<header>
|
122
|
+
<version>1.0</version>
|
123
|
+
</header>
|
124
|
+
<body>
|
125
|
+
<data_block>
|
126
|
+
<dt_assoc>
|
127
|
+
<item key='domain_list'>
|
128
|
+
<dt_array>
|
129
|
+
<item key='0'>ns1.example.com</item>
|
130
|
+
<item key='1'>ns2.example.com</item>
|
131
|
+
<item key='2'>ns3.example.com</item>
|
132
|
+
</dt_array>
|
133
|
+
</item>
|
134
|
+
</dt_assoc>
|
135
|
+
</data_block>
|
136
|
+
</body>
|
137
|
+
</OPS_envelope>}
|
138
|
+
|
139
|
+
@response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
|
140
|
+
end
|
141
|
+
|
142
|
+
it { @response["domain_list"].class.should eql(Array) }
|
143
|
+
it { @response["domain_list"][0].should eql("ns1.example.com") }
|
144
|
+
it { @response["domain_list"][1].should eql("ns2.example.com") }
|
145
|
+
it { @response["domain_list"][2].should eql("ns3.example.com") }
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when associative arrays containing other associative arrays" do
|
149
|
+
before(:each) do
|
150
|
+
xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
|
151
|
+
<!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
|
152
|
+
<OPS_envelope>
|
153
|
+
<header>
|
154
|
+
<version>1.0</version>
|
155
|
+
</header>
|
156
|
+
<body>
|
157
|
+
<data_block>
|
158
|
+
<dt_assoc>
|
159
|
+
<item key="contact_set">
|
160
|
+
<dt_assoc>
|
161
|
+
<item key='owner'>
|
162
|
+
<dt_assoc>
|
163
|
+
<item key='first_name'>Tom</item>
|
164
|
+
<item key='last_name'>Jones</item>
|
165
|
+
</dt_assoc>
|
166
|
+
</item>
|
167
|
+
<item key='tech'>
|
168
|
+
<dt_assoc>
|
169
|
+
<item key='first_name'>Anne</item>
|
170
|
+
<item key='last_name'>Smith</item>
|
171
|
+
</dt_assoc>
|
172
|
+
</item>
|
173
|
+
</dt_assoc>
|
174
|
+
</item>
|
175
|
+
</dt_assoc>
|
176
|
+
</data_block>
|
177
|
+
</body>
|
178
|
+
</OPS_envelope>}
|
179
|
+
|
180
|
+
@response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
|
181
|
+
end
|
182
|
+
it { @response["contact_set"]["owner"]["first_name"].should eql("Tom") }
|
183
|
+
it { @response["contact_set"]["owner"]["last_name"].should eql("Jones") }
|
184
|
+
it { @response["contact_set"]["tech"]["first_name"].should eql("Anne") }
|
185
|
+
it { @response["contact_set"]["tech"]["last_name"].should eql("Smith") }
|
186
|
+
end
|
187
|
+
|
188
|
+
context "with a balance enquiry example response" do
|
189
|
+
before(:each) do
|
190
|
+
xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
|
191
|
+
<!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
|
192
|
+
<OPS_envelope>
|
193
|
+
<header>
|
194
|
+
<version>0.9</version>
|
195
|
+
</header>
|
196
|
+
<body>
|
197
|
+
<data_block>
|
198
|
+
<dt_assoc>
|
199
|
+
<item key="protocol">XCP</item>
|
200
|
+
<item key="action">REPLY</item>
|
201
|
+
<item key="object">BALANCE</item>
|
202
|
+
<item key="is_success">1</item>
|
203
|
+
<item key="response_code">200</item>
|
204
|
+
<item key="response_text">Command successful</item>
|
205
|
+
<item key="attributes">
|
206
|
+
<dt_assoc>
|
207
|
+
<item key="balance">8549.18</item>
|
208
|
+
<item key="hold_balance">1676.05</item>
|
209
|
+
</dt_assoc>
|
210
|
+
</item>
|
211
|
+
</dt_assoc>
|
212
|
+
</data_block>
|
213
|
+
</body>
|
214
|
+
</OPS_envelope>}
|
215
|
+
|
216
|
+
@response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
|
217
|
+
end
|
218
|
+
|
219
|
+
it { @response.should be_an_instance_of(Hash) }
|
220
|
+
it { @response["protocol"].should eql("XCP") }
|
221
|
+
it { @response["action"].should eql("REPLY") }
|
222
|
+
it { @response["object"].should eql("BALANCE") }
|
223
|
+
it { @response["attributes"]["balance"].should eql("8549.18") }
|
224
|
+
it { @response["attributes"]["hold_balance"].should eql("1676.05") }
|
225
|
+
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glennr_opensrs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Delsman
|
9
|
+
- Glenn Roberts
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: libxml-ruby
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.1.2
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: nokogiri
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.4.6
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.4.6
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: git
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rake
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: shoulda
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '2.0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '2.0'
|
127
|
+
description: Provides support to utilize the OpenSRS API with Ruby/Rails.
|
128
|
+
email: glenn@siyelo.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files:
|
132
|
+
- LICENSE
|
133
|
+
- README.rdoc
|
134
|
+
files:
|
135
|
+
- .document
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE
|
139
|
+
- README.rdoc
|
140
|
+
- Rakefile
|
141
|
+
- lib/opensrs.rb
|
142
|
+
- lib/opensrs/response.rb
|
143
|
+
- lib/opensrs/server.rb
|
144
|
+
- lib/opensrs/version.rb
|
145
|
+
- lib/opensrs/xml_processor.rb
|
146
|
+
- lib/opensrs/xml_processor/libxml.rb
|
147
|
+
- lib/opensrs/xml_processor/nokogiri.rb
|
148
|
+
- opensrs.gemspec
|
149
|
+
- spec/opensrs/server_spec.rb
|
150
|
+
- spec/opensrs/version_spec.rb
|
151
|
+
- spec/opensrs/xml_processor/libxml_spec.rb
|
152
|
+
- spec/opensrs/xml_processor/nokogiri_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
homepage: http://github.com/glennr/opensrs
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
hash: -274764561660248788
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ! '>='
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 1.8.23
|
179
|
+
signing_key:
|
180
|
+
specification_version: 3
|
181
|
+
summary: Provides support to utilize the OpenSRS API with Ruby/Rails.
|
182
|
+
test_files: []
|