wrest 1.0.0.beta1 → 1.0.0.beta2
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/CHANGELOG +14 -2
- data/LICENCE +7 -0
- data/README.rdoc +15 -69
- data/lib/wrest/components/container/alias_accessors.rb +1 -1
- data/lib/wrest/components/container/alias_accessors.rbc +905 -0
- data/lib/wrest/components/container/typecaster.rb +5 -5
- data/lib/wrest/components/container/typecaster.rbc +1985 -0
- data/lib/wrest/components/container.rb +11 -12
- data/lib/wrest/components/container.rbc +2466 -0
- data/lib/wrest/components/mutators/base.rbc +702 -0
- data/lib/wrest/components/mutators/camel_to_snake_case.rbc +360 -0
- data/lib/wrest/components/mutators/xml_mini_type_caster.rbc +679 -0
- data/lib/wrest/components/mutators/xml_simple_type_caster.rbc +559 -0
- data/lib/wrest/components/mutators.rbc +650 -0
- data/lib/wrest/components/translators/content_types.rbc +339 -0
- data/lib/wrest/components/translators/json.rbc +462 -0
- data/lib/wrest/components/translators/xml.rbc +457 -0
- data/lib/wrest/components/translators.rbc +517 -0
- data/lib/wrest/components.rbc +217 -0
- data/lib/wrest/core_ext/hash/conversions.rbc +501 -0
- data/lib/wrest/core_ext/hash.rbc +182 -0
- data/lib/wrest/core_ext/string/conversions.rbc +471 -0
- data/lib/wrest/core_ext/string.rbc +182 -0
- data/lib/wrest/curl/response.rb +8 -0
- data/lib/wrest/curl.rbc +704 -0
- data/lib/wrest/exceptions.rbc +312 -0
- data/lib/wrest/http_shared/headers.rb +0 -7
- data/lib/wrest/http_shared/headers.rbc +353 -0
- data/lib/wrest/http_shared/standard_headers.rbc +336 -0
- data/lib/wrest/http_shared/standard_tokens.rbc +316 -0
- data/lib/wrest/http_shared.rbc +279 -0
- data/lib/wrest/native/connection_factory.rbc +445 -0
- data/lib/wrest/native/delete.rbc +371 -0
- data/lib/wrest/native/get.rb +26 -0
- data/lib/wrest/native/get.rbc +855 -0
- data/lib/wrest/native/options.rbc +347 -0
- data/lib/wrest/native/post.rbc +388 -0
- data/lib/wrest/native/put.rbc +388 -0
- data/lib/wrest/native/redirection.rbc +520 -0
- data/lib/wrest/native/request.rb +4 -2
- data/lib/wrest/native/request.rbc +1675 -0
- data/lib/wrest/native/response.rb +53 -2
- data/lib/wrest/native/response.rbc +2150 -0
- data/lib/wrest/native/session.rbc +1372 -0
- data/lib/wrest/native.rbc +513 -0
- data/lib/wrest/resource/base.rbc +2115 -0
- data/lib/wrest/resource.rbc +163 -0
- data/lib/wrest/uri.rbc +2599 -0
- data/lib/wrest/uri_template.rbc +505 -0
- data/lib/wrest/version.rb +1 -1
- data/lib/wrest/version.rbc +372 -0
- data/lib/wrest.rb +1 -1
- data/lib/wrest.rbc +1900 -0
- metadata +99 -102
- data/Rakefile +0 -495
- data/VERSION.yml +0 -5
- data/bin/jwrest +0 -3
- data/examples/delicious.rb +0 -72
- data/examples/facebook.rb +0 -101
- data/examples/imgur_multipart.rb +0 -24
- data/examples/keep_alive.rb +0 -37
- data/examples/redirection.rb +0 -27
- data/examples/twitter.rb +0 -78
- data/examples/twitter_public_timeline.rb +0 -32
- data/examples/wow_realm_status.rb +0 -67
- data/init.rb +0 -0
- data/spec/custom_matchers/custom_matchers.rb +0 -2
- data/spec/rcov.opts +0 -4
- data/spec/spec.opts.disable +0 -6
- data/spec/unit/spec_helper.rb +0 -35
- data/spec/unit/wrest/components/attributes_container/alias_accessors_spec.rb +0 -49
- data/spec/unit/wrest/components/attributes_container/typecaster_spec.rb +0 -83
- data/spec/unit/wrest/components/attributes_container_spec.rb +0 -254
- data/spec/unit/wrest/components/mutators/base_spec.rb +0 -42
- data/spec/unit/wrest/components/mutators/camel_to_snake_spec.rb +0 -22
- data/spec/unit/wrest/components/mutators/xml_mini_type_caster_spec.rb +0 -75
- data/spec/unit/wrest/components/mutators/xml_simple_type_caster_spec.rb +0 -47
- data/spec/unit/wrest/components/mutators_spec.rb +0 -21
- data/spec/unit/wrest/components/translators/xml_spec.rb +0 -16
- data/spec/unit/wrest/components/translators_spec.rb +0 -18
- data/spec/unit/wrest/core_ext/hash/conversions_spec.rb +0 -22
- data/spec/unit/wrest/core_ext/string/conversions_spec.rb +0 -39
- data/spec/unit/wrest/curl/request_spec.rb +0 -19
- data/spec/unit/wrest/curl/response_spec.rb +0 -16
- data/spec/unit/wrest/http/response_spec.rb +0 -24
- data/spec/unit/wrest/native/redirection_spec.rb +0 -42
- data/spec/unit/wrest/native/request_spec.rb +0 -71
- data/spec/unit/wrest/native/response_spec.rb +0 -72
- data/spec/unit/wrest/native/session_spec.rb +0 -74
- data/spec/unit/wrest/resource/base_spec.rb +0 -274
- data/spec/unit/wrest/uri_spec.rb +0 -273
- data/spec/unit/wrest/uri_template_spec.rb +0 -38
- data/wrest.gemspec +0 -168
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
11
|
-
|
|
12
|
-
module Wrest::Components
|
|
13
|
-
describe Container do
|
|
14
|
-
class HumanBeing
|
|
15
|
-
include Wrest::Components::Container
|
|
16
|
-
always_has :id
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class WaterMagician < HumanBeing
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should allow instantiation with no attributes" do
|
|
23
|
-
lambda{ HumanBeing.new }.should_not raise_error
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe 'serialisation' do
|
|
27
|
-
it "should know its xml element name" do
|
|
28
|
-
HumanBeing.element_name.should == 'human_being'
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should know how to serialise itself given any of the Wrest::Components::Translators" do
|
|
32
|
-
result = HumanBeing.new(:age => "70", :name => 'Li Piao').serialise_using(Wrest::Components::Translators::Json)
|
|
33
|
-
expectedPermutationOne = "{\"age\":\"70\",\"name\":\"Li Piao\"}"
|
|
34
|
-
expectedPermutationTwo = "{\"name\":\"Li Piao\",\"age\":\"70\"}"
|
|
35
|
-
|
|
36
|
-
(result == expectedPermutationOne || result == expectedPermutationTwo).should be_true
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "should have a to_xml helper that ensures that the name of the class is the root of the serilised form" do
|
|
40
|
-
result = HumanBeing.new(:age => "70", :name => 'Li Piao').to_xml
|
|
41
|
-
expectedPermutationOne = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<human-being>\n <age>70</age>\n <name>Li Piao</name>\n</human-being>\n"
|
|
42
|
-
expectedPermutationTwo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<human-being>\n <name>Li Piao</name>\n <age>70</age>\n</human-being>\n"
|
|
43
|
-
|
|
44
|
-
(result == expectedPermutationOne || result == expectedPermutationTwo).should be_true
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe 'subclasses' do
|
|
48
|
-
it "should not allow cached element name to clash" do
|
|
49
|
-
WaterMagician.element_name.should == 'water_magician'
|
|
50
|
-
HumanBeing.element_name.should == 'human_being'
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
describe "typecasting" do
|
|
56
|
-
before(:each) do
|
|
57
|
-
@Demon = Class.new
|
|
58
|
-
|
|
59
|
-
@Demon.class_eval do
|
|
60
|
-
include Wrest::Components::Container
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "should delegate to AttributesContainer::Typecaster#typecast to actually do the typecasting" do
|
|
65
|
-
@Demon.class_eval do
|
|
66
|
-
typecast :foo => lambda{|value| value.to_i}
|
|
67
|
-
end
|
|
68
|
-
@Demon.new(:foo => '1').foo.should == 1
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "should provide helpers for common typecasts" do
|
|
72
|
-
@Demon.class_eval do
|
|
73
|
-
typecast :foo => as_integer
|
|
74
|
-
end
|
|
75
|
-
@Demon.new(:foo => '1').foo.should == 1
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
describe 'always_has' do
|
|
80
|
-
describe 'method creation' do
|
|
81
|
-
before :each do
|
|
82
|
-
@Demon = Class.new
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# Methods are string in 1.8 and symbols in 1.9. We'll use to_sym to
|
|
86
|
-
# allow us to build on both.
|
|
87
|
-
it "should define attribute getters at the class level" do
|
|
88
|
-
kai_wren = @Demon.new
|
|
89
|
-
kai_wren.methods.map(&:to_sym).should_not include(:trainer)
|
|
90
|
-
|
|
91
|
-
@Demon.class_eval{
|
|
92
|
-
include Wrest::Components::Container
|
|
93
|
-
always_has :trainer
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
kai_wren.methods.map(&:to_sym).should include(:trainer)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should define attribute setters at the class level" do
|
|
100
|
-
kai_wren = @Demon.new
|
|
101
|
-
kai_wren.methods.map(&:to_sym).should_not include(:trainer=)
|
|
102
|
-
|
|
103
|
-
@Demon.class_eval{
|
|
104
|
-
include Wrest::Components::Container
|
|
105
|
-
always_has :trainer
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
kai_wren.methods.map(&:to_sym).should include(:trainer=)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it "should define attribute query methods at the class level" do
|
|
112
|
-
kai_wren = @Demon.new
|
|
113
|
-
kai_wren.methods.map(&:to_sym).should_not include(:trainer?)
|
|
114
|
-
|
|
115
|
-
@Demon.class_eval{
|
|
116
|
-
include Wrest::Components::Container
|
|
117
|
-
always_has :trainer
|
|
118
|
-
}
|
|
119
|
-
kai_wren.methods.map(&:to_sym).should include(:trainer?)
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe 'method functionality' do
|
|
124
|
-
before :each do
|
|
125
|
-
@Demon = Class.new
|
|
126
|
-
@Demon.class_eval{
|
|
127
|
-
include Wrest::Components::Container
|
|
128
|
-
always_has :trainer
|
|
129
|
-
|
|
130
|
-
def method_missing(method_name, *args)
|
|
131
|
-
# Ensuring that the instance level
|
|
132
|
-
# attribute methods don't kick in
|
|
133
|
-
# by overriding method_missing
|
|
134
|
-
raise NoMethodError.new("Method #{method_name} was invoked, but doesn't exist", method_name)
|
|
135
|
-
end
|
|
136
|
-
}
|
|
137
|
-
@kai_wren = @Demon.new
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "should define attribute getters at the class level" do
|
|
141
|
-
@kai_wren.instance_variable_get("@attributes")[:trainer] = 'Viss'
|
|
142
|
-
@kai_wren.trainer.should == 'Viss'
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it "should define attribute setters at the class level" do
|
|
146
|
-
@kai_wren.trainer = 'Viss'
|
|
147
|
-
@kai_wren.instance_variable_get("@attributes")[:trainer].should == 'Viss'
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it "should define attribute query methods at the class level" do
|
|
151
|
-
@kai_wren.trainer?.should be_false
|
|
152
|
-
@kai_wren.instance_variable_get("@attributes")[:trainer] = 'Viss'
|
|
153
|
-
@kai_wren.trainer?.should be_true
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
describe 'provides an attributes interface which' do
|
|
159
|
-
before :each do
|
|
160
|
-
@li_piao = HumanBeing.new(:id => 5, :profession => 'Natural Magician', 'enhanced_by' => 'Kai Wren')
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it "should provide a generic key based getter that requires symbols" do
|
|
164
|
-
@li_piao[:profession].should == "Natural Magician"
|
|
165
|
-
@li_piao['profession'].should == "Natural Magician"
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
it "should fail when getter methods for attributes that don't exist are invoked" do
|
|
169
|
-
lambda{ @li_piao.ooga }.should raise_error(NoMethodError)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
it "should provide getter methods for attributes" do
|
|
173
|
-
@li_piao.profession.should == 'Natural Magician'
|
|
174
|
-
@li_piao.enhanced_by.should == 'Kai Wren'
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
it "should respond to getter methods for attributes" do
|
|
178
|
-
@li_piao.should respond_to(:profession)
|
|
179
|
-
@li_piao.should respond_to(:enhanced_by)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "should not respond to getter methods for attributes that don't exist" do
|
|
183
|
-
@li_piao.should_not respond_to(:gods)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
it "should provide a generic key based setter that understands symbols" do
|
|
187
|
-
@li_piao[:enhanced_by] = "Viss"
|
|
188
|
-
@li_piao.instance_variable_get('@attributes')[:enhanced_by].should == "Viss"
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
it "should provide a generic key based setter that translates strings to symbols" do
|
|
192
|
-
@li_piao['enhanced_by'] = "Viss"
|
|
193
|
-
@li_piao.instance_variable_get('@attributes')[:enhanced_by].should == "Viss"
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
it "should create a setter method when one is invoked for attributes that don't exist" do
|
|
197
|
-
@li_piao.niece = 'Li Plum'
|
|
198
|
-
@li_piao.instance_variable_get('@attributes')[:niece].should == 'Li Plum'
|
|
199
|
-
@li_piao.niece.should == 'Li Plum'
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it "should provide setter methods for attributes" do
|
|
203
|
-
@li_piao.enhanced_by = 'He of the Towers of Light'
|
|
204
|
-
@li_piao.instance_variable_get('@attributes')[:enhanced_by].should == 'He of the Towers of Light'
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it "should respond to setter methods for attributes" do
|
|
208
|
-
@li_piao.should respond_to(:profession=)
|
|
209
|
-
@li_piao.should respond_to(:enhanced_by=)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it "should not respond to setter methods for attributes that don't exist" do
|
|
213
|
-
@li_piao.should_not respond_to(:god=)
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
it "should return false when query methods for attributes that don't exist are invoked" do
|
|
217
|
-
@li_piao.ooga?.should be_false
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
it "should provide query methods for attributes" do
|
|
221
|
-
li_piao = HumanBeing.new( :profession => 'Natural Magician', :enhanced_by => nil)
|
|
222
|
-
li_piao.profession?.should be_true
|
|
223
|
-
li_piao.enhanced_by?.should be_false
|
|
224
|
-
li_piao.gender?.should be_false
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
it "should respond to query methods for attributes" do
|
|
228
|
-
@li_piao.should respond_to(:profession?)
|
|
229
|
-
@li_piao.should respond_to(:enhanced_by?)
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
it "should not respond to query methods for attributes that don't exist" do
|
|
233
|
-
@li_piao.should_not respond_to(:theronic?)
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
it "should override methods which already exist on the container" do
|
|
237
|
-
@li_piao.id.should == 5
|
|
238
|
-
@li_piao.id = 6
|
|
239
|
-
@li_piao.id.should == 6
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
it "should provide getter and query methods to instance which has corresponding attribute" do
|
|
243
|
-
zotoh_zhaan = HumanBeing.new(:species => "Delvian")
|
|
244
|
-
zotoh_zhaan.species.should == "Delvian"
|
|
245
|
-
zotoh_zhaan.species?.should be_true
|
|
246
|
-
zotoh_zhaan.species = "Human"
|
|
247
|
-
lambda{@li_piao.species}.should raise_error(NoMethodError)
|
|
248
|
-
@li_piao.species?.should be_false
|
|
249
|
-
@li_piao.should_not respond_to(:species=)
|
|
250
|
-
@li_piao.methods.grep(/:species=/).should be_empty
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
11
|
-
|
|
12
|
-
module Wrest::Components
|
|
13
|
-
describe Mutators::Base do
|
|
14
|
-
it "should raise an exception if mutate is invoked without do_mutate being implemented in a subclass" do
|
|
15
|
-
lambda{ Class.new(Mutators::Base).new.mutate([]) }.should raise_error(Wrest::Exceptions::MethodNotOverridden)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should ensure that the next mutator is invoked for a subclass" do
|
|
19
|
-
next_mutator = mock('Mutator')
|
|
20
|
-
mutator = Mutators::CamelToSnakeCase.new(next_mutator)
|
|
21
|
-
|
|
22
|
-
next_mutator.should_receive(:mutate).with(['a', 1]).and_return([:a, '1'])
|
|
23
|
-
|
|
24
|
-
mutator.mutate(['a', 1]).should == [:a, '1']
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "should know how to chain mutators recursively" do
|
|
28
|
-
mutator = Mutators::XmlSimpleTypeCaster.new(Mutators::CamelToSnakeCase.new)
|
|
29
|
-
mutator.mutate(
|
|
30
|
-
["Result", [{
|
|
31
|
-
"Publish-Date"=>["1240326000"],
|
|
32
|
-
"News-Source"=>[{"Online" => ["PC via News"], "Unique-Id" => [{"type"=>"integer", "content"=>"1"}]}]
|
|
33
|
-
}]]
|
|
34
|
-
).should == ["result", {"publish_date" => "1240326000", "news_source" => {"online"=>"PC via News", "unique_id"=>1}}]
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should register all subclasses in the registry" do
|
|
38
|
-
class SomeMutator < Mutators::Base; end
|
|
39
|
-
Mutators::REGISTRY[:some_mutator].should == SomeMutator
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
11
|
-
|
|
12
|
-
module Wrest::Components
|
|
13
|
-
describe Mutators::CamelToSnakeCase do
|
|
14
|
-
before(:each) do
|
|
15
|
-
@mutator = Mutators::CamelToSnakeCase.new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should underscore the key in a tuple" do
|
|
19
|
-
@mutator.mutate(["universe-id", "1"]).should == ["universe_id", "1"]
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
11
|
-
|
|
12
|
-
module Wrest::Components
|
|
13
|
-
describe Mutators::XmlMiniTypeCaster do
|
|
14
|
-
before(:each) do
|
|
15
|
-
@mutator = Mutators::XmlMiniTypeCaster.new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# {"lead-bottle"=>{"name"=>{"__content__"=>"Wooz"}, "universe-id"=>{"type"=>"integer", "nil"=>"true"}, "id"=>{"__content__"=>"1", "type"=>"integer"}}}
|
|
19
|
-
|
|
20
|
-
it "should typecast a nil value in a tuple" do
|
|
21
|
-
@mutator.mutate(
|
|
22
|
-
["universe-id", {"type"=>"integer", "nil"=>"true"}]
|
|
23
|
-
).should == ["universe-id", nil]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should leave a string value in a tuple unchanged" do
|
|
27
|
-
@mutator.mutate(
|
|
28
|
-
["name", {"__content__" => "Wooz"}]
|
|
29
|
-
).should == ["name", "Wooz"]
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should cast an integer value in a tuple" do
|
|
33
|
-
@mutator.mutate(
|
|
34
|
-
["id", {"type"=>"integer", "__content__"=>"1"}]
|
|
35
|
-
).should == ["id", 1]
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should step into a value if it is a hash" do
|
|
39
|
-
@mutator.mutate(
|
|
40
|
-
["ResultSet", {
|
|
41
|
-
"firstResultPosition"=>"1", "totalResultsReturned"=>"1",
|
|
42
|
-
"xsi:schemaLocation"=>"urn:ooga:on http://api.search.ooga.com/NewsSearchService/V1/NewsSearchResponse.xsd",
|
|
43
|
-
"totalResultsAvailable"=>"23287",
|
|
44
|
-
"Result"=>{
|
|
45
|
-
"UniqueId"=>{"__content__"=>"1", "type" => "integer"},
|
|
46
|
-
"PublishDate"=>{"__content__"=>"20090424", "type" => "date"},
|
|
47
|
-
"Language"=>{"__content__"=>"en"},
|
|
48
|
-
"Title"=>{"__content__"=>"Wootler: Wook focus should be Klingon, not India"},
|
|
49
|
-
"ClickUrls"=>[
|
|
50
|
-
{"One" => {"__content__"=>"http://news.ooga.com/s/ap/20090424/ap_on_go_ca_st_pe/us_us_wookieland_5"}},
|
|
51
|
-
{"Two" => {"__content__"=>"http://news.ooga.com/s/ap/20090424/ap_on_go_ca_st_pe/us_us_wookieland_6"}},
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
).should == ["ResultSet", {
|
|
58
|
-
"firstResultPosition"=>"1", "totalResultsReturned"=>"1",
|
|
59
|
-
"xsi:schemaLocation"=>"urn:ooga:on http://api.search.ooga.com/NewsSearchService/V1/NewsSearchResponse.xsd",
|
|
60
|
-
"totalResultsAvailable"=>"23287",
|
|
61
|
-
"Result"=>{
|
|
62
|
-
"UniqueId"=> 1,
|
|
63
|
-
"PublishDate"=>Date.parse("20090424"),
|
|
64
|
-
"Language"=>"en",
|
|
65
|
-
"Title"=>"Wootler: Wook focus should be Klingon, not India",
|
|
66
|
-
"ClickUrls"=>[
|
|
67
|
-
{"One" => "http://news.ooga.com/s/ap/20090424/ap_on_go_ca_st_pe/us_us_wookieland_5"},
|
|
68
|
-
{"Two" => "http://news.ooga.com/s/ap/20090424/ap_on_go_ca_st_pe/us_us_wookieland_6"},
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
11
|
-
|
|
12
|
-
module Wrest::Components
|
|
13
|
-
describe Mutators::XmlSimpleTypeCaster do
|
|
14
|
-
before(:each) do
|
|
15
|
-
@mutator = Mutators::XmlSimpleTypeCaster.new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# {"lead-bottle"=>[{"name"=>["Wooz"], "universe-id"=>[{"type"=>"integer", "nil"=>"true"}], "id"=>[{"type"=>"integer", "content"=>"1"}]}]}
|
|
19
|
-
|
|
20
|
-
it "should typecast a nil value in a tuple" do
|
|
21
|
-
@mutator.mutate(
|
|
22
|
-
["universe-id", [{"type"=>"integer", "nil"=>"true"}]]
|
|
23
|
-
).should == ["universe-id", nil]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should leave a string value in a tuple unchanged" do
|
|
27
|
-
@mutator.mutate(
|
|
28
|
-
["name", ["Wooz"]]
|
|
29
|
-
).should == ["name", "Wooz"]
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should cast an integer value in a tuple" do
|
|
33
|
-
@mutator.mutate(
|
|
34
|
-
["id", [{"type"=>"integer", "content"=>"1"}]]
|
|
35
|
-
).should == ["id", 1]
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should step into a value if it is a hash" do
|
|
39
|
-
@mutator.mutate(
|
|
40
|
-
["Result", [{
|
|
41
|
-
"PublishDate"=>["1240326000"],
|
|
42
|
-
"NewsSource"=>[{"Online" => ["PC via News"], "UniqueId" => [{"type"=>"integer", "content"=>"1"}]}]
|
|
43
|
-
}]]
|
|
44
|
-
).should == ["Result", {"PublishDate" => "1240326000", "NewsSource" => {"Online"=>"PC via News", "UniqueId"=>1}}]
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
11
|
-
|
|
12
|
-
module Wrest::Components
|
|
13
|
-
describe Mutators do
|
|
14
|
-
it "should know how to chain mutators without having to namespace them all" do
|
|
15
|
-
mutator = Mutators.chain(:xml_mini_type_caster, :xml_simple_type_caster, :camel_to_snake_case)
|
|
16
|
-
mutator.class.should == Mutators::XmlMiniTypeCaster
|
|
17
|
-
mutator.next_mutator.class.should == Mutators::XmlSimpleTypeCaster
|
|
18
|
-
mutator.next_mutator.next_mutator.class.should == Mutators::CamelToSnakeCase
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
2
|
-
|
|
3
|
-
module Wrest::Components::Translators
|
|
4
|
-
describe Xml do
|
|
5
|
-
it "should know how to convert xml to a hashmap" do
|
|
6
|
-
http_response = mock('Http Reponse')
|
|
7
|
-
http_response.should_receive(:body).and_return("<ooga><age>12</age></ooga>")
|
|
8
|
-
|
|
9
|
-
Xml.deserialise(http_response).should == {"ooga"=>{"age"=> "12"}}
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should know how to convert a hashmap to xml" do
|
|
13
|
-
Xml.serialise({"ooga"=>{"age" => "12"}}).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <ooga>\n <age>12</age>\n </ooga>\n</hash>\n"
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
11
|
-
|
|
12
|
-
module Wrest::Components
|
|
13
|
-
describe Translators do
|
|
14
|
-
it "should know how to raise an exception if the mime type doesn't exist" do
|
|
15
|
-
lambda{ Translators.lookup('weird/unknown')}.should raise_error(Wrest::Exceptions::UnsupportedContentType)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
11
|
-
|
|
12
|
-
describe Hash, 'conversions' do
|
|
13
|
-
it "should know how to build a mutated hash given a hash mutator" do
|
|
14
|
-
class StringToSymbolMutator < Wrest::Components::Mutators::Base
|
|
15
|
-
def mutate(pair)
|
|
16
|
-
[pair.first.to_sym, pair.last]
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
{'ooga' => 'booga'}.mutate_using(StringToSymbolMutator.new).should == {:ooga => 'booga'}
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
11
|
-
|
|
12
|
-
describe String, 'conversions' do
|
|
13
|
-
it "should know how to convert a string to a Wrest::Uri" do
|
|
14
|
-
'http://localhost:3000'.to_uri.should == Wrest::Uri.new('http://localhost:3000')
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should accept username and password as options" do
|
|
18
|
-
uri = 'http://localhost:3000'.to_uri(
|
|
19
|
-
:username => 'ooga',
|
|
20
|
-
:password => 'booga'
|
|
21
|
-
)
|
|
22
|
-
uri.username.should == 'ooga'
|
|
23
|
-
uri.password.should == 'booga'
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should strip leading spaces from a uri before building it" do
|
|
27
|
-
' http://localhost:3000'.to_uri.should == Wrest::Uri.new('http://localhost:3000')
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should strip trailing spaces from a uri before building it" do
|
|
31
|
-
'http://localhost:3000 '.to_uri.should == Wrest::Uri.new('http://localhost:3000')
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "should levae the original string unchanged after building a uri from it" do
|
|
35
|
-
url = ' http://localhost:3000 '
|
|
36
|
-
url.to_uri.should == Wrest::Uri.new('http://localhost:3000')
|
|
37
|
-
url.should == ' http://localhost:3000 '
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
-
|
|
3
|
-
unless RUBY_PLATFORM =~ /java/
|
|
4
|
-
module Wrest
|
|
5
|
-
describe Curl::Request do
|
|
6
|
-
before :all do
|
|
7
|
-
Wrest.use_curl
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "should raise an exception if an options is invoked" do
|
|
11
|
-
lambda{ 'http://localhost:3000/bottles'.to_uri.options }.should raise_error(Wrest::Exceptions::UnsupportedHttpVerb)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
after :all do
|
|
15
|
-
Wrest.use_native
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
-
|
|
3
|
-
unless RUBY_PLATFORM =~ /java/
|
|
4
|
-
module Wrest
|
|
5
|
-
describe Curl::Response do
|
|
6
|
-
describe 'Headers' do
|
|
7
|
-
it "should know how to retrieve content type irrespective of the casing" do
|
|
8
|
-
http_response = mock('Patron::Response')
|
|
9
|
-
http_response.stub!(:headers).and_return({'Content-type' => 'text/xml;charset=utf-8'})
|
|
10
|
-
response = Wrest::Curl::Response.new(http_response)
|
|
11
|
-
response.content_type.should == 'text/xml'
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
-
|
|
3
|
-
module Wrest
|
|
4
|
-
libraries = [Wrest::Native]
|
|
5
|
-
libraries << Wrest::Curl unless RUBY_PLATFORM =~ /java/
|
|
6
|
-
|
|
7
|
-
libraries.each do |library|
|
|
8
|
-
describe "For #{library}" do
|
|
9
|
-
describe 'Response' do
|
|
10
|
-
describe 'Headers' do
|
|
11
|
-
it "should know how to retrieve content type irrespective of the casing" do
|
|
12
|
-
http_response = mock('Response')
|
|
13
|
-
http_response.stub!(:headers).and_return({'Content-type' => 'application/xml'})
|
|
14
|
-
http_response.stub!(:code).and_return('200')
|
|
15
|
-
http_response.stub!(:content_type).and_return('application/xml')
|
|
16
|
-
|
|
17
|
-
response = library::Response.new(http_response)
|
|
18
|
-
response.content_type.should == 'application/xml'
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|