DataComApi
Ruby bindings for Data.com API ( Salesforce, ex Jigsaw ).
Installation
Add this line to your application's Gemfile:
gem 'data-com-api', '~> 0.1.1'
And then execute:
$ bundle
Or install it yourself as:
$ gem install data-com-api
Usage
First, create a DataComApi::Client instance with the following line:
client = DataComApi::Client.new('your-api-token')
You can then configure the client in the following way:
client.page_size = 100 # Value must be between 1 and 100
You can also get the totals API calls performed on the client with:
client.api_calls_count
Then, you can perform one of the following requests:
search_contactsearch_companycompany_contact_countcontacts
Every method matches the Data.com API call and support the same parameters. All requests are lazy,
which means that the request will be performed only once you actually perform an action on the response, like
requesting size, all, each and such (keep reading).
Client methods aka API responses
#search_contact and #search_company
The parameters accepted by this method are the keys of the DataComApi::QueryParameters. Notice that you can use the key specified as :from for a more ruby-like
syntax.
The returned object is a DataComApi::SearchContact which is mostly a DataComApi::SearchBase instance with the following main methods:
sizewhich returns thetotalHitsfield from the response (it will perform a request only if none performed)allwhich returns an array containing all records that can be fetched (be careful, can be memory hungry). Will handle paging by itselfeachwhich yields each record that can be obtained with the request, less memory hungry than previous request. Will handle paging by itselfeach_with_indexsame as previous one but with indexat_offsetwhich get one page of records (as an array) at specified offset
Every record returned will be a DataComApi::Contact or a DataComApi::Company instance.
#company_contact_count
The parameters accepted by this method are company_id (required) and the second one is DataComApi::QueryParameters which is useful only for the include_graveyard key
This method allows you to count contacts per company, the response has the following methods:
sizewhich returnstotalCountfrom API responseurlwhich returnsurlfrom API responselevelswhich returns an array of DataComApi::CompanyContactCount::Leveldepartmentswhich returns an array of DataComApi::CompanyContactCount::Departments
#contacts
The parameters accepted by this method are contact_ids (an array of Fixnum), username, password
which are required and the optional purchase_flag which defaults to false.
Be careful, this method may purchase records.
This response has the following methods:
sizewhich returnstotalHitsfrom API responseused_pointswhich returnspointsUsedfrom API responsepurchased_contactswhich returnsnumberOfContactsPurchasedfrom API responsepoint_balancewhich returnspointBalancefrom API responsecontactswhich returns an array of DataComApi::Contact
TODO
- Implement
partnerrequest - Implement
partner_contactsrequest - Implement
userrequest used to purchase points through API - Write some tests for
search_companywhich is exactly the same assearch_contact - Improve tests organization
- Test exceptions when performing API requests
Contributing
- Fork it
- 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 new Pull Request