Module: Salesforce::Connection::RestApi::ClassMethods
- Defined in:
- lib/salesforce/connection/rest_api.rb
Instance Method Summary collapse
- #create(object_name, fields) ⇒ Object
- #destroy(object_name, object_id) ⇒ Object
- #fields(object_name) ⇒ Object
- #find_object_by_id(object_name, object_id, fields) ⇒ Object
- #soql(query_string) ⇒ Object
- #supported_objects ⇒ Object
- #update(object_name, object_id, fields) ⇒ Object
Instance Method Details
#create(object_name, fields) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/salesforce/connection/rest_api.rb', line 36 def create(object_name, fields) result = post("sobjects/#{object_name}.json", fields.to_json, :format => :json) if result["success"] return result["id"] else raise RecordInvalid.new(object_name, result["errors"]) end end |
#destroy(object_name, object_id) ⇒ Object
45 46 47 |
# File 'lib/salesforce/connection/rest_api.rb', line 45 def destroy(object_name, object_id) delete("sobjects/#{object_name}/#{object_id}") end |
#fields(object_name) ⇒ Object
11 12 13 14 |
# File 'lib/salesforce/connection/rest_api.rb', line 11 def fields(object_name) raise ObjectNotSupported.new(object_name) unless supported_objects.include?(object_name) get("sobjects/#{object_name}/describe.json", :format => :json)["fields"] end |
#find_object_by_id(object_name, object_id, fields) ⇒ Object
16 17 18 |
# File 'lib/salesforce/connection/rest_api.rb', line 16 def find_object_by_id(object_name, object_id, fields) get("sobjects/#{object_name}/#{object_id}.json?fields=#{URI.encode(fields)}", :format => :json) end |
#soql(query_string) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/salesforce/connection/rest_api.rb', line 20 def soql(query_string) records = [] response = get "query.json?q=#{CGI.escape(query_string)}", :format => :json records += response["records"].each { |r| r.delete("attributes")} while(!response["done"]) response = get((response["nextRecordsUrl"] + '.json'), :format => :json) records += response["records"].each { |r| r.delete("attributes")} end records end |
#supported_objects ⇒ Object
7 8 9 |
# File 'lib/salesforce/connection/rest_api.rb', line 7 def supported_objects get("sobjects.json", :format => :json)["sobjects"].map { |hash| hash["name"] } end |
#update(object_name, object_id, fields) ⇒ Object
31 32 33 34 |
# File 'lib/salesforce/connection/rest_api.rb', line 31 def update(object_name, object_id, fields) response = patch("sobjects/#{object_name}/#{object_id}.json", fields.to_json, :format => :json) response.code == 204 end |