gwt_rpc 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'typhoeus'
6
+ gem 'activesupport'
7
+ gem 'json'
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "> 2.0.0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.5.1"
15
+ gem "rcov", ">= 0"
16
+ end
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.3)
5
+ diff-lcs (1.1.2)
6
+ git (1.2.5)
7
+ jeweler (1.5.2)
8
+ bundler (~> 1.0.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ json (1.5.1)
12
+ mime-types (1.16)
13
+ rake (0.8.7)
14
+ rcov (0.9.9)
15
+ rspec (2.4.0)
16
+ rspec-core (~> 2.4.0)
17
+ rspec-expectations (~> 2.4.0)
18
+ rspec-mocks (~> 2.4.0)
19
+ rspec-core (2.4.0)
20
+ rspec-expectations (2.4.0)
21
+ diff-lcs (~> 1.1.2)
22
+ rspec-mocks (2.4.0)
23
+ typhoeus (0.2.1)
24
+ mime-types
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ activesupport
31
+ bundler (~> 1.0.0)
32
+ jeweler (~> 1.5.1)
33
+ json
34
+ rcov
35
+ rspec (> 2.0.0)
36
+ typhoeus
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andrew Carpenter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andrew Carpenter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = gwt_rpc
2
+
3
+ Ruby GWT client. More details to come. Pre-alpha.
4
+
5
+ == Contributing to gwt_rpc
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Andrew Carpenter. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "gwt_rpc"
16
+ gem.homepage = "http://github.com/andrewcarpenter/gwt_rpc"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby Google Web Toolkit client}
19
+ gem.description = %Q{Spider Google Web Toolkit sites using ruby}
20
+ gem.email = "andrew.main@gmail.com"
21
+ gem.authors = ["Andrew Carpenter"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'typhoeus'
25
+ gem.add_runtime_dependency 'active_support'
26
+ gem.add_runtime_dependency 'json'
27
+ gem.add_development_dependency 'rspec', '> 1.2.3'
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rspec/core'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:spec) do |spec|
34
+ spec.pattern = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
38
+ spec.pattern = 'spec/**/*_spec.rb'
39
+ spec.rcov = true
40
+ end
41
+
42
+ task :default => :spec
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "gwt_rpc #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,31 @@
1
+ require 'rubygems' # TODO: remove me
2
+ require 'active_support/all' # TODO: support activesupport 2 or 3
3
+ require 'typhoeus'
4
+ require 'json'
5
+
6
+ module GwtRpc
7
+ module BaseExtensions
8
+ end
9
+ module Gxt
10
+ end
11
+ end
12
+
13
+ require "gwt_rpc/client"
14
+ require "gwt_rpc/procedure"
15
+ require "gwt_rpc/request"
16
+ require "gwt_rpc/response"
17
+ require "gwt_rpc/response/reader"
18
+
19
+ require "gwt_rpc/base_extensions/array"
20
+ require "gwt_rpc/base_extensions/boolean"
21
+ require "gwt_rpc/base_extensions/date"
22
+ require "gwt_rpc/base_extensions/float"
23
+ require "gwt_rpc/base_extensions/hash"
24
+ require "gwt_rpc/base_extensions/multipart_string"
25
+ require "gwt_rpc/base_extensions/fixnum"
26
+ require "gwt_rpc/base_extensions/string"
27
+
28
+ require "gwt_rpc/gxt/hash"
29
+ require "gwt_rpc/gxt/paginated_resultset"
30
+ require "gwt_rpc/gxt/sort_dir"
31
+ require "gwt_rpc/gxt/sort_info"
@@ -0,0 +1,16 @@
1
+ module GwtRpc::BaseExtensions::Array
2
+ def gwt_deserialize(reader)
3
+ size = reader.read_int
4
+
5
+ obj = new
6
+ size.times do |i|
7
+ # puts "starting array item #{i+1} of #{size}"
8
+ obj << reader.read_object
9
+ # puts "finished array item #{i+1} of #{size}"
10
+ end
11
+ # puts "!!! done with array of size #{size}"
12
+ obj
13
+ end
14
+ end
15
+
16
+ Array.send(:extend, GwtRpc::BaseExtensions::Array)
@@ -0,0 +1,5 @@
1
+ class GwtRpc::BaseExtensions::Boolean
2
+ def self.gwt_deserialize(reader)
3
+ reader.read_int == 1
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module GwtRpc::BaseExtensions::Date
2
+ def self.included(base)
3
+ base.send(:extend, ClassMethods)
4
+ end
5
+
6
+ module ClassMethods
7
+ def gwt_deserialize(reader)
8
+ reader.read_int
9
+ reader.read_int
10
+ end
11
+ end
12
+ end
13
+
14
+ Date.send(:include, GwtRpc::BaseExtensions::Date)
@@ -0,0 +1,20 @@
1
+ module GwtRpc::BaseExtensions::Fixnum
2
+ def self.included(base)
3
+ base.send(:extend, ClassMethods)
4
+ base.send(:include, InstanceMethods)
5
+ end
6
+
7
+ module InstanceMethods
8
+ def gwt_serialize
9
+ [self]
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def gwt_deserialize(reader)
15
+ reader.read_int
16
+ end
17
+ end
18
+ end
19
+
20
+ Fixnum.send(:include, GwtRpc::BaseExtensions::Fixnum)
@@ -0,0 +1,22 @@
1
+ module GwtRpc::BaseExtensions::Float
2
+ def self.included(base)
3
+ base.send(:extend, ClassMethods)
4
+ base.send(:include, InstanceMethods)
5
+ end
6
+
7
+ module InstanceMethods
8
+ def gwt_serialize
9
+ [self.to_s]
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def gwt_deserialize(reader)
15
+ ret = reader.read_int.to_f
16
+ reader.read_int # FIXME: ignoring this for now...
17
+ ret
18
+ end
19
+ end
20
+ end
21
+
22
+ Float.send(:include, GwtRpc::BaseExtensions::Float)
@@ -0,0 +1,16 @@
1
+ module GwtRpc::BaseExtensions::Hash
2
+ def gwt_deserialize(reader)
3
+ size = reader.read_int
4
+
5
+ obj = new
6
+ size.times do
7
+ key = reader.read_object
8
+ value = reader.read_object
9
+ obj[key] = value
10
+ end
11
+
12
+ obj
13
+ end
14
+ end
15
+
16
+ Hash.send(:extend, GwtRpc::BaseExtensions::Hash)
@@ -0,0 +1,9 @@
1
+ class GwtRpc::BaseExtensions::MultipartString
2
+ def self.gwt_deserialize(reader)
3
+ size = reader.read_int
4
+ a = []
5
+ size.times {a << reader.read_string }
6
+ a
7
+ end
8
+ end
9
+
@@ -0,0 +1,20 @@
1
+ module GwtRpc::BaseExtensions::String
2
+ def self.included(base)
3
+ base.send(:extend, ClassMethods)
4
+ base.send(:include, InstanceMethods)
5
+ end
6
+
7
+ module InstanceMethods
8
+ def gwt_serialize
9
+ [self]
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def gwt_deserialize(reader)
15
+ reader.read_string
16
+ end
17
+ end
18
+ end
19
+
20
+ String.send(:include, GwtRpc::BaseExtensions::String)
@@ -0,0 +1,68 @@
1
+ class GwtRpc::Client
2
+ def self.domain(domain = nil)
3
+ if domain
4
+ @domain = domain
5
+ end
6
+ @domain
7
+ end
8
+
9
+ def self.js_url(js_url = nil)
10
+ if js_url
11
+ @js_url = js_url
12
+ end
13
+ @js_url
14
+ end
15
+
16
+ delegate :domain, :js_url, :to => "self.class"
17
+
18
+ def self.map_classes(mapping)
19
+ @class_map ||= {}
20
+ mapping.each_pair do |java_class, ruby_class|
21
+ @class_map[java_class.to_s] = ruby_class.to_s
22
+ end
23
+ end
24
+
25
+ def self.ruby_class_to_java(klass)
26
+ @class_map.invert[klass.to_s]
27
+ end
28
+
29
+ def self.java_class_to_ruby(klass)
30
+ @class_map[klass.to_s]
31
+ end
32
+
33
+ def self.add_procedure(name, options, &block)
34
+ procedures[name] = GwtRpc::Procedure.new(options, &block)
35
+
36
+ define_method name do |*parameters|
37
+ self.class.procedures[name].call(self, *parameters)
38
+ end
39
+
40
+ define_method "#{name}_request" do |*parameters|
41
+ self.class.procedures[name].request(self, *parameters)
42
+ end
43
+ end
44
+
45
+ def self.procedures
46
+ @procedures ||= {}
47
+ end
48
+
49
+ def self.inherited(subclass)
50
+ subclass.domain self.domain
51
+ subclass.js_url self.js_url
52
+
53
+ subclass.map_classes @class_map
54
+ end
55
+
56
+ map_classes "java.lang.String" => "String",
57
+ "java.util.ArrayList" => "Array",
58
+ "java.util.Date" => "Date",
59
+ "java.lang.Long" => "Float",
60
+ "java.util.HashMap" => "Hash",
61
+ "java.lang.Integer" => "Fixnum",
62
+ "java.lang.Boolean" => "GwtRpc::BaseExtensions::Boolean",
63
+ "[Ljava.lang.String;" => "GwtRpc::BaseExtensions::MultipartString",
64
+ "com.extjs.gxt.ui.client.data.RpcMap" => "GwtRpc::Gxt::Hash",
65
+ "com.extjs.gxt.ui.client.Style$SortDir" => "GwtRpc::Gxt::SortDir",
66
+ "com.extjs.gxt.ui.client.data.SortInfo" => "GwtRpc::Gxt::SortInfo",
67
+ "com.extjs.gxt.ui.client.data.BasePagingLoadResult" => "GwtRpc::Gxt::PaginatedResultset"
68
+ end
@@ -0,0 +1,24 @@
1
+ class GwtRpc::Gxt::Hash < Hash
2
+ def gwt_serialize
3
+ ["com.extjs.gxt.ui.client.data.RpcMap/3441186752",
4
+ self.size
5
+ ] +
6
+ %w(modelInstanceBelongsTo documentType searchFields recordsPerPage openForComments queryString).map {|key|
7
+ val = self[key]
8
+ [key, val.gwt_serialize]
9
+ }.flatten
10
+ end
11
+
12
+ def self.gwt_deserialize(reader)
13
+ size = reader.read_int
14
+
15
+ obj = new
16
+ size.times do
17
+ key = reader.read_string
18
+ value = reader.read_object
19
+ obj[key] = value
20
+ end
21
+
22
+ obj
23
+ end
24
+ end