class DataComApi::Client
Constants
- BASE_OFFSET
- BASE_PAGE_SIZE
- ENV_NAME_TOKEN
- MAX_OFFSET
- MAX_PAGE_SIZE
- MIN_PAGE_SIZE
We start at 1, 0 is a special case
- SIZE_ONLY_PAGE_SIZE
- TIME_ZONE
Attributes
api_calls_count[R]
token[R]
Public Class Methods
new(api_token=nil)
click to toggle source
# File lib/data-com-api/client.rb, line 37 def initialize(api_token=nil) @token = api_token || ENV[ENV_NAME_TOKEN] @page_size = BASE_PAGE_SIZE @api_calls_count = 0 raise TokenFailError, 'No token set!' unless @token end
Public Instance Methods
company_contact_count(company_id, options={})
click to toggle source
# File lib/data-com-api/client.rb, line 71 def company_contact_count(company_id, options={}) Responses::CompanyContactCount.new(self, company_id, options) end
company_contact_count_raw(company_id, include_graveyard)
click to toggle source
Raw calls
# File lib/data-com-api/client.rb, line 87 def company_contact_count_raw(company_id, include_graveyard) params = QueryParameters.new( token: token, company_id: company_id, include_graveyard: include_graveyard ) response = self.class.get( ApiURI.company_contact_count(company_id), { query: params } ) increase_api_calls_count! response.body end
company_contact_count_raw_json(company_id, include_graveyard)
click to toggle source
JSON calls
# File lib/data-com-api/client.rb, line 190 def company_contact_count_raw_json(company_id, include_graveyard) json_or_raise company_contact_count_raw(company_id, include_graveyard) end
contacts(contact_ids, username, password, purchase_flag=false)
click to toggle source
# File lib/data-com-api/client.rb, line 75 def contacts(contact_ids, username, password, purchase_flag=false) Responses::Contacts.new( self, contact_ids, username, password, purchase_flag ) end
contacts_raw(contact_ids, username, password, purchase_flag=false)
click to toggle source
# File lib/data-com-api/client.rb, line 123 def contacts_raw(contact_ids, username, password, purchase_flag=false) raise ParamError, 'One contact required at least' unless contact_ids.size > 0 params = QueryParameters.new( token: token, username: username, password: password, purchase_flag: purchase_flag ) response = self.class.get( ApiURI.contacts(contact_ids), { query: params } ) increase_api_calls_count! response.body end
contacts_raw_json(contact_ids, username, password, purchase_flag=false)
click to toggle source
# File lib/data-com-api/client.rb, line 202 def contacts_raw_json(contact_ids, username, password, purchase_flag=false) json_or_raise contacts_raw( contact_ids, username, password, purchase_flag ) end
max_offset()
click to toggle source
# File lib/data-com-api/client.rb, line 29 def max_offset MAX_OFFSET end
page_size()
click to toggle source
# File lib/data-com-api/client.rb, line 45 def page_size @page_size end
page_size=(value)
click to toggle source
Page size = 0 returns objects count only (small request)
# File lib/data-com-api/client.rb, line 50 def page_size=(value) real_value = value.to_i if real_value < MIN_PAGE_SIZE || real_value > MAX_PAGE_SIZE raise ParamError, <<-eos page_size must be between #{ MIN_PAGE_SIZE } and #{ MAX_PAGE_SIZE }, received #{ real_value }" eos end @page_size = real_value end
partner_contacts_raw(contact_ids, end_org_id, end_user_id)
click to toggle source
# File lib/data-com-api/client.rb, line 142 def partner_contacts_raw(contact_ids, end_org_id, end_user_id) raise ParamError, 'One contact required at least' unless contact_ids.size > 0 params = QueryParameters.new( token: token, end_org_id: end_org_id, end_user_id: end_user_id ) response = self.class.get( ApiURI.partner_contacts(contact_ids), { query: params } ) increase_api_calls_count! response.body end
partner_contacts_raw_json(contact_ids, end_org_id, end_user_id)
click to toggle source
# File lib/data-com-api/client.rb, line 211 def partner_contacts_raw_json(contact_ids, end_org_id, end_user_id) json_or_raise partner_contacts_raw( contact_ids, end_org_id, end_user_id ) end
partner_raw()
click to toggle source
# File lib/data-com-api/client.rb, line 160 def partner_raw params = QueryParameters.new(token: token) response = self.class.get( ApiURI.partner, { query: params } ) increase_api_calls_count! response.body end
partner_raw_json()
click to toggle source
# File lib/data-com-api/client.rb, line 219 def partner_raw_json json_or_raise partner_raw end
search_company(options={})
click to toggle source
# File lib/data-com-api/client.rb, line 67 def search_company(options={}) Responses::SearchCompany.new(self, options) end
search_company_raw(options={})
click to toggle source
# File lib/data-com-api/client.rb, line 113 def search_company_raw(options={}) response = self.class.get( ApiURI.search_company, generate_params(options) ) increase_api_calls_count! response.body end
search_company_raw_json(options={})
click to toggle source
# File lib/data-com-api/client.rb, line 198 def search_company_raw_json(options={}) json_or_raise search_company_raw(options) end
search_contact(options={})
click to toggle source
# File lib/data-com-api/client.rb, line 63 def search_contact(options={}) Responses::SearchContact.new(self, options) end
search_contact_raw(options={})
click to toggle source
# File lib/data-com-api/client.rb, line 103 def search_contact_raw(options={}) response = self.class.get( ApiURI.search_contact, generate_params(options) ) increase_api_calls_count! response.body end
search_contact_raw_json(options={})
click to toggle source
# File lib/data-com-api/client.rb, line 194 def search_contact_raw_json(options={}) json_or_raise search_contact_raw(options) end
size_only_page_size()
click to toggle source
# File lib/data-com-api/client.rb, line 33 def size_only_page_size SIZE_ONLY_PAGE_SIZE end
user_raw(username, password)
click to toggle source
# File lib/data-com-api/client.rb, line 172 def user_raw(username, password) params = QueryParameters.new( username: username, password: password, token: token ) response = self.class.get( ApiURI.user, { query: params } ) increase_api_calls_count! response.body end
user_raw_json(username, password)
click to toggle source
# File lib/data-com-api/client.rb, line 223 def user_raw_json(username, password) json_or_raise user_raw(username, password) end
Private Instance Methods
generate_params(options)
click to toggle source
# File lib/data-com-api/client.rb, line 246 def generate_params(options) params = QueryParameters.new(options) params.offset = BASE_OFFSET unless params.offset params.page_size = page_size unless params.pageSize params.token = token { query: params } end
increase_api_calls_count!()
click to toggle source
# File lib/data-com-api/client.rb, line 255 def increase_api_calls_count! @api_calls_count += 1 end
json_or_raise(json_str)
click to toggle source
# File lib/data-com-api/client.rb, line 229 def json_or_raise(json_str) json = nil if json_str == DataComApi::Error::API_LIMIT_EXCEEDED_MSG raise ApiLimitExceededError, json_str else json = JSON.parse(json_str) end if json.kind_of? Array error = json.first raise Error.from_code(error['errorCode']).new(error['errorMsg']) end json end