Class: GwtRpc::Request
- Inherits:
-
Object
- Object
- GwtRpc::Request
- Defined in:
- lib/gwt_rpc/request.rb
Instance Method Summary collapse
- #body ⇒ Object
- #call ⇒ Object
- #data ⇒ Object
- #header ⇒ Object
-
#initialize(client, options = {}) ⇒ Request
constructor
A new instance of Request.
- #parameter_classes ⇒ Object
- #parameter_values ⇒ Object
- #stringtablize(data) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(client, options = {}) ⇒ Request
Returns a new instance of Request.
2 3 4 5 6 7 |
# File 'lib/gwt_rpc/request.rb', line 2 def initialize(client, = {}) @client = client @procedure = [:procedure] @parameters = [:parameters] @body = [:body] end |
Instance Method Details
#body ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/gwt_rpc/request.rb', line 37 def body if @body body = @body else string_table, payload = stringtablize(data) body = (header + [string_table.size] + string_table + payload).join("|") + "|" end end |
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gwt_rpc/request.rb', line 9 def call @client.num_attempts.times do begin response = Typhoeus::Request.post(url, :body => body, :headers => { 'Content-Type' => "text/x-gwt-rpc; charset=utf-8", 'X-GWT-Module-Base' => @client.js_url, 'X-GWT-Permutation' => @client.gwt_permutation, }, :timeout => @client.timeout, :cache_timeout => 60) return GwtRpc::Response.new(@client, response).content rescue GwtRpc::Error::NoResponse # prevent random hiccups end end return nil end |
#data ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gwt_rpc/request.rb', line 46 def data [ @client.js_url, @procedure.identifier, @procedure.namespace, @procedure.method, @parameters.size, parameter_classes, parameter_values.flatten ].flatten end |
#header ⇒ Object
33 34 35 |
# File 'lib/gwt_rpc/request.rb', line 33 def header [5,0] end |
#parameter_classes ⇒ Object
58 59 60 |
# File 'lib/gwt_rpc/request.rb', line 58 def parameter_classes @parameters.map{|p| @client.class.ruby_class_to_java(p.class)} end |
#parameter_values ⇒ Object
62 63 64 |
# File 'lib/gwt_rpc/request.rb', line 62 def parameter_values @parameters.map{|p| p.gwt_serialize }.flatten end |
#stringtablize(data) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gwt_rpc/request.rb', line 66 def stringtablize(data) string_table = data.select{|v| v.class == String }.uniq vals = data.map do |v| if v.class == String string_table.index(v) + 1 else v end end return string_table, vals end |
#url ⇒ Object
29 30 31 |
# File 'lib/gwt_rpc/request.rb', line 29 def url 'http://' + @client.domain + @procedure.path end |