gwt_rpc 0.0.0

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 (43) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +36 -0
  5. data/LICENSE +20 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.rdoc +19 -0
  8. data/Rakefile +52 -0
  9. data/VERSION +1 -0
  10. data/lib/gwt_rpc.rb +31 -0
  11. data/lib/gwt_rpc/base_extensions/array.rb +16 -0
  12. data/lib/gwt_rpc/base_extensions/boolean.rb +5 -0
  13. data/lib/gwt_rpc/base_extensions/date.rb +14 -0
  14. data/lib/gwt_rpc/base_extensions/fixnum.rb +20 -0
  15. data/lib/gwt_rpc/base_extensions/float.rb +22 -0
  16. data/lib/gwt_rpc/base_extensions/hash.rb +16 -0
  17. data/lib/gwt_rpc/base_extensions/multipart_string.rb +9 -0
  18. data/lib/gwt_rpc/base_extensions/string.rb +20 -0
  19. data/lib/gwt_rpc/client.rb +68 -0
  20. data/lib/gwt_rpc/gxt/hash.rb +24 -0
  21. data/lib/gwt_rpc/gxt/paginated_resultset.rb +16 -0
  22. data/lib/gwt_rpc/gxt/sort_dir.rb +15 -0
  23. data/lib/gwt_rpc/gxt/sort_info.rb +15 -0
  24. data/lib/gwt_rpc/procedure.rb +26 -0
  25. data/lib/gwt_rpc/request.rb +72 -0
  26. data/lib/gwt_rpc/response.rb +19 -0
  27. data/lib/gwt_rpc/response/reader.rb +75 -0
  28. data/spec/gwt_rpc/base_extensions/array_spec.rb +14 -0
  29. data/spec/gwt_rpc/base_extensions/boolean_spec.rb +16 -0
  30. data/spec/gwt_rpc/base_extensions/hash_spec.rb +14 -0
  31. data/spec/gwt_rpc/base_extensions/multipart_string_spec.rb +11 -0
  32. data/spec/gwt_rpc/base_extensions/string_spec.rb +18 -0
  33. data/spec/gwt_rpc/client_spec.rb +81 -0
  34. data/spec/gwt_rpc/gxt/hash_spec.rb +19 -0
  35. data/spec/gwt_rpc/gxt/paginated_resultset_spec.rb +14 -0
  36. data/spec/gwt_rpc/gxt/sort_dir_spec.rb +11 -0
  37. data/spec/gwt_rpc/gxt/sort_info_spec.rb +13 -0
  38. data/spec/gwt_rpc/procedure_spec.rb +30 -0
  39. data/spec/gwt_rpc/request_spec.rb +72 -0
  40. data/spec/gwt_rpc/response/reader_spec.rb +58 -0
  41. data/spec/gwt_rpc/response_spec.rb +39 -0
  42. data/spec/spec_helper.rb +12 -0
  43. metadata +285 -0
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe GwtRpc::Gxt::SortDir do
4
+ describe ".gwt_deserialize" do
5
+ it "should determine the direction" do
6
+ @client = GwtRpc::Client.new
7
+ @reader = GwtRpc::Response::Reader.new(@client, '[1,[],0,5]')
8
+ GwtRpc::Gxt::SortDir.gwt_deserialize(@reader).direction == 1
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe GwtRpc::Gxt::SortInfo do
4
+ describe ".gwt_deserialize" do
5
+ it "should determine it size and call read_object that many times" do
6
+ @client = GwtRpc::Client.new
7
+ @reader = GwtRpc::Response::Reader.new(@client, '[0,0,0,1,["com.extjs.gxt.ui.client.Style$SortDir/640452531"],0,5]')
8
+ sort_info = GwtRpc::Gxt::SortInfo.gwt_deserialize(@reader)
9
+ sort_info.field.should == nil
10
+ sort_info.direction.direction.should == 0
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe GwtRpc::Procedure do
4
+ required_options = {:namespace => "java.lang.Greeting", :method => "hello_world", :path => "/hello/world", :identifier => 'abc' }
5
+
6
+ describe ".new" do
7
+ required_options.keys.each do |key|
8
+ it "should require a #{key}" do
9
+ lambda{GwtRpc::Procedure.new(required_options.except(key))}.should raise_error
10
+ end
11
+ end
12
+
13
+ it "should succeed when all valid keys are provided" do
14
+ lambda{GwtRpc::Procedure.new(required_options)}.should_not raise_error
15
+ end
16
+
17
+ it "should only require a :path if a block is provided" do
18
+ lambda{ GwtRpc::Procedure.new(:path => '/hello/world'){ "abc" } }.should_not raise_error
19
+ end
20
+ end
21
+
22
+ describe ".call" do
23
+ it "should return a response" do
24
+ client = GwtRpc::Client.new
25
+ client.domain 'http://www.example.com'
26
+ Typhoeus::Request.should_receive(:post).and_return(Typhoeus::Response.new(:code => 200, :body => '//OK[2,1,["java.lang.String","Howdy"],0,5]'))
27
+ GwtRpc::Procedure.new(required_options).call(client).should == "Howdy"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe GwtRpc::Request do
4
+ before :each do
5
+ GwtRpc::Client.domain "example.com"
6
+ GwtRpc::Client.js_url "http://www.example.com/js"
7
+ @client = GwtRpc::Client.new
8
+ @procedure = GwtRpc::Procedure.new(:namespace => "foo.bar", :method => "hello_you", :path => '/hello', :identifier => "abc")
9
+ @parameters = ["Andrew"]
10
+ @request = GwtRpc::Request.new(@client, :procedure => @procedure, :parameters => @parameters)
11
+ end
12
+
13
+ describe ".url" do
14
+ it "should be based on the client's domain and the procedure's path" do
15
+ @request.url.should == "http://example.com/hello"
16
+ end
17
+ end
18
+
19
+ describe ".header" do
20
+ it "should be the GWT version and a flag" do
21
+ @request.header.should == [5,0]
22
+ end
23
+ end
24
+
25
+ # FIXME: this test knows too much about the implementation :-(
26
+ describe ".data" do
27
+ it "should be the js_url, the identifier, the namespace, the method, the number of parameters, the classes of the parameters, and the serialized parameter values" do
28
+ @request.data.should == [
29
+ @client.js_url,
30
+ @procedure.identifier,
31
+ @procedure.namespace,
32
+ @procedure.method,
33
+ @parameters.size,
34
+ @request.parameter_classes,
35
+ @request.parameter_values
36
+ ].flatten
37
+ end
38
+ end
39
+
40
+ describe ".body" do
41
+ it "should be the header, the size of the string table, the string table, then the payload, separated by pipes" do
42
+ @request.body.should == "5|0|6|http://www.example.com/js|abc|foo.bar|hello_you|java.lang.String|Andrew|1|2|3|4|1|5|6|"
43
+ end
44
+
45
+ it "should be the passed body if one is passed" do
46
+ request = GwtRpc::Request.new(@client, :procedure => @procedure, :body => "FOO BAR BAZ")
47
+ request.body.should == "FOO BAR BAZ"
48
+ end
49
+ end
50
+
51
+ describe ".parameter_classes" do
52
+ it "should return the java class names for each of the parameters passed" do
53
+ @client.class.should_receive(:ruby_class_to_java).with{|klass| klass.should == String}.and_return('java.lang.String')
54
+ @request.parameter_classes.should == ['java.lang.String']
55
+ end
56
+ end
57
+
58
+ describe ".stringtablize" do
59
+ it "should return the array unchanged if composed only of integers" do
60
+ string_table, vals = @request.stringtablize([1,2,3])
61
+ string_table.should == []
62
+ string_table.should be_empty
63
+ vals.should == [1,2,3]
64
+ end
65
+
66
+ it "should replace all strings with their location in the string table" do
67
+ string_table, vals = @request.stringtablize([1,"A","A","B",2])
68
+ string_table.should == ["A","B"]
69
+ vals.should == [1,1,1,2,2]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe GwtRpc::Response::Reader do
4
+ before :each do
5
+ client = GwtRpc::Client.new
6
+ @reader = GwtRpc::Response::Reader.new(client, '[4,2,3,2,2,1,["java.util.ArrayList/3821976829","java.lang.String/2004016611","Hello","World"],0,5]')
7
+ end
8
+
9
+ describe ".string_table" do
10
+ it "should be all the provided strings" do
11
+ @reader.string_table.should == ["java.util.ArrayList/3821976829","java.lang.String/2004016611","Hello","World"]
12
+ end
13
+ end
14
+
15
+ describe ".version" do
16
+ it "should be the last value" do
17
+ @reader.version.should == 5
18
+ end
19
+ end
20
+
21
+ describe ".data" do
22
+ it "should be the integer payload in reverse order" do
23
+ @reader.data.should == [1,2,2,3,2,4]
24
+ end
25
+ end
26
+
27
+ describe ".read_int" do
28
+ it "should read the first value off the data stack" do
29
+ @reader.read_int.should == 1
30
+ @reader.data == [2,2,3,2,4]
31
+ end
32
+ end
33
+
34
+ describe ".read_string" do
35
+ it "should read the first value off the stack with no parameters" do
36
+ @reader.read_string.should == "java.util.ArrayList/3821976829"
37
+ end
38
+
39
+ it "should read the specified string when value provided" do
40
+ @reader.read_string(1).should == "java.util.ArrayList/3821976829"
41
+ @reader.read_string(2).should == "java.lang.String/2004016611"
42
+ end
43
+
44
+ it "should error when reading a specified string beyond the maximum seen" do
45
+ lambda { @reader.read_string(4) }.should raise_error
46
+ end
47
+ end
48
+
49
+ describe ".read_object" do
50
+ it "should call .gwt_deserialize on the appropriate class" do
51
+ Array.should_receive(:gwt_deserialize)
52
+ @reader.read_object
53
+ end
54
+ it "should return the extracted data structure" do
55
+ @reader.read_object.should == ["Hello", "World"]
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe GwtRpc::Response do
4
+ before :each do
5
+ @client = GwtRpc::Client.new
6
+ end
7
+
8
+ describe ".new" do
9
+ it "should return a response object when everything is ok" do
10
+ response = Typhoeus::Response.new(:code => 200, :body => "//OK[1,2,3,4]")
11
+ GwtRpc::Response.new(@client, response).should be_a(GwtRpc::Response)
12
+ end
13
+
14
+ it "should raise an error when the response is not a 200" do
15
+ response = Typhoeus::Response.new(:code => 500)
16
+ lambda { GwtRpc::Response.new(@client, response) }.should raise_error GwtRpc::Error::ServerError
17
+ end
18
+
19
+ it "should raise an error when there is no response" do
20
+ response = Typhoeus::Response.new(:code => 0)
21
+ lambda { GwtRpc::Response.new(@client, response) }.should raise_error GwtRpc::Error::NoResponse
22
+ end
23
+
24
+ it "should raise an error when the response body does not begin with //OK" do
25
+ response = Typhoeus::Response.new(:code => 200, :body => "//ERR")
26
+ lambda { GwtRpc::Response.new(@client, response) }.should raise_error GwtRpc::Error::ServerError
27
+ end
28
+ end
29
+
30
+ # describe ".content" do
31
+ # it "should call GwtRpc::ResponseReader" do
32
+ # response = Typhoeus::Response.new(:code => 200, :body => "//OK[1,2,3,4]")
33
+ # @client = GwtRpc::Client.new
34
+ #
35
+ # GwtRpc::Response::Reader.should_receive(:new).with(@client,'[1,2,3,4]')
36
+ # GwtRpc::Response.new(nil, @client, response).content
37
+ # end
38
+ # end
39
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'gwt_rpc'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,285 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gwt_rpc
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Carpenter
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-02 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: typhoeus
24
+ type: :runtime
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: activesupport
38
+ type: :runtime
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ name: json
52
+ type: :runtime
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ name: rspec
66
+ type: :development
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">"
71
+ - !ruby/object:Gem::Version
72
+ hash: 15
73
+ segments:
74
+ - 2
75
+ - 0
76
+ - 0
77
+ version: 2.0.0
78
+ requirement: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ prerelease: false
81
+ name: bundler
82
+ type: :development
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ hash: 23
89
+ segments:
90
+ - 1
91
+ - 0
92
+ - 0
93
+ version: 1.0.0
94
+ requirement: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ prerelease: false
97
+ name: jeweler
98
+ type: :development
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ hash: 1
105
+ segments:
106
+ - 1
107
+ - 5
108
+ - 1
109
+ version: 1.5.1
110
+ requirement: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ prerelease: false
113
+ name: rcov
114
+ type: :development
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirement: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ prerelease: false
127
+ name: typhoeus
128
+ type: :runtime
129
+ version_requirements: &id008 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirement: *id008
139
+ - !ruby/object:Gem::Dependency
140
+ prerelease: false
141
+ name: active_support
142
+ type: :runtime
143
+ version_requirements: &id009 !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ requirement: *id009
153
+ - !ruby/object:Gem::Dependency
154
+ prerelease: false
155
+ name: json
156
+ type: :runtime
157
+ version_requirements: &id010 !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ requirement: *id010
167
+ - !ruby/object:Gem::Dependency
168
+ prerelease: false
169
+ name: rspec
170
+ type: :development
171
+ version_requirements: &id011 !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ">"
175
+ - !ruby/object:Gem::Version
176
+ hash: 25
177
+ segments:
178
+ - 1
179
+ - 2
180
+ - 3
181
+ version: 1.2.3
182
+ requirement: *id011
183
+ description: Spider Google Web Toolkit sites using ruby
184
+ email: andrew.main@gmail.com
185
+ executables: []
186
+
187
+ extensions: []
188
+
189
+ extra_rdoc_files:
190
+ - LICENSE
191
+ - LICENSE.txt
192
+ - README.rdoc
193
+ files:
194
+ - .document
195
+ - .rspec
196
+ - Gemfile
197
+ - Gemfile.lock
198
+ - LICENSE
199
+ - LICENSE.txt
200
+ - README.rdoc
201
+ - Rakefile
202
+ - VERSION
203
+ - lib/gwt_rpc.rb
204
+ - lib/gwt_rpc/base_extensions/array.rb
205
+ - lib/gwt_rpc/base_extensions/boolean.rb
206
+ - lib/gwt_rpc/base_extensions/date.rb
207
+ - lib/gwt_rpc/base_extensions/fixnum.rb
208
+ - lib/gwt_rpc/base_extensions/float.rb
209
+ - lib/gwt_rpc/base_extensions/hash.rb
210
+ - lib/gwt_rpc/base_extensions/multipart_string.rb
211
+ - lib/gwt_rpc/base_extensions/string.rb
212
+ - lib/gwt_rpc/client.rb
213
+ - lib/gwt_rpc/gxt/hash.rb
214
+ - lib/gwt_rpc/gxt/paginated_resultset.rb
215
+ - lib/gwt_rpc/gxt/sort_dir.rb
216
+ - lib/gwt_rpc/gxt/sort_info.rb
217
+ - lib/gwt_rpc/procedure.rb
218
+ - lib/gwt_rpc/request.rb
219
+ - lib/gwt_rpc/response.rb
220
+ - lib/gwt_rpc/response/reader.rb
221
+ - spec/gwt_rpc/base_extensions/array_spec.rb
222
+ - spec/gwt_rpc/base_extensions/boolean_spec.rb
223
+ - spec/gwt_rpc/base_extensions/hash_spec.rb
224
+ - spec/gwt_rpc/base_extensions/multipart_string_spec.rb
225
+ - spec/gwt_rpc/base_extensions/string_spec.rb
226
+ - spec/gwt_rpc/client_spec.rb
227
+ - spec/gwt_rpc/gxt/hash_spec.rb
228
+ - spec/gwt_rpc/gxt/paginated_resultset_spec.rb
229
+ - spec/gwt_rpc/gxt/sort_dir_spec.rb
230
+ - spec/gwt_rpc/gxt/sort_info_spec.rb
231
+ - spec/gwt_rpc/procedure_spec.rb
232
+ - spec/gwt_rpc/request_spec.rb
233
+ - spec/gwt_rpc/response/reader_spec.rb
234
+ - spec/gwt_rpc/response_spec.rb
235
+ - spec/spec_helper.rb
236
+ has_rdoc: true
237
+ homepage: http://github.com/andrewcarpenter/gwt_rpc
238
+ licenses:
239
+ - MIT
240
+ post_install_message:
241
+ rdoc_options: []
242
+
243
+ require_paths:
244
+ - lib
245
+ required_ruby_version: !ruby/object:Gem::Requirement
246
+ none: false
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ hash: 3
251
+ segments:
252
+ - 0
253
+ version: "0"
254
+ required_rubygems_version: !ruby/object:Gem::Requirement
255
+ none: false
256
+ requirements:
257
+ - - ">="
258
+ - !ruby/object:Gem::Version
259
+ hash: 3
260
+ segments:
261
+ - 0
262
+ version: "0"
263
+ requirements: []
264
+
265
+ rubyforge_project:
266
+ rubygems_version: 1.4.2
267
+ signing_key:
268
+ specification_version: 3
269
+ summary: Ruby Google Web Toolkit client
270
+ test_files:
271
+ - spec/gwt_rpc/base_extensions/array_spec.rb
272
+ - spec/gwt_rpc/base_extensions/boolean_spec.rb
273
+ - spec/gwt_rpc/base_extensions/hash_spec.rb
274
+ - spec/gwt_rpc/base_extensions/multipart_string_spec.rb
275
+ - spec/gwt_rpc/base_extensions/string_spec.rb
276
+ - spec/gwt_rpc/client_spec.rb
277
+ - spec/gwt_rpc/gxt/hash_spec.rb
278
+ - spec/gwt_rpc/gxt/paginated_resultset_spec.rb
279
+ - spec/gwt_rpc/gxt/sort_dir_spec.rb
280
+ - spec/gwt_rpc/gxt/sort_info_spec.rb
281
+ - spec/gwt_rpc/procedure_spec.rb
282
+ - spec/gwt_rpc/request_spec.rb
283
+ - spec/gwt_rpc/response/reader_spec.rb
284
+ - spec/gwt_rpc/response_spec.rb
285
+ - spec/spec_helper.rb