Crystalforce is a crystal shards for the Salesforce REST api.
Add this to your application's shard.yml
:
dependencies:
crystalforce:
github: msky026/crystalforce
require "crystalforce"
client = Crystalforce.new({
:username => "foo",
:password => "bar",
:security_token => "security_token",
:client_id => "client_id",
:client_secret => "client_secret"
})
You can connect to sandbox orgs by specifying a host. The default host is 'login.salesforce.com':
client = Crystalforce.new({:host => 'test.salesforce.com'})
By default, the shard defaults to using version 34.0 of the Salesforce API.
Some more recent API endpoints will not be available without moving to a more recent
version - if you're trying to use a method that is unavailable with your API version,
Restforce will raise an APIVersionError
.
You can change the api_version
setting from the default either on a per-client basis:
client = Crystalforce.new({api_version: "36.0" # ...})
accounts = client.query("select Id, Something__c from Account where Id = 'someid'")
accounts = client.query_all("select Id, Something__c from Account where isDeleted = true")
query_all allows you to include results from your query that Salesforce hides in the default "query" method. These include soft-deleted records and archived records (e.g. Task and Event records which are usually archived automatically after they are a year old).
Only available in version 29.0 and later of the Salesforce API.
# Add a new account
client.create("Account", {:Name => "Foobar Inc.""})
# => '0016000000MRatd'
# Update the Account with `Id` '0016000000MRatd'
client.update("Account", "0016000000MRatd", {:Name => "Whizbang Corp"})
# => true
# Update the record with external `External__c` external ID set to '12'
client.upsert("Account", "External__c", "External__c" => 12, "Name" => "Foobar")
# => response.body["id"] or true
# Delete the Account with `Id` '0016000000MRatd'
client.destroy("Account", "0016000000MRatd")
# => true
If you are using TLS 1.0 or earlier version of the library, update the ssl library to the latest one and use the following option.
crystal run --link-flags "-L/path/to/openssl/lib/" <file>
- Fork it ( https://github.com/msky026/crystalforce/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- msky - creator, maintainer