Class: SugarCRM::Request
- Inherits:
-
Object
- Object
- SugarCRM::Request
- Defined in:
- lib/sugarcrm/connection/request.rb
Instance Attribute Summary collapse
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#json ⇒ Object
Returns the value of attribute json.
-
#method ⇒ Object
Returns the value of attribute method.
-
#request ⇒ Object
Returns the value of attribute request.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #bytesize ⇒ Object
-
#convert_reserved_characters(string) ⇒ Object
A tiny helper for converting reserved characters for html encoding.
- #escape(json) ⇒ Object
-
#initialize(url, method, json, debug = false) ⇒ Request
constructor
A new instance of Request.
- #length ⇒ Object
- #to_s ⇒ Object (also: #to_str)
-
#unescape ⇒ Object
TODO: Fix this so that it JSON.parse will consume it.
Constructor Details
#initialize(url, method, json, debug = false) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sugarcrm/connection/request.rb', line 8 def initialize(url, method, json, debug=false) @url = url @method = method @json = escape(json) @request = 'method=' << @method.to_s @request << '&input_type=JSON' @request << '&response_type=JSON' @request << '&rest_data=' << @json if debug puts "#{method}: Request:" puts json puts "\n" end self end |
Instance Attribute Details
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
6 7 8 |
# File 'lib/sugarcrm/connection/request.rb', line 6 def http_method @http_method end |
#json ⇒ Object
Returns the value of attribute json.
5 6 7 |
# File 'lib/sugarcrm/connection/request.rb', line 5 def json @json end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/sugarcrm/connection/request.rb', line 4 def method @method end |
#request ⇒ Object
Returns the value of attribute request.
2 3 4 |
# File 'lib/sugarcrm/connection/request.rb', line 2 def request @request end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/sugarcrm/connection/request.rb', line 3 def url @url end |
Instance Method Details
#bytesize ⇒ Object
38 39 40 |
# File 'lib/sugarcrm/connection/request.rb', line 38 def bytesize self.to_s.bytesize end |
#convert_reserved_characters(string) ⇒ Object
A tiny helper for converting reserved characters for html encoding
52 53 54 55 56 57 58 59 |
# File 'lib/sugarcrm/connection/request.rb', line 52 def convert_reserved_characters(string) string.gsub!(/"/, '\"') string.gsub!(/'/, '\'') string.gsub!(/&/, '\&') string.gsub!(/</, '\<') string.gsub!(/</, '\>') string end |
#escape(json) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/sugarcrm/connection/request.rb', line 24 def escape(json) # BUG: SugarCRM doesn't properly handle '"' inside of JSON for some reason. Let's unescape any html elements. j = convert_reserved_characters(json) # Now we escape the resulting string. j = CGI.escape(j) j end |
#length ⇒ Object
42 43 44 |
# File 'lib/sugarcrm/connection/request.rb', line 42 def length self.to_s.length end |
#to_s ⇒ Object Also known as: to_str
46 47 48 |
# File 'lib/sugarcrm/connection/request.rb', line 46 def to_s @request end |
#unescape ⇒ Object
TODO: Fix this so that it JSON.parse will consume it.
33 34 35 36 |
# File 'lib/sugarcrm/connection/request.rb', line 33 def unescape j = CGI.unescape(@json) j.gsub!(/\n/, '') end |