kaiwren-wrest 0.0.4

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 (38) hide show
  1. data/README.rdoc +104 -0
  2. data/Rakefile +203 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/wrest +22 -0
  5. data/lib/wrest.rb +41 -0
  6. data/lib/wrest/core_ext/string.rb +5 -0
  7. data/lib/wrest/core_ext/string/conversions.rb +23 -0
  8. data/lib/wrest/exceptions.rb +1 -0
  9. data/lib/wrest/exceptions/unsupported_content_type_exception.rb +15 -0
  10. data/lib/wrest/mappers.rb +21 -0
  11. data/lib/wrest/mappers/attributes_container.rb +123 -0
  12. data/lib/wrest/mappers/resource.rb +17 -0
  13. data/lib/wrest/mappers/resource/base.rb +69 -0
  14. data/lib/wrest/mappers/resource/collection.rb +12 -0
  15. data/lib/wrest/mappers/simple_resource.rb +17 -0
  16. data/lib/wrest/response.rb +38 -0
  17. data/lib/wrest/translators.rb +26 -0
  18. data/lib/wrest/translators/content_types.rb +20 -0
  19. data/lib/wrest/translators/json.rb +21 -0
  20. data/lib/wrest/translators/typed_hash.rb +4 -0
  21. data/lib/wrest/translators/xml.rb +24 -0
  22. data/lib/wrest/uri.rb +74 -0
  23. data/lib/wrest/uri_template.rb +32 -0
  24. data/lib/wrest/version.rb +22 -0
  25. data/spec/custom_matchers/custom_matchers.rb +2 -0
  26. data/spec/rcov.opts +4 -0
  27. data/spec/spec.opts +6 -0
  28. data/spec/spec_helper.rb +18 -0
  29. data/spec/wrest/mappers/attributes_container_spec.rb +184 -0
  30. data/spec/wrest/mappers/resource/base_spec.rb +158 -0
  31. data/spec/wrest/mappers/simple_resource_spec.rb +7 -0
  32. data/spec/wrest/response_spec.rb +21 -0
  33. data/spec/wrest/translators/typed_hash_spec.rb +9 -0
  34. data/spec/wrest/translators/xml_spec.rb +12 -0
  35. data/spec/wrest/translators_spec.rb +9 -0
  36. data/spec/wrest/uri_spec.rb +131 -0
  37. data/spec/wrest/uri_template_spec.rb +28 -0
  38. metadata +128 -0
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Wrest::Translators
4
+ describe TypedHash do
5
+ it "should description" do
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Wrest::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.call(http_response).should == {"ooga"=>[{"age"=>["12"]}]}
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Wrest
4
+ describe Translators do
5
+ it "should know how to raise an exception if the mime type doesn't exist" do
6
+ lambda{ Translators.load('weird/unknown')}.should raise_error(UnsupportedContentTypeException)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,131 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Wrest
4
+ describe Uri do
5
+ def build_ok_response(body = '')
6
+ returning mock(Net::HTTPOK) do |response|
7
+ response.stub!(:code).and_return('200')
8
+ response.stub!(:message).and_return('OK')
9
+ response.stub!(:body).and_return(body)
10
+ end
11
+ end
12
+
13
+ it "should respond to the four http actions" do
14
+ uri = Uri.new('http://localhost')
15
+ uri.should respond_to(:get)
16
+ uri.should respond_to(:post)
17
+ uri.should respond_to(:put)
18
+ uri.should respond_to(:delete)
19
+ end
20
+
21
+ it "should know when it is https" do
22
+ Uri.new('https://localhost:3000').should be_https
23
+ end
24
+
25
+ it "should know when it is not https" do
26
+ Uri.new('http://localhost:3000').should_not be_https
27
+ end
28
+
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')
35
+ end
36
+
37
+
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
41
+ end
42
+
43
+ describe 'Get' do
44
+ it "should know how to get" do
45
+ uri = "http://localhost:3000/glassware".to_uri
46
+ uri.should_not be_https
47
+
48
+ http = mock(Net::HTTP)
49
+ Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
50
+
51
+ http.should_receive(:get).with('/glassware', {}).and_return(build_ok_response)
52
+
53
+ uri.get
54
+ end
55
+
56
+ it "should know how to get with parameters" do
57
+ uri = "http://localhost:3000/glassware".to_uri
58
+ uri.should_not be_https
59
+
60
+ http = mock(Net::HTTP)
61
+ 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)
64
+
65
+ uri.get({:owner => 'Kai', :type => 'bottle'}, :page => '2', :per_page => '5')
66
+ end
67
+
68
+ it "should know how to get with parameters but without any headers" do
69
+ uri = "http://localhost:3000/glassware".to_uri
70
+ uri.should_not be_https
71
+
72
+ http = mock(Net::HTTP)
73
+ Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
74
+
75
+ http.should_receive(:get).with('/glassware?owner=Kai&type=bottle', {}).and_return(build_ok_response)
76
+
77
+ uri.get(:owner => 'Kai', :type => 'bottle')
78
+ end
79
+ end
80
+
81
+ it "should know how to post" do
82
+ uri = "http://localhost:3000/glassware".to_uri
83
+ uri.should_not be_https
84
+
85
+ http = mock(Net::HTTP)
86
+ Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
87
+
88
+ http.should_receive(:post).with('/glassware', '<ooga>Booga</ooga>', {'page' => '2', 'per_page' => '5'}).and_return(build_ok_response)
89
+
90
+ uri.post '<ooga>Booga</ooga>', :page => '2', :per_page => '5'
91
+ end
92
+
93
+ it "should know how to put" do
94
+ uri = "http://localhost:3000/glassware".to_uri
95
+ uri.should_not be_https
96
+
97
+ http = mock(Net::HTTP)
98
+ Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
99
+
100
+ http.should_receive(:put).with('/glassware', '<ooga>Booga</ooga>', {'page' => '2', 'per_page' => '5'}).and_return(build_ok_response)
101
+
102
+ uri.put '<ooga>Booga</ooga>', :page => '2', :per_page => '5'
103
+ end
104
+
105
+ it "should know how to delete" do
106
+ uri = "http://localhost:3000/glassware".to_uri
107
+ uri.should_not be_https
108
+
109
+ http = mock(Net::HTTP)
110
+ Net::HTTP.should_receive(:new).with('localhost', 3000).and_return(http)
111
+
112
+ http.should_receive(:delete).with('/glassware', {'page' => '2', 'per_page' => '5'}).and_return(build_ok_response(nil))
113
+
114
+ uri.delete(:page => '2', :per_page => '5')
115
+ end
116
+
117
+ it "should not mutate state of the uri across requests" do
118
+ uri = "http://localhost:3000/glassware".to_uri
119
+ uri.should_not be_https
120
+
121
+ http = mock(Net::HTTP)
122
+ Net::HTTP.should_receive(:new).with('localhost', 3000).any_number_of_times.and_return(http)
123
+
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)
126
+
127
+ uri.get({:owner => 'Kai', :type => 'bottle'}, :page => '2', :per_page => '5')
128
+ uri.post '<ooga>Booga</ooga>', :page => '2', :per_page => '5'
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,28 @@
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
13
+ describe UriTemplate do
14
+ it "should not maintain a reference to the string it is initialized with" do
15
+ url_pattern = "http://localhost:3000/:resource/:id.:format"
16
+ template = UriTemplate.new(url_pattern)
17
+ url_pattern.gsub!(':', '!')
18
+ template.uri_pattern.should == "http://localhost:3000/:resource/:id.:format"
19
+ end
20
+
21
+ it "should know how to build a Wrest::Uri from the pattern given a set of replacement options" do
22
+ template = UriTemplate.new("http://localhost:3000/:resource/:id.:format")
23
+ template.to_uri(
24
+ :resource => 'shen_coins', :id => 5, :format => :json
25
+ ).should == "http://localhost:3000/shen_coins/5.json".to_uri
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kaiwren-wrest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Sidu Ponnappa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-18 00:00:00 -07:00
13
+ default_executable: wrest
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: xml-simple
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.11
44
+ version:
45
+ description: Wrest is a REST client library which allows you to quickly build object oriented wrappers around any web service. It has two main components - Wrest Core and Wrest::Resource.
46
+ email: ckponnappa@gmail.com
47
+ executables:
48
+ - wrest
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ files:
54
+ - README.rdoc
55
+ - Rakefile
56
+ - VERSION.yml
57
+ - bin/wrest
58
+ - lib/wrest.rb
59
+ - lib/wrest/core_ext/string.rb
60
+ - lib/wrest/core_ext/string/conversions.rb
61
+ - lib/wrest/exceptions.rb
62
+ - lib/wrest/exceptions/unsupported_content_type_exception.rb
63
+ - lib/wrest/mappers.rb
64
+ - lib/wrest/mappers/attributes_container.rb
65
+ - lib/wrest/mappers/resource.rb
66
+ - lib/wrest/mappers/resource/base.rb
67
+ - lib/wrest/mappers/resource/collection.rb
68
+ - lib/wrest/mappers/simple_resource.rb
69
+ - lib/wrest/response.rb
70
+ - lib/wrest/translators.rb
71
+ - lib/wrest/translators/content_types.rb
72
+ - lib/wrest/translators/json.rb
73
+ - lib/wrest/translators/typed_hash.rb
74
+ - lib/wrest/translators/xml.rb
75
+ - lib/wrest/uri.rb
76
+ - lib/wrest/uri_template.rb
77
+ - lib/wrest/version.rb
78
+ - spec/custom_matchers/custom_matchers.rb
79
+ - spec/rcov.opts
80
+ - spec/spec.opts
81
+ - spec/spec_helper.rb
82
+ - spec/wrest/mappers/attributes_container_spec.rb
83
+ - spec/wrest/mappers/resource/base_spec.rb
84
+ - spec/wrest/mappers/simple_resource_spec.rb
85
+ - spec/wrest/response_spec.rb
86
+ - spec/wrest/translators/typed_hash_spec.rb
87
+ - spec/wrest/translators/xml_spec.rb
88
+ - spec/wrest/translators_spec.rb
89
+ - spec/wrest/uri_spec.rb
90
+ - spec/wrest/uri_template_spec.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/kaiwren/wrest
93
+ post_install_message:
94
+ rdoc_options:
95
+ - --charset=UTF-8
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
109
+ version:
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.2.0
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: REST client library for Ruby.
117
+ test_files:
118
+ - spec/custom_matchers/custom_matchers.rb
119
+ - spec/spec_helper.rb
120
+ - spec/wrest/mappers/attributes_container_spec.rb
121
+ - spec/wrest/mappers/resource/base_spec.rb
122
+ - spec/wrest/mappers/simple_resource_spec.rb
123
+ - spec/wrest/response_spec.rb
124
+ - spec/wrest/translators/typed_hash_spec.rb
125
+ - spec/wrest/translators/xml_spec.rb
126
+ - spec/wrest/translators_spec.rb
127
+ - spec/wrest/uri_spec.rb
128
+ - spec/wrest/uri_template_spec.rb