Sha256: 7b7e4d949eca63ef93418f6ca3384f7acd50581bf012aa0a28ab85d19d9d53ab

Contents?: true

Size: 1.73 KB

Versions: 21

Compression:

Stored size: 1.73 KB

Contents

module Salesforce
  module Connection
    module RestApi
      extend ActiveSupport::Concern
      module ClassMethods

        def supported_objects
          get("sobjects.json", :format => :json)["sobjects"].map { |hash| hash["name"] }
        end

        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

        def find_object_by_id(object_name, object_id, fields)
          get("sobjects/#{object_name}/#{object_id}.json?fields=#{URI.encode(fields)}", :format => :json)
        end

        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

        def update(object_name, object_id, fields)
          response = patch("sobjects/#{object_name}/#{object_id}.json", fields.to_json, :format => :json)
          response.code == 204
        end

        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

        def destroy(object_name, object_id)
          delete("sobjects/#{object_name}/#{object_id}")
        end
        
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
activeforce-5.0.0 lib/salesforce/connection/rest_api.rb
activeforce-1.10.5 lib/salesforce/connection/rest_api.rb
activeforce-1.10.4 lib/salesforce/connection/rest_api.rb
activeforce-4.0.0 lib/salesforce/connection/rest_api.rb
activeforce-1.10.3 lib/salesforce/connection/rest_api.rb
activeforce-3.1.0 lib/salesforce/connection/rest_api.rb
activeforce-1.10.2 lib/salesforce/connection/rest_api.rb
activeforce-3.0.0 lib/salesforce/connection/rest_api.rb
activeforce-2.1.1 lib/salesforce/connection/rest_api.rb
activeforce-1.10.1 lib/salesforce/connection/rest_api.rb
activeforce-2.1.0 lib/salesforce/connection/rest_api.rb
activeforce-1.10.0 lib/salesforce/connection/rest_api.rb
activeforce-2.0.1 lib/salesforce/connection/rest_api.rb
activeforce-2.0.0 lib/salesforce/connection/rest_api.rb
activeforce-1.9.1 lib/salesforce/connection/rest_api.rb
activeforce-1.9.0 lib/salesforce/connection/rest_api.rb
activeforce-1.8.0 lib/salesforce/connection/rest_api.rb
activeforce-1.7.1 lib/salesforce/connection/rest_api.rb
activeforce-1.7.0 lib/salesforce/connection/rest_api.rb
activeforce-1.6.0 lib/salesforce/connection/rest_api.rb