kaiwren-wrest 0.0.6 → 0.0.8

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.
Files changed (51) hide show
  1. data/README.rdoc +83 -31
  2. data/Rakefile +29 -13
  3. data/VERSION.yml +1 -1
  4. data/examples/delicious.rb +58 -0
  5. data/examples/wow_realm_status.rb +57 -0
  6. data/lib/wrest.rb +11 -2
  7. data/lib/wrest/components.rb +1 -2
  8. data/lib/wrest/components/attributes_container.rb +34 -74
  9. data/lib/wrest/components/attributes_container/typecaster.rb +121 -0
  10. data/lib/wrest/components/mutators.rb +18 -1
  11. data/lib/wrest/components/mutators/base.rb +52 -39
  12. data/lib/wrest/components/mutators/camel_to_snake_case.rb +7 -5
  13. data/lib/wrest/components/mutators/xml_mini_type_caster.rb +43 -0
  14. data/lib/wrest/components/mutators/xml_simple_type_caster.rb +22 -20
  15. data/lib/wrest/components/translators.rb +20 -17
  16. data/lib/wrest/components/translators/content_types.rb +2 -2
  17. data/lib/wrest/components/translators/json.rb +11 -8
  18. data/lib/wrest/components/translators/xml.rb +9 -12
  19. data/lib/wrest/core_ext/hash/conversions.rb +1 -1
  20. data/lib/wrest/core_ext/string/conversions.rb +2 -2
  21. data/lib/wrest/http.rb +24 -0
  22. data/lib/wrest/http/delete.rb +23 -0
  23. data/lib/wrest/http/get.rb +23 -0
  24. data/lib/wrest/http/options.rb +23 -0
  25. data/lib/wrest/http/post.rb +23 -0
  26. data/lib/wrest/http/put.rb +23 -0
  27. data/lib/wrest/http/request.rb +48 -0
  28. data/lib/wrest/http/response.rb +44 -0
  29. data/lib/wrest/resource/base.rb +52 -25
  30. data/lib/wrest/resource/state.rb +6 -0
  31. data/lib/wrest/uri.rb +85 -29
  32. data/lib/wrest/uri_template.rb +18 -1
  33. data/lib/wrest/version.rb +1 -1
  34. data/spec/spec.opts +1 -1
  35. data/spec/spec_helper.rb +8 -1
  36. data/spec/wrest/components/attributes_container/typecaster_spec.rb +63 -0
  37. data/spec/wrest/components/attributes_container_spec.rb +17 -61
  38. data/spec/wrest/components/mutators/base_spec.rb +5 -1
  39. data/spec/wrest/components/mutators/xml_mini_type_caster_spec.rb +75 -0
  40. data/spec/wrest/components/mutators_spec.rb +21 -0
  41. data/spec/wrest/components/translators/xml_spec.rb +1 -1
  42. data/spec/wrest/components/translators_spec.rb +9 -0
  43. data/spec/wrest/core_ext/string/conversions_spec.rb +9 -0
  44. data/spec/wrest/http/request_spec.rb +22 -0
  45. data/spec/wrest/{response_spec.rb → http/response_spec.rb} +4 -4
  46. data/spec/wrest/resource/base_spec.rb +126 -11
  47. data/spec/wrest/uri_spec.rb +124 -20
  48. data/spec/wrest/uri_template_spec.rb +11 -1
  49. metadata +33 -20
  50. data/lib/wrest/components/typecast_helpers.rb +0 -41
  51. data/lib/wrest/response.rb +0 -38
@@ -5,11 +5,12 @@ class Glassware < Wrest::Resource::Base
5
5
  end
6
6
 
7
7
  class BottledUniverse < Glassware
8
- set_host "http://localhost:3001"
8
+ set_host "http://localhost:3001"
9
+ set_default_format :xml
9
10
  end
10
11
 
11
12
  module Wrest
12
- describe Resource::Base do
13
+ describe Wrest::Resource::Base do
13
14
  it "should not affect other classes when setting up its macros" do
14
15
  Class.should_not respond_to(:host=)
15
16
  Object.should_not respond_to(:host=)
@@ -23,21 +24,80 @@ module Wrest
23
24
  before(:each) do
24
25
  @BottledUniverse = Class.new(Resource::Base)
25
26
  @BottledUniverse.class_eval do
26
- set_resource_name 'BottledUniverse'
27
+ set_resource_name 'BottledUniverse'
28
+ end
29
+ end
30
+
31
+ describe 'equality' do
32
+ it "should be equal if it is the same instance" do
33
+ universe = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
34
+ (universe == universe).should be_true
35
+ end
36
+
37
+ it "should be equal if it has the same state" do
38
+ (
39
+ @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1) == @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
40
+ ).should be_true
41
+ end
42
+
43
+ it "should not be equal to nil" do
44
+ (@BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1) == nil).should be_false
45
+ end
46
+
47
+ it "should not be equal if it is not the same class" do
48
+ (
49
+ @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1) == Glassware.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
50
+ ).should be_false
51
+ end
52
+
53
+ it "should not be equal if it is has a different state" do
54
+ (
55
+ @BottledUniverse.new(:universe_id=>3, :name=>"Wooz", :id=>1) == @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
56
+ ).should be_false
57
+ end
58
+
59
+ it "should be symmetric" do
60
+ universe_one = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
61
+ universe_two = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
62
+ (universe_one == universe_one).should be_true
63
+ (universe_two == universe_two).should be_true
64
+ end
65
+
66
+ it "should be transitive" do
67
+ universe_one = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
68
+ universe_two = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
69
+ universe_three = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
70
+ (universe_one == universe_two).should be_true
71
+ (universe_two == universe_three).should be_true
72
+ (universe_one == universe_three).should be_true
73
+ end
74
+
75
+ it "should ensure that the hashcode is a fixnum" do
76
+ @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1).hash.should be_kind_of(Fixnum)
77
+ end
78
+
79
+ it "should ensure that instances with the same ids have the same hashcode" do
80
+ universe_one = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
81
+ universe_two = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
82
+ universe_one.hash.should == universe_two.hash
83
+ end
84
+
85
+ it "should ensure that instances with different ids have the different hashcodes" do
86
+ universe_one = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
87
+ universe_two = @BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>2)
88
+ universe_one.hash.should_not == universe_two.hash
27
89
  end
28
90
  end
29
91
 
30
92
  it "should know its name as a resource by default" do
31
- BottledUniverse.resource_name.should == 'BottledUniverse'
93
+ BottledUniverse.resource_name.should == 'bottled_universe'
32
94
  end
33
95
 
34
96
  it "should allow its name as a resource to be configured for anonymous classes" do
35
- @BottledUniverse.resource_name.should == 'BottledUniverse'
97
+ @BottledUniverse.resource_name.should == 'bottled_universe'
36
98
  end
37
99
 
38
100
  it "should know how to create an instance using deserialised attributes" do
39
- # Json => {"lead_bottle"=>{"name"=>"Wooz", "id"=>1, "universe_id"=>nil}}
40
- # Xml => {"lead-bottle"=>[{"name"=>["Wooz"], "universe-id"=>[{"type"=>"integer", "nil"=>"true"}], "id"=>[{"type"=>"integer", "content"=>"1"}]}]}
41
101
  universe = @BottledUniverse.new "name"=>"Wooz", "id"=>'1', "universe_id"=>nil, 'owner_id'=>nil
42
102
  universe.name.should == "Wooz"
43
103
  universe.owner_id.should be_nil
@@ -69,8 +129,48 @@ module Wrest
69
129
  @BottledUniverse.host.should == "http://localhost:3000"
70
130
  end
71
131
 
72
- it "should know its resource path" do
73
- Glassware.resource_path.should == '/glasswares'
132
+ it "should know its resource collection name" do
133
+ Glassware.resource_collection_name.should == 'glasswares'
134
+ end
135
+
136
+ it "should know its uri template for find one" do
137
+ Glassware.find_one_uri_template.to_uri(
138
+ :host => 'http://localhost:3000',
139
+ :resource_collection_name => 'glasswares',
140
+ :id => 1,
141
+ :format => 'json'
142
+ ).should == 'http://localhost:3000/glasswares/1.json'.to_uri
143
+ end
144
+
145
+ it "should know how to serialise itself to xml" do
146
+ BottledUniverse.new(:name => 'Foo').to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bottled-universe>\n <name>Foo</name>\n</bottled-universe>\n"
147
+ end
148
+
149
+ describe 'finders' do
150
+ # Json =>
151
+ # body => {"lead_bottle": {"name": "Wooz", "id": 1, "universe_id": null}}
152
+ # hash => {"lead_bottle"=>{"name"=>"Wooz", "id"=>1, "universe_id"=>nil}}
153
+ # Xml =>
154
+ # body =>
155
+ # <?xml version="1.0" encoding="UTF-8"?>
156
+ # <lead-bottle>
157
+ # <id type="integer">1</id>
158
+ # <name>Wooz</name>
159
+ # <universe-id type="integer" nil="true"></universe-id>
160
+ # </lead-bottle>
161
+ # hash =>
162
+ # {"lead-bottle"=>{"name"=>{"__content__"=>"Wooz"}, "universe-id"=>{"type"=>"integer", "nil"=>"true"}, "id"=>{"__content__"=>"1", "type"=>"integer"}}}
163
+ # typecast =>
164
+ # {"lead_bottle"=>{"name"=>"Wooz", "id"=>1, "universe_id"=>nil}}
165
+ it "should know how to find a resource by id" do
166
+ uri = 'http://localhost:3001/bottled_universe/1.xml'.to_uri
167
+ Wrest::Uri.should_receive(:new).with('http://localhost:3001/bottled_universes/1.xml', {}).and_return(uri)
168
+ response = mock(Wrest::Http::Response)
169
+ uri.should_receive(:get).with(no_args).and_return(response)
170
+ response.should_receive(:deserialise).and_return({"bottled-universe"=>{"name"=>{"__content__"=>"Wooz"}, "universe-id"=>{"type"=>"integer", "nil"=>"true"}, "id"=>{"__content__"=>"1", "type"=>"integer"}}})
171
+
172
+ BottledUniverse.find(1).should == BottledUniverse.new(:universe_id=>nil, :name=>"Wooz", :id=>1)
173
+ end
74
174
  end
75
175
  end
76
176
 
@@ -80,8 +180,23 @@ module Wrest
80
180
  BottledUniverse.host.should == "http://localhost:3001"
81
181
  end
82
182
 
83
- it "should know its resource path when it is a subclass of a subclass" do
84
- BottledUniverse.resource_path.should == '/bottled_universes'
183
+ it "should know its resource collection name when it is a subclass of a subclass" do
184
+ BottledUniverse.resource_collection_name.should == 'bottled_universes'
185
+ end
186
+
187
+
188
+ it "should know how to create a new resource" do
189
+ uri = mock(Uri)
190
+ mock_http_response = mock(Net::HTTPResponse)
191
+ mock_http_response.stub!(:content_type).and_return('application/xml')
192
+ mock_http_response.stub!(:body).and_return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bottled-universe>\n <name>Woot</name>\n <id>1</id>\n </bottled-universe>\n")
193
+
194
+ Uri.should_receive(:new).with("http://localhost:3001/bottled_universes.xml", {}).and_return(uri)
195
+ uri.should_receive(:post).with(
196
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bottled-universe>\n <name>Woot</name>\n</bottled-universe>\n",
197
+ 'Content-Type' => 'application/xml'
198
+ ).and_return(Wrest::Http::Response.new(mock_http_response))
199
+ ware = BottledUniverse.create(:name => 'Woot')
85
200
  end
86
201
  end
87
202
 
@@ -1,7 +1,16 @@
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
+
1
10
  require File.dirname(__FILE__) + '/../spec_helper'
2
11
 
3
12
  module Wrest
4
- describe Uri do
13
+ describe Wrest::Uri do
5
14
  def build_ok_response(body = '')
6
15
  returning mock(Net::HTTPOK) do |response|
7
16
  response.stub!(:code).and_return('200')
@@ -26,18 +35,74 @@ module Wrest
26
35
  Uri.new('http://localhost:3000').should_not be_https
27
36
  end
28
37
 
29
- it "should understand equality" do
30
- Uri.new('https://localhost:3000/ooga').should_not == 'https://localhost:3000/ooga'
31
- Uri.new('https://localhost:3000/ooga').should_not == Uri.new('https://localhost:3000/booga')
32
- Uri.new('https://localhost:3000').should_not == Uri.new('https://localhost:3500')
33
- Uri.new('https://localhost:3000').should_not == Uri.new('http://localhost:3000')
34
- Uri.new('http://localhost:3000').should == Uri.new('http://localhost:3000')
38
+ it "should know how to build a new uri from an existing one by appending a path" do
39
+ Uri.new('http://localhost:3000')['/ooga/booga'].should == Uri.new('http://localhost:3000/ooga/booga')
35
40
  end
36
41
 
42
+ it "should know its full path" do
43
+ Uri.new('http://localhost:3000/ooga').full_path.should == '/ooga'
44
+ Uri.new('http://localhost:3000/ooga?foo=meh&bar=1').full_path.should == '/ooga?foo=meh&bar=1'
45
+ end
46
+
47
+ it "should know its host" do
48
+ Uri.new('http://localhost:3000/ooga').host.should == 'localhost'
49
+ end
50
+
51
+ it "should know its port" do
52
+ Uri.new('http://localhost:3000/ooga').port.should == 3000
53
+ Uri.new('http://localhost/ooga').port.should == 80
54
+ end
55
+
56
+ it "should include the username and password while building a new uri if no options are provided" do
57
+ Uri.new(
58
+ 'http://localhost:3000',
59
+ :username => 'foo',
60
+ :password => 'bar')['/ooga/booga'].should == Uri.new(
61
+ 'http://localhost:3000/ooga/booga',
62
+ :username => 'foo',
63
+ :password => 'bar')
64
+ end
37
65
 
38
- it "should have the same hash code if it is the same uri" do
39
- Uri.new('https://localhost:3000').hash.should == Uri.new('https://localhost:3000').hash
40
- Uri.new('https://localhost:3001').hash.should_not == Uri.new('https://localhost:3000').hash
66
+ it "should use the username and password provided while building a new uri if present" do
67
+ uri = Uri.new('http://localhost:3000', :username => 'foo', :password => 'bar')
68
+ uri.username.should == 'foo'
69
+ uri.password.should == 'bar'
70
+
71
+ extended_uri = uri['/ooga/booga', {:username => 'meh', :password => 'baz'}]
72
+ extended_uri.username.should == 'meh'
73
+ extended_uri.password.should == 'baz'
74
+ end
75
+
76
+ describe 'Equals' do
77
+ it "should understand equality" do
78
+ Uri.new('https://localhost:3000/ooga').should_not == nil
79
+ Uri.new('https://localhost:3000/ooga').should_not == 'https://localhost:3000/ooga'
80
+ Uri.new('https://localhost:3000/ooga').should_not == Uri.new('https://localhost:3000/booga')
81
+
82
+ Uri.new('https://ooga:booga@localhost:3000/ooga').should_not == Uri.new('https://foo:bar@localhost:3000/booga')
83
+ Uri.new('http://ooga:booga@localhost:3000/ooga').should_not == Uri.new('http://foo:bar@localhost:3000/booga')
84
+ Uri.new('http://localhost:3000/ooga').should_not == Uri.new('http://foo:bar@localhost:3000/booga')
85
+
86
+ Uri.new('https://localhost:3000').should_not == Uri.new('https://localhost:3500')
87
+ Uri.new('https://localhost:3000').should_not == Uri.new('http://localhost:3000')
88
+ Uri.new('http://localhost:3000', :username => 'ooga', :password => 'booga').should_not == Uri.new('http://ooga:booga@localhost:3000')
89
+
90
+ Uri.new('http://localhost:3000').should == Uri.new('http://localhost:3000')
91
+ Uri.new('http://localhost:3000', :username => 'ooga', :password => 'booga').should == Uri.new('http://localhost:3000', :username => 'ooga', :password => 'booga')
92
+ Uri.new('http://ooga:booga@localhost:3000').should == Uri.new('http://ooga:booga@localhost:3000')
93
+ end
94
+
95
+
96
+ it "should have the same hash code if it is the same uri" do
97
+ Uri.new('https://localhost:3000').hash.should == Uri.new('https://localhost:3000').hash
98
+ Uri.new('http://ooga:booga@localhost:3000').hash.should == Uri.new('http://ooga:booga@localhost:3000').hash
99
+ Uri.new('http://localhost:3000', :username => 'ooga', :password => 'booga').hash.should == Uri.new('http://localhost:3000', :username => 'ooga', :password => 'booga').hash
100
+
101
+ Uri.new('https://localhost:3001').hash.should_not == Uri.new('https://localhost:3000').hash
102
+ Uri.new('https://ooga:booga@localhost:3000').hash.should_not == Uri.new('https://localhost:3000').hash
103
+ Uri.new('https://localhost:3000', :username => 'ooga', :password => 'booga').hash.should_not == Uri.new('https://localhost:3000').hash
104
+ Uri.new('https://localhost:3000', :username => 'ooga', :password => 'booga').hash.should_not == Uri.new('http://localhost:3000', :username => 'foo', :password => 'bar').hash
105
+ end
41
106
  end
42
107
 
43
108
  describe 'Get' do
@@ -48,7 +113,10 @@ module Wrest
48
113
  http = mock(Net::HTTP)
49
114
  Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
50
115
 
51
- http.should_receive(:get).with('/glassware', {}).and_return(build_ok_response)
116
+ request = Net::HTTP::Get.new('/glassware', {})
117
+ Net::HTTP::Get.should_receive(:new).with('/glassware', {}).and_return(request)
118
+
119
+ http.should_receive(:request).with(request, nil).and_return(build_ok_response)
52
120
 
53
121
  uri.get
54
122
  end
@@ -59,8 +127,11 @@ module Wrest
59
127
 
60
128
  http = mock(Net::HTTP)
61
129
  Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
62
-
63
- http.should_receive(:get).with('/glassware?owner=Kai&type=bottle', 'page' => '2', 'per_page' => '5').and_return(build_ok_response)
130
+
131
+ request = Net::HTTP::Get.new('/glassware?owner=Kai&type=bottle', {'page' => '2', 'per_page' => '5'})
132
+ Net::HTTP::Get.should_receive(:new).with('/glassware?owner=Kai&type=bottle', {'page' => '2', 'per_page' => '5'}).and_return(request)
133
+
134
+ http.should_receive(:request).with(request, nil).and_return(build_ok_response)
64
135
 
65
136
  uri.get({:owner => 'Kai', :type => 'bottle'}, :page => '2', :per_page => '5')
66
137
  end
@@ -72,12 +143,15 @@ module Wrest
72
143
  http = mock(Net::HTTP)
73
144
  Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
74
145
 
75
- http.should_receive(:get).with('/glassware?owner=Kai&type=bottle', {}).and_return(build_ok_response)
146
+ request = Net::HTTP::Get.new('/glassware?owner=Kai&type=bottle', {})
147
+ Net::HTTP::Get.should_receive(:new).with('/glassware?owner=Kai&type=bottle', {}).and_return(request)
148
+
149
+ http.should_receive(:request).with(request, nil).and_return(build_ok_response)
76
150
 
77
151
  uri.get(:owner => 'Kai', :type => 'bottle')
78
152
  end
79
153
  end
80
-
154
+
81
155
  it "should know how to post" do
82
156
  uri = "http://localhost:3000/glassware".to_uri
83
157
  uri.should_not be_https
@@ -85,7 +159,10 @@ module Wrest
85
159
  http = mock(Net::HTTP)
86
160
  Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
87
161
 
88
- http.should_receive(:post).with('/glassware', '<ooga>Booga</ooga>', {'page' => '2', 'per_page' => '5'}).and_return(build_ok_response)
162
+ request = Net::HTTP::Post.new('/glassware', {'page' => '2', 'per_page' => '5'})
163
+ Net::HTTP::Post.should_receive(:new).with('/glassware', {'page' => '2', 'per_page' => '5'}).and_return(request)
164
+
165
+ http.should_receive(:request).with(request, '<ooga>Booga</ooga>').and_return(build_ok_response)
89
166
 
90
167
  uri.post '<ooga>Booga</ooga>', :page => '2', :per_page => '5'
91
168
  end
@@ -96,8 +173,11 @@ module Wrest
96
173
 
97
174
  http = mock(Net::HTTP)
98
175
  Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
176
+
177
+ request = Net::HTTP::Put.new('/glassware', {'page' => '2', 'per_page' => '5'})
178
+ Net::HTTP::Put.should_receive(:new).with('/glassware', {'page' => '2', 'per_page' => '5'}).and_return(request)
99
179
 
100
- http.should_receive(:put).with('/glassware', '<ooga>Booga</ooga>', {'page' => '2', 'per_page' => '5'}).and_return(build_ok_response)
180
+ http.should_receive(:request).with(request, '<ooga>Booga</ooga>').and_return(build_ok_response)
101
181
 
102
182
  uri.put '<ooga>Booga</ooga>', :page => '2', :per_page => '5'
103
183
  end
@@ -109,11 +189,29 @@ module Wrest
109
189
  http = mock(Net::HTTP)
110
190
  Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
111
191
 
112
- http.should_receive(:delete).with('/glassware?owner=Kai&type=bottle', {'page' => '2', 'per_page' => '5'}).and_return(build_ok_response(nil))
192
+ request = Net::HTTP::Delete.new('/glassware?owner=Kai&type=bottle', {'page' => '2', 'per_page' => '5'})
193
+ Net::HTTP::Delete.should_receive(:new).with('/glassware?owner=Kai&type=bottle', {'page' => '2', 'per_page' => '5'}).and_return(request)
194
+
195
+ http.should_receive(:request).with(request, nil).and_return(build_ok_response(nil))
113
196
 
114
197
  uri.delete({:owner => 'Kai', :type => 'bottle'}, :page => '2', :per_page => '5')
115
198
  end
116
199
 
200
+ it "should know how to ask for options on a URI" do
201
+ uri = "http://localhost:3000/glassware".to_uri
202
+ uri.should_not be_https
203
+
204
+ http = mock(Net::HTTP)
205
+ Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
206
+
207
+ request = Net::HTTP::Options.new('/glassware')
208
+ Net::HTTP::Options.should_receive(:new).with('/glassware', {}).and_return(request)
209
+
210
+ http.should_receive(:request).with(request, nil).and_return(build_ok_response(nil))
211
+
212
+ uri.options
213
+ end
214
+
117
215
  it "should not mutate state of the uri across requests" do
118
216
  uri = "http://localhost:3000/glassware".to_uri
119
217
  uri.should_not be_https
@@ -121,8 +219,14 @@ module Wrest
121
219
  http = mock(Net::HTTP)
122
220
  Net::HTTP.should_receive(:new).with('localhost', 3000).any_number_of_times.and_return(http)
123
221
 
124
- http.should_receive(:get).with('/glassware?owner=Kai&type=bottle', 'page' => '2', 'per_page' => '5').and_return(build_ok_response)
125
- http.should_receive(:post).with('/glassware', '<ooga>Booga</ooga>', {'page' => '2', 'per_page' => '5'}).and_return(build_ok_response)
222
+ request_get = Net::HTTP::Get.new('/glassware?owner=Kai&type=bottle', {'page' => '2', 'per_page' => '5'})
223
+ Net::HTTP::Get.should_receive(:new).with('/glassware?owner=Kai&type=bottle', {'page' => '2', 'per_page' => '5'}).and_return(request_get)
224
+
225
+ request_post = Net::HTTP::Post.new('/glassware', {'page' => '2', 'per_page' => '5'})
226
+ Net::HTTP::Post.should_receive(:new).with('/glassware', {'page' => '2', 'per_page' => '5'}).and_return(request_post)
227
+
228
+ http.should_receive(:request).with(request_get, nil).and_return(build_ok_response)
229
+ http.should_receive(:request).with(request_post, '<ooga>Booga</ooga>').and_return(build_ok_response)
126
230
 
127
231
  uri.get({:owner => 'Kai', :type => 'bottle'}, :page => '2', :per_page => '5')
128
232
  uri.post '<ooga>Booga</ooga>', :page => '2', :per_page => '5'
@@ -10,7 +10,7 @@
10
10
  require File.dirname(__FILE__) + '/../spec_helper'
11
11
 
12
12
  module Wrest
13
- describe UriTemplate do
13
+ describe Wrest::UriTemplate do
14
14
  it "should not maintain a reference to the string it is initialized with" do
15
15
  url_pattern = "http://localhost:3000/:resource/:id.:format"
16
16
  template = UriTemplate.new(url_pattern)
@@ -24,5 +24,15 @@ module Wrest
24
24
  :resource => 'shen_coins', :id => 5, :format => :json
25
25
  ).should == "http://localhost:3000/shen_coins/5.json".to_uri
26
26
  end
27
+
28
+ it "should also handle username and password" do
29
+ template = UriTemplate.new("http://:user::password@coathangers.com/:resource/:id")
30
+ template.to_uri(
31
+ :user => 'kaiwren',
32
+ :password => 'fupuppies',
33
+ :resource => 'portal',
34
+ :id => '1'
35
+ ).should == "http://kaiwren:fupuppies@coathangers.com/portal/1".to_uri
36
+ end
27
37
  end
28
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaiwren-wrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidu Ponnappa
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-24 00:00:00 -07:00
13
- default_executable: wrest
12
+ date: 2009-08-13 00:00:00 -07:00
13
+ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -20,17 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.1.0
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: xml-simple
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.0.11
23
+ version: 2.3.2
34
24
  version:
35
25
  - !ruby/object:Gem::Dependency
36
26
  name: json
@@ -46,6 +36,7 @@ description: Wrest is a REST client library which allows you to quickly build ob
46
36
  email: ckponnappa@gmail.com
47
37
  executables:
48
38
  - wrest
39
+ - jwrest
49
40
  extensions: []
50
41
 
51
42
  extra_rdoc_files:
@@ -57,18 +48,21 @@ files:
57
48
  - bin/jwrest
58
49
  - bin/wrest
59
50
  - bin/wrest_shell.rb
51
+ - examples/delicious.rb
52
+ - examples/wow_realm_status.rb
60
53
  - lib/wrest.rb
61
54
  - lib/wrest/components.rb
62
55
  - lib/wrest/components/attributes_container.rb
56
+ - lib/wrest/components/attributes_container/typecaster.rb
63
57
  - lib/wrest/components/mutators.rb
64
58
  - lib/wrest/components/mutators/base.rb
65
59
  - lib/wrest/components/mutators/camel_to_snake_case.rb
60
+ - lib/wrest/components/mutators/xml_mini_type_caster.rb
66
61
  - lib/wrest/components/mutators/xml_simple_type_caster.rb
67
62
  - lib/wrest/components/translators.rb
68
63
  - lib/wrest/components/translators/content_types.rb
69
64
  - lib/wrest/components/translators/json.rb
70
65
  - lib/wrest/components/translators/xml.rb
71
- - lib/wrest/components/typecast_helpers.rb
72
66
  - lib/wrest/core_ext/hash.rb
73
67
  - lib/wrest/core_ext/hash/conversions.rb
74
68
  - lib/wrest/core_ext/string.rb
@@ -76,10 +70,18 @@ files:
76
70
  - lib/wrest/exceptions.rb
77
71
  - lib/wrest/exceptions/method_not_overridden_exception.rb
78
72
  - lib/wrest/exceptions/unsupported_content_type_exception.rb
73
+ - lib/wrest/http.rb
74
+ - lib/wrest/http/delete.rb
75
+ - lib/wrest/http/get.rb
76
+ - lib/wrest/http/options.rb
77
+ - lib/wrest/http/post.rb
78
+ - lib/wrest/http/put.rb
79
+ - lib/wrest/http/request.rb
80
+ - lib/wrest/http/response.rb
79
81
  - lib/wrest/resource.rb
80
82
  - lib/wrest/resource/base.rb
81
83
  - lib/wrest/resource/collection.rb
82
- - lib/wrest/response.rb
84
+ - lib/wrest/resource/state.rb
83
85
  - lib/wrest/uri.rb
84
86
  - lib/wrest/uri_template.rb
85
87
  - lib/wrest/version.rb
@@ -87,20 +89,25 @@ files:
87
89
  - spec/rcov.opts
88
90
  - spec/spec.opts
89
91
  - spec/spec_helper.rb
92
+ - spec/wrest/components/attributes_container/typecaster_spec.rb
90
93
  - spec/wrest/components/attributes_container_spec.rb
91
94
  - spec/wrest/components/mutators/base_spec.rb
92
95
  - spec/wrest/components/mutators/camel_to_snake_spec.rb
96
+ - spec/wrest/components/mutators/xml_mini_type_caster_spec.rb
93
97
  - spec/wrest/components/mutators/xml_simple_type_caster_spec.rb
98
+ - spec/wrest/components/mutators_spec.rb
94
99
  - spec/wrest/components/translators/xml_spec.rb
95
100
  - spec/wrest/components/translators_spec.rb
96
101
  - spec/wrest/core_ext/hash/conversions_spec.rb
97
102
  - spec/wrest/core_ext/string/conversions_spec.rb
103
+ - spec/wrest/http/request_spec.rb
104
+ - spec/wrest/http/response_spec.rb
98
105
  - spec/wrest/resource/base_spec.rb
99
- - spec/wrest/response_spec.rb
100
106
  - spec/wrest/uri_spec.rb
101
107
  - spec/wrest/uri_template_spec.rb
102
- has_rdoc: true
108
+ has_rdoc: false
103
109
  homepage: http://github.com/kaiwren/wrest
110
+ licenses:
104
111
  post_install_message:
105
112
  rdoc_options:
106
113
  - --charset=UTF-8
@@ -121,22 +128,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
128
  requirements: []
122
129
 
123
130
  rubyforge_project: wrest
124
- rubygems_version: 1.2.0
131
+ rubygems_version: 1.3.5
125
132
  signing_key:
126
133
  specification_version: 3
127
134
  summary: REST client library for Ruby.
128
135
  test_files:
129
136
  - spec/custom_matchers/custom_matchers.rb
130
137
  - spec/spec_helper.rb
138
+ - spec/wrest/components/attributes_container/typecaster_spec.rb
131
139
  - spec/wrest/components/attributes_container_spec.rb
132
140
  - spec/wrest/components/mutators/base_spec.rb
133
141
  - spec/wrest/components/mutators/camel_to_snake_spec.rb
142
+ - spec/wrest/components/mutators/xml_mini_type_caster_spec.rb
134
143
  - spec/wrest/components/mutators/xml_simple_type_caster_spec.rb
144
+ - spec/wrest/components/mutators_spec.rb
135
145
  - spec/wrest/components/translators/xml_spec.rb
136
146
  - spec/wrest/components/translators_spec.rb
137
147
  - spec/wrest/core_ext/hash/conversions_spec.rb
138
148
  - spec/wrest/core_ext/string/conversions_spec.rb
149
+ - spec/wrest/http/request_spec.rb
150
+ - spec/wrest/http/response_spec.rb
139
151
  - spec/wrest/resource/base_spec.rb
140
- - spec/wrest/response_spec.rb
141
152
  - spec/wrest/uri_spec.rb
142
153
  - spec/wrest/uri_template_spec.rb
154
+ - examples/delicious.rb
155
+ - examples/wow_realm_status.rb