lib/databasedotcom/client.rb in databasedotcom-1.1.2 vs lib/databasedotcom/client.rb in databasedotcom-1.1.4

- old
+ new

@@ -179,19 +179,19 @@ # Returns a Collection of Sobjects of the class specified in the _soql_expr_, which is a valid SOQL[http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql.htm] expression. The objects will only be populated with the values of attributes specified in the query. # # client.query("SELECT Name FROM Account") #=> [#<Account @Id=nil, @Name="Foo", ...>, #<Account @Id=nil, @Name="Bar", ...> ...] def query(soql_expr) - result = http_get("/services/data/v#{self.version}/query?q=#{soql_expr}") + result = http_get("/services/data/v#{self.version}/query", :q => soql_expr) collection_from(result.body) end # Returns a Collection of Sobject instances form the results of the SOSL[http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sosl.htm] search. # # client.search("FIND {bar}") #=> [#<Account @Name="foobar", ...>, #<Account @Name="barfoo", ...> ...] def search(sosl_expr) - result = http_get("/services/data/v#{self.version}/search?q=#{sosl_expr}") + result = http_get("/services/data/v#{self.version}/search", :q => sosl_expr) collection_from(result.body) end # Used by Collection objects. Returns a Collection of Sobjects from the specified URL path that represents the next page of paginated results. def next_page(path) @@ -366,15 +366,19 @@ def encode_path_with_params(path, parameters={}) [URI.escape(path), encode_parameters(parameters)].reject{|el| el.empty?}.join('?') end def encode_parameters(parameters={}) - (parameters || {}).collect { |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join('&') + (parameters || {}).collect { |k, v| "#{uri_escape(k)}=#{uri_escape(v)}" }.join('&') end def log_request(path, options={}) base_url = options[:host] ? "https://#{options[:host]}" : self.instance_url puts "***** REQUEST: #{path.include?(':') ? path : URI.join(base_url, path)}#{options[:data] ? " => #{options[:data]}" : ''}" if self.debugging + end + + def uri_escape(str) + URI.escape(str.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end def log_response(result) puts "***** RESPONSE: #{result.class.name} -> #{result.body}" if self.debugging end