Permalink
Browse files

support describe global method

  • Loading branch information...
1 parent 70dca1a commit 6c7b45669db998ba74ec1b6e6bdee30367d4d156 Ralph Callaway committed Sep 1, 2011
@@ -147,6 +147,16 @@ def materialize(classnames)
classes.length == 1 ? classes.first : classes
end
+ # Returns an Array of Hashes listing the properties for every type of _Sobject_ in the database. Raises SalesForceError if an error occurs.
+ def describe_global
+ result = http_get("/services/data/v#{self.version}/sobjects")
+ if result.is_a?(Net::HTTPOK)
+ JSON.parse(result.body)["sobjects"]
+ elsif result.is_a?(Net::HTTPBadRequest)
+ raise SalesForceError.new(result)
+ end
+ end
+
# Returns a description of the Sobject specified by _class_name_. The description includes all fields and their properties for the Sobject.
def describe_sobject(class_name)
result = http_get("/services/data/v#{self.version}/sobjects/#{class_name}/describe")
@@ -0,0 +1 @@
+[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
@@ -0,0 +1,31 @@
+{
+ "encoding" : "UTF-8",
+ "maxBatchSize" : 200,
+ "sobjects" : [ {
+ "name" : "Account",
+ "label" : "Account",
+ "custom" : false,
+ "keyPrefix" : "001",
+ "labelPlural" : "Accounts",
+ "layoutable" : true,
+ "activateable" : false,
+ "updateable" : true,
+ "urls" : {
+ "sobject" : "/services/data/v23.0/sobjects/Account",
+ "describe" : "/services/data/v23.0/sobjects/Account/describe",
+ "rowTemplate" : "/services/data/v23.0/sobjects/Account/{ID}"
+ },
+ "searchable" : true,
+ "createable" : true,
+ "customSetting" : false,
+ "deletable" : true,
+ "deprecatedAndHidden" : false,
+ "feedEnabled" : true,
+ "mergeable" : true,
+ "queryable" : true,
+ "replicateable" : true,
+ "retrieveable" : true,
+ "undeletable" : true,
+ "triggerable" : true
+ }]
+}
@@ -272,6 +272,33 @@
end
end
end
+
+ describe "#describe_global" do
+ context "with a successful request" do
+ before do
+ @response_body = File.read(File.join(File.dirname(__FILE__), "../fixtures/sobject/describe_global_success_response.json"))
+ stub_request(:get, "https://na1.salesforce.com/services/data/v23.0/sobjects").to_return(:body => @response_body, :status => 200)
+ end
+
+ it "returns an array of hashes listing the properties for available sobjects with a given version" do
+ @client.describe_global.first["name"].should == "Account"
+ @client.describe_global.first["createable"].should == true
+ end
+ end
+
+ context "with a failed request" do
+ before do
+ @response_body = File.read(File.join(File.dirname(__FILE__), "../fixtures/sobject/describe_global_error_response.json"))
+ stub_request(:get, "https://na1.salesforce.com/services/data/v23.0/sobjects").to_return(:body => @response_body, :status => 400)
+ end
+
+ it "raises a Databasedotcom::Sobject::SalesForceError" do
+ lambda {
+ @client.describe_global
+ }.should raise_error(Databasedotcom::SalesForceError)
+ end
+ end
+ end
describe "#materialize" do
before do

0 comments on commit 6c7b456

Please sign in to comment.