data-com-api 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +81 -3
  3. data/data-com-api.gemspec +3 -1
  4. data/lib/data-com-api/api_uri.rb +40 -0
  5. data/lib/data-com-api/client.rb +247 -0
  6. data/lib/data-com-api/company.rb +17 -0
  7. data/lib/data-com-api/company_contact_count/department.rb +17 -0
  8. data/lib/data-com-api/company_contact_count/level.rb +17 -0
  9. data/lib/data-com-api/contact.rb +32 -0
  10. data/lib/data-com-api/errors.rb +96 -0
  11. data/lib/data-com-api/query_parameters.rb +66 -0
  12. data/lib/data-com-api/responses/base.rb +19 -0
  13. data/lib/data-com-api/responses/company_contact_count.rb +96 -0
  14. data/lib/data-com-api/responses/contacts.rb +97 -0
  15. data/lib/data-com-api/responses/search_base.rb +112 -0
  16. data/lib/data-com-api/responses/search_company.rb +23 -0
  17. data/lib/data-com-api/responses/search_contact.rb +23 -0
  18. data/lib/data-com-api/version.rb +1 -1
  19. data/lib/data-com-api.rb +14 -1
  20. data/spec/factories/client_factory.rb +12 -0
  21. data/spec/factories/data-com/company_contact_count/department_factory.rb +14 -0
  22. data/spec/factories/data-com/company_contact_count/level_factory.rb +14 -0
  23. data/spec/factories/data-com/company_contact_count_response_factory.rb +39 -0
  24. data/spec/factories/data-com/contact_factory.rb +35 -0
  25. data/spec/factories/data-com/contacts_response_factory.rb +30 -0
  26. data/spec/factories/data-com/search_contact_response_factory.rb +30 -0
  27. data/spec/factories/query_parameters_factory.rb +11 -0
  28. data/spec/factories/responses/search_contact_factory.rb +13 -0
  29. data/spec/integration/client_spec.rb +167 -0
  30. data/spec/integration/webmock_spec.rb +34 -0
  31. data/spec/models/client_spec.rb +164 -0
  32. data/spec/models/query_parameters_spec.rb +42 -0
  33. data/spec/models/search_base_spec.rb +80 -0
  34. data/spec/spec_helper.rb +22 -2
  35. data/spec/support/data_com_api_stub_requests.rb +229 -0
  36. metadata +75 -8
  37. data/spec/factories.rb +0 -4
  38. data/spec/requests/client_spec.rb +0 -6
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGVlNTI1Mzg4ZTM5MGRlNTBmNTk2ODhmN2FkYWVjZmYxZTVlYzI5NQ==
4
+ ZmJiODI5NjlmY2YxNTllZWYxMTM1NDZjYTA1MTI4ZTg5YWNkYTYxYQ==
5
5
  data.tar.gz: !binary |-
6
- ZDE2NTc1MDg4YzgxNzY1MzhmNWUwZTlhNDEwYmFhYzY0N2QzZDFmYQ==
6
+ ZWU3YzRiZDY4NjRlMTJiMDMzNDMyZmZjOGNkYmI5ZWM1OWU5NWU0NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGVlZGNlMDk0NzAwZDY0MzIxNjQ1MjNkYzJkYzQ3MzU2Mjg1ODk4ZjU4M2Yy
10
- NTliZmFhM2Y3ODBkOThlZTZlMTA1MzViMzk5ZTJiNDNjMGZiYjVkYzE0MmU3
11
- NmQxMGJlNGE0NjBjMDFkMmQ4ZDRjNDA5ODk5NjFmYjhiOGM5MGE=
9
+ YjQ0OWJkMWU0ZDA4MGMzMWNlNTBjOTE0ZjYwMDI1MjQ2NjYzODg2OGRjNTg0
10
+ MzAyZmI3MjVjN2VjMjk1YTQ5NWRiZDM4ZDNiYzQ3MDM3Y2JhYzliMjhjYjAx
11
+ NWEyN2Y4OTg1Y2I1YTdiZTI3OWRiYTU3NmNhN2FhY2NmNjExZjI=
12
12
  data.tar.gz: !binary |-
13
- ZWVmMjkwYTMxMjc0N2E5NWUwOGM5ZWQ4YjlmMTYxNzcwYTU4Y2Q2YmY0ODkz
14
- MzBkZmRmZGQzMGQzZTg5ZDJmNjA1ODFjOWEzY2QzYmUwNTU2ODI4YzI3ODRk
15
- ZmI0OTdkMzFjZGFlY2M3N2I2YzFjNGY4ZGE1ODgxNzU2ZmViM2M=
13
+ MzFmMTM4NjhkNTZhMjQ4M2UyNzhjZjg4NDYyNWZhNTdmYWRmYTZjNTVmNjE0
14
+ ODkzYjg5MGIyNDY5OTc2YzUzN2ZiZTljY2JiMWVmZTdkOTQ2ZjAzNjk4NjVh
15
+ ODhhYTMzNzhkMzU4ZWQxNWQ2Mzk5YmM5YjE4NWJiNTc1NGUzZTE=
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Data.com API
1
+ # DataComApi
2
2
 
3
3
  Allows to interface with Data.com API ( Salesforce, ex Jigsaw ).
4
4
  **Work in progress**
@@ -7,7 +7,7 @@ Allows to interface with Data.com API ( Salesforce, ex Jigsaw ).
7
7
 
8
8
  Add this line to your application's Gemfile:
9
9
 
10
- gem 'data-com-api'
10
+ gem 'data-com-api', '~> 0.1.0'
11
11
 
12
12
  And then execute:
13
13
 
@@ -19,7 +19,85 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- TODO: Write usage instructions here
22
+ First, create a `DataComApi::Client` instance with the following line:
23
+
24
+ ```ruby
25
+ client = DataComApi::Client.new('your-api-token')
26
+ ```
27
+
28
+ You can then configure the client in the following way:
29
+
30
+ ```ruby
31
+ client.page_size = 100 # Value must be between 1 and 100
32
+ ```
33
+
34
+ You can also get the totals API calls performed on the client with:
35
+
36
+ ```ruby
37
+ client.api_calls_count
38
+ ```
39
+
40
+ Then, you can perform one of the following requests:
41
+
42
+ - `search_contact`
43
+ - `search_company`
44
+ - `company_contact_count`
45
+ - `contacts`
46
+
47
+ Every method matches the Data.com API call and support the same parameters. All requests are *lazy*,
48
+ which means that the request will be performed only once you actually perform an action on the response, like
49
+ requesting `size`, `all`, `each` and such (keep reading).
50
+
51
+ ### Client methods aka API responses
52
+ #### #search\_contact and #search\_company
53
+
54
+ The parameters accepted by this method are the keys of the [DataComApi::QueryParameters](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/query_parameters.rb). Notice that you can use the key specified as `:from` for a more ruby-like
55
+ syntax.
56
+
57
+ The returned object is a `DataComApi::SearchContact` which is mostly a [DataComApi::SearchBase](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/responses/search_base.rb) instance with the following main methods:
58
+ - `size` which returns the `totalHits` field from the response
59
+ (it will perform a request only if none performed)
60
+ - `all` which returns an array containing all records that can be fetched
61
+ (be careful, can be **memory hungry**). Will handle paging by itself
62
+ - `each` which yields each record that can be obtained with the request, less memory hungry than previous
63
+ request. Will handle paging by itself
64
+ - `each_with_index` same as previous one but with index
65
+ - `at_offset` which get one page of records (as an array) at specified offset
66
+
67
+ Every record returned will be a [DataComApi::Contact](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/contact.rb) or a [DataComApi::Company](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/company.rb) instance.
68
+
69
+ #### #company\_contact\_count
70
+
71
+ The parameters accepted by this method are `company_id` (required) and the second one is [DataComApi::QueryParameters](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/query_parameters.rb) which is useful only for the `include_graveyard` key
72
+
73
+ This method allows you to count contacts per company, the response has the following methods:
74
+ - `size` which returns `totalCount` from API response
75
+ - `url` which returns `url` from API response
76
+ - `levels` which returns an array of [DataComApi::CompanyContactCount::Level](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/company_contact_count/level.rb)
77
+ - `departments` which returns an array of [DataComApi::CompanyContactCount::Departments](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/company_contact_count/department.rb)
78
+
79
+ #### #contacts
80
+
81
+ The parameters accepted by this method are `contact_ids` (an array of `Fixnum`), `username`, `password`
82
+ which are required and the optional `purchase_flag` which defaults to `false`.
83
+
84
+ **Be careful, this method may purchase records.**
85
+ This response has the following methods:
86
+ - `size` which returns `totalHits` from API response
87
+ - `used_points` which returns `pointsUsed` from API response
88
+ - `purchased_contacts` which returns `numberOfContactsPurchased` from API response
89
+ - `point_balance` which returns `pointBalance` from API response
90
+ - `contacts` which returns an array of [DataComApi::Contact](https://github.com/Fire-Dragon-DoL/data-com-api/blob/master/lib/data-com-api/contact.rb)
91
+
92
+ ## TODO
93
+
94
+ - Implement `partner` request
95
+ - Implement `partner_contacts` request
96
+ - Implement `user` request used to purchase points through API
97
+ - Write some tests for `search_company` which is exactly the same as
98
+ `search_contact`
99
+ - Improve tests organization
100
+ - Test exceptions when performing API requests
23
101
 
24
102
  ## Contributing
25
103
 
data/data-com-api.gemspec CHANGED
@@ -22,7 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency 'httparty', '~> 0.12.0'
25
+ spec.add_dependency 'httparty', '~> 0.12'
26
+ spec.add_dependency 'activesupport', '~> 4.0'
27
+ spec.add_dependency 'hashie', '~> 2.0'
26
28
 
27
29
  spec.add_development_dependency 'rspec', '~> 2.14'
28
30
  spec.add_development_dependency 'rspec-mocks', '~> 2.14'
@@ -0,0 +1,40 @@
1
+ require 'singleton'
2
+
3
+ module DataComApi
4
+
5
+ class BaseApiURI
6
+ include Singleton
7
+
8
+ def company_contact_count(company_id)
9
+ "/rest/companyContactCount/#{ company_id }.json"
10
+ end
11
+
12
+ def search_contact
13
+ "/rest/searchContact.json"
14
+ end
15
+
16
+ def search_company
17
+ "/rest/searchCompany.json"
18
+ end
19
+
20
+ def contacts(contact_ids)
21
+ "/rest/contacts/#{ contact_ids.join(',') }.json"
22
+ end
23
+
24
+ def partner_contacts(contact_ids)
25
+ "/rest/partnerContacts/#{ contact_ids.join(',') }.json"
26
+ end
27
+
28
+ def partner
29
+ "/rest/partner.json"
30
+ end
31
+
32
+ def user
33
+ "/rest/user.json"
34
+ end
35
+
36
+ end
37
+
38
+ ApiURI = BaseApiURI.instance
39
+
40
+ end
@@ -1,4 +1,251 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'data-com-api/errors'
4
+ require 'data-com-api/api_uri'
5
+ require 'data-com-api/responses/search_contact'
6
+ require 'data-com-api/responses/search_company'
7
+ require 'data-com-api/responses/company_contact_count'
8
+ require 'data-com-api/responses/contacts'
9
+
1
10
  module DataComApi
11
+
2
12
  class Client
13
+ include HTTParty
14
+ base_uri 'https://www.jigsaw.com'
15
+
16
+ ENV_NAME_TOKEN = 'DATA_COM_TOKEN'.freeze
17
+ TIME_ZONE = 'Pacific Time (US & Canada)'.freeze
18
+ BASE_OFFSET = 0
19
+ BASE_PAGE_SIZE = 50
20
+ SIZE_ONLY_PAGE_SIZE = 0
21
+ # We start at 1, 0 is a special case
22
+ MIN_PAGE_SIZE = 1
23
+ MAX_PAGE_SIZE = 100
24
+ MAX_OFFSET = 100_000
25
+
26
+ attr_reader :api_calls_count
27
+ attr_reader :token
28
+
29
+ def max_offset
30
+ MAX_OFFSET
31
+ end
32
+
33
+ def size_only_page_size
34
+ SIZE_ONLY_PAGE_SIZE
35
+ end
36
+
37
+ def initialize(api_token=nil)
38
+ @token = api_token || ENV[ENV_NAME_TOKEN]
39
+ @page_size = BASE_PAGE_SIZE
40
+ @api_calls_count = 0
41
+
42
+ raise TokenFailError, 'No token set!' unless @token
43
+ end
44
+
45
+ def page_size
46
+ @page_size
47
+ end
48
+
49
+ # Page size = 0 returns objects count only (small request)
50
+ def page_size=(value)
51
+ real_value = value.to_i
52
+
53
+ if real_value < MIN_PAGE_SIZE || real_value > MAX_PAGE_SIZE
54
+ raise ParamError, <<-eos
55
+ page_size must be between #{ MIN_PAGE_SIZE } and #{ MAX_PAGE_SIZE },
56
+ received #{ real_value }"
57
+ eos
58
+ end
59
+
60
+ @page_size = real_value
61
+ end
62
+
63
+ def search_contact(options={})
64
+ Responses::SearchContact.new(self, options)
65
+ end
66
+
67
+ def company_contact_count(company_id, options={})
68
+ Responses::CompanyContactCount.new(self, company_id, options)
69
+ end
70
+
71
+ def contacts(contact_ids, username, password, purchase_flag=false)
72
+ Responses::Contacts.new(
73
+ self,
74
+ contact_ids,
75
+ username,
76
+ password,
77
+ purchase_flag
78
+ )
79
+ end
80
+
81
+ # Raw calls
82
+
83
+ def company_contact_count_raw(company_id, include_graveyard)
84
+ params = QueryParameters.new(
85
+ token: token,
86
+ company_id: company_id,
87
+ include_graveyard: include_graveyard
88
+ )
89
+
90
+ response = self.class.get(
91
+ ApiURI.company_contact_count(company_id),
92
+ { query: params }
93
+ )
94
+ increase_api_calls_count!
95
+
96
+ response.body
97
+ end
98
+
99
+ def search_contact_raw(options={})
100
+ response = self.class.get(
101
+ ApiURI.search_contact,
102
+ generate_params(options)
103
+ )
104
+ increase_api_calls_count!
105
+
106
+ response.body
107
+ end
108
+
109
+ def search_company_raw(options={})
110
+ response = self.class.get(
111
+ ApiURI.search_company,
112
+ generate_params(options)
113
+ )
114
+ increase_api_calls_count!
115
+
116
+ response.body
117
+ end
118
+
119
+ def contacts_raw(contact_ids, username, password, purchase_flag=false)
120
+ raise ParamError, 'One contact required at least' unless contact_ids.size > 0
121
+
122
+ params = QueryParameters.new(
123
+ token: token,
124
+ username: username,
125
+ password: password,
126
+ purchase_flag: purchase_flag
127
+ )
128
+
129
+ response = self.class.get(
130
+ ApiURI.contacts(contact_ids),
131
+ { query: params }
132
+ )
133
+ increase_api_calls_count!
134
+
135
+ response.body
136
+ end
137
+
138
+ def partner_contacts_raw(contact_ids, end_org_id, end_user_id)
139
+ raise ParamError, 'One contact required at least' unless contact_ids.size > 0
140
+
141
+ params = QueryParameters.new(
142
+ token: token,
143
+ end_org_id: end_org_id,
144
+ end_user_id: end_user_id
145
+ )
146
+
147
+ response = self.class.get(
148
+ ApiURI.partner_contacts(contact_ids),
149
+ { query: params }
150
+ )
151
+ increase_api_calls_count!
152
+
153
+ response.body
154
+ end
155
+
156
+ def partner_raw
157
+ params = QueryParameters.new(token: token)
158
+
159
+ response = self.class.get(
160
+ ApiURI.partner,
161
+ { query: params }
162
+ )
163
+ increase_api_calls_count!
164
+
165
+ response.body
166
+ end
167
+
168
+ def user_raw(username, password)
169
+ params = QueryParameters.new(
170
+ username: username,
171
+ password: password,
172
+ token: token
173
+ )
174
+
175
+ response = self.class.get(
176
+ ApiURI.user,
177
+ { query: params }
178
+ )
179
+ increase_api_calls_count!
180
+
181
+ response.body
182
+ end
183
+
184
+ # JSON calls
185
+
186
+ def company_contact_count_raw_json(company_id, include_graveyard)
187
+ json_or_raise company_contact_count_raw(company_id, include_graveyard)
188
+ end
189
+
190
+ def search_contact_raw_json(options={})
191
+ json_or_raise search_contact_raw(options)
192
+ end
193
+
194
+ def search_company_raw_json(options={})
195
+ json_or_raise search_company_raw(options)
196
+ end
197
+
198
+ def contacts_raw_json(contact_ids, username, password, purchase_flag=false)
199
+ json_or_raise contacts_raw(
200
+ contact_ids,
201
+ username,
202
+ password,
203
+ purchase_flag
204
+ )
205
+ end
206
+
207
+ def partner_contacts_raw_json(contact_ids, end_org_id, end_user_id)
208
+ json_or_raise partner_contacts_raw(
209
+ contact_ids,
210
+ end_org_id,
211
+ end_user_id
212
+ )
213
+ end
214
+
215
+ def partner_raw_json
216
+ json_or_raise partner_raw
217
+ end
218
+
219
+ def user_raw_json(username, password)
220
+ json_or_raise user_raw(username, password)
221
+ end
222
+
223
+ private
224
+
225
+ def json_or_raise(json_str)
226
+ json = JSON.parse(json_str)
227
+
228
+ if json.kind_of? Array
229
+ error = json.first
230
+ raise Error.from_code(error['errorCode']).new(error['errorMsg'])
231
+ end
232
+
233
+ json
234
+ end
235
+
236
+ def generate_params(options)
237
+ params = QueryParameters.new(options)
238
+ params.offset = BASE_OFFSET unless params.offset
239
+ params.page_size = page_size unless params.pageSize
240
+ params.token = token
241
+
242
+ { query: params }
243
+ end
244
+
245
+ def increase_api_calls_count!
246
+ @api_calls_count += 1
247
+ end
248
+
3
249
  end
250
+
4
251
  end
@@ -0,0 +1,17 @@
1
+ require 'hashie'
2
+
3
+ module DataComApi
4
+ class Company < Hashie::Trash
5
+ property :id, from: :companyId
6
+ property :zip
7
+ property :address
8
+ property :name
9
+ property :active_contacts, from: :activeContacts
10
+ property :state
11
+ property :graveyarded
12
+ property :city
13
+ property :country
14
+
15
+ alias_method :graveyarded?, :graveyarded
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'hashie'
2
+
3
+ module DataComApi
4
+
5
+ module CompanyContactCount
6
+
7
+ class Department < Hashie::Trash
8
+ property :count
9
+ property :name
10
+ property :url
11
+
12
+ alias_method :size, :count
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'hashie'
2
+
3
+ module DataComApi
4
+
5
+ module CompanyContactCount
6
+
7
+ class Level < Hashie::Trash
8
+ property :count
9
+ property :name
10
+ property :url
11
+
12
+ alias_method :size, :count
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,32 @@
1
+ require 'hashie'
2
+ require 'active_support/time'
3
+
4
+ module DataComApi
5
+ class Contact < Hashie::Trash
6
+ property :id, from: :contactId
7
+ property :zip
8
+ property :phone
9
+ property :area_code, from: :areaCode
10
+ property :updated_at, from: :updatedDate, with: ->(v) { Time.parse(v.to_s).utc }
11
+ property :seo_contact_url, from: :seoContactURL
12
+ property :state
13
+ property :first_name, from: :firstname
14
+ property :last_name, from: :lastname
15
+ property :company_name, from: :companyName
16
+ property :contact_url, from: :contactURL
17
+ property :contact_sales, from: :contactSales
18
+ property :country
19
+ property :owned
20
+ property :city
21
+ property :title
22
+ property :email
23
+ property :address
24
+ property :graveyard_status, from: :graveyardStatus
25
+ property :owned_type, from: :ownedType
26
+ property :company_id, from: :companyId
27
+
28
+ alias_method :graveyarded, :graveyard_status
29
+ alias_method :graveyarded?, :graveyarded
30
+ alias_method :owned?, :owned
31
+ end
32
+ end
@@ -0,0 +1,96 @@
1
+ require 'active_support/core_ext/hash/reverse_merge'
2
+
3
+ module DataComApi
4
+
5
+ class Error < StandardError
6
+
7
+ API_HTTP_STATUS_CODE = 0
8
+ API_ERROR_CODE = 'no error code provided'
9
+
10
+ attr_reader :http_status_code
11
+ attr_reader :api_stack_trace
12
+ attr_reader :error_code
13
+
14
+ def initialize(msg=nil, options={})
15
+ options = options.reverse_merge({
16
+ http_status_code: nil,
17
+ api_stack_trace: nil,
18
+ error_code: nil
19
+ })
20
+
21
+ @http_status_code ||= options[:http_status_code] || self.class::API_HTTP_STATUS_CODE
22
+ @api_stack_trace ||= options[:api_stack_trace]
23
+ @error_code ||= options[:error_code] || self.class::API_ERROR_CODE
24
+
25
+ super(msg)
26
+ end
27
+
28
+ def self.from_code(error_code_str)
29
+ case error_code_str
30
+ when ParamError::API_ERROR_CODE then ParamError
31
+ when LoginFailError::API_ERROR_CODE then LoginFailError
32
+ when TokenFailError::API_ERROR_CODE then TokenFailError
33
+ when PurchaseLowPointsError::API_ERROR_CODE then PurchaseLowPointsError
34
+ when ContactNotExistError::API_ERROR_CODE then ContactNotExistError
35
+ when ContactNotOwnedError::API_ERROR_CODE then ContactNotOwnedError
36
+ when SearchError::API_ERROR_CODE then SearchError
37
+ when SysError::API_ERROR_CODE then SysError
38
+ when NotImplementedError::API_ERROR_CODE then NotImplementedError
39
+ when NotAvailableError::API_ERROR_CODE then NotAvailableError
40
+ else Error
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ class ParamError < Error
47
+ API_HTTP_STATUS_CODE = 400
48
+ API_ERROR_CODE = 'PARAM_ERROR'.freeze
49
+ end
50
+
51
+ class LoginFailError < Error
52
+ API_HTTP_STATUS_CODE = 403
53
+ API_ERROR_CODE = 'LOGIN_FAIL'.freeze
54
+ end
55
+
56
+ class TokenFailError < Error
57
+ API_HTTP_STATUS_CODE = 403
58
+ API_ERROR_CODE = 'TOKEN_FAIL'.freeze
59
+ end
60
+
61
+ class PurchaseLowPointsError < Error
62
+ API_HTTP_STATUS_CODE = 405
63
+ API_ERROR_CODE = 'PURCHASE_LOW_POINTS'.freeze
64
+ end
65
+
66
+ class ContactNotExistError < Error
67
+ API_HTTP_STATUS_CODE = 404
68
+ API_ERROR_CODE = 'CONTACT_NOT_EXIST'.freeze
69
+ end
70
+
71
+ class ContactNotOwnedError < Error
72
+ API_HTTP_STATUS_CODE = 405
73
+ API_ERROR_CODE = 'CONTACT_NOT_OWNED'.freeze
74
+ end
75
+
76
+ class SearchError < Error
77
+ API_HTTP_STATUS_CODE = 500
78
+ API_ERROR_CODE = 'SEARCH_ERROR'.freeze
79
+ end
80
+
81
+ class SysError < Error
82
+ API_HTTP_STATUS_CODE = 500
83
+ API_ERROR_CODE = 'SYS_ERROR'.freeze
84
+ end
85
+
86
+ class NotImplementedError < Error
87
+ API_HTTP_STATUS_CODE = 501
88
+ API_ERROR_CODE = 'NOT_IMPLEMENTED'.freeze
89
+ end
90
+
91
+ class NotAvailableError < Error
92
+ API_HTTP_STATUS_CODE = 503
93
+ API_ERROR_CODE = 'NOT_AVAILABLE'.freeze
94
+ end
95
+
96
+ end
@@ -0,0 +1,66 @@
1
+ require 'hashie'
2
+ require 'active_support/time'
3
+
4
+ module DataComApi
5
+ class QueryParameters < Hashie::Trash
6
+ UNALLOWED_FIELDS = [
7
+ :offset,
8
+ :pageSize,
9
+ :page_size,
10
+ :username,
11
+ :password,
12
+ :token
13
+ ].freeze
14
+
15
+ property :companyId, from: :company_id
16
+ property :updatedSince, from: :updated_since, with: ->(v) do
17
+ Time.parse(v).utc.in_time_zone(Client::TIME_ZONE)
18
+ end
19
+ property :title
20
+ property :companyName, from: :company_name
21
+ property :name
22
+ property :lastname
23
+ property :firstname
24
+ property :email
25
+ property :levels
26
+ property :departments
27
+ property :country
28
+ property :state
29
+ property :metroArea, from: :metro_area
30
+ property :areaCode, from: :area_code
31
+ property :zipCode, from: :zip_code
32
+ property :industry
33
+ property :subIndustry, from: :sub_industry
34
+ property :employees
35
+ property :revenue
36
+ property :ownership
37
+ property :websiteType, from: :website_type
38
+ property :fortuneRank, from: :fortune_rank
39
+ property :includeGraveyard, from: :include_graveyard
40
+ property :order
41
+ property :orderBy, from: :order_by
42
+ property :purchaseFlag, from: :purchase_flag
43
+ property :endOrgId, from: :end_org_id
44
+ property :endUserId, from: :end_user_id
45
+
46
+ # Special params, used to inject into query, set only through gem
47
+ property :offset
48
+ property :pageSize, from: :page_size
49
+ property :username
50
+ property :password
51
+ property :token
52
+
53
+ # Destructively convert all values using into strings
54
+ def self.stringify_hash_values(hash)
55
+ hash.each_pair do |key, value|
56
+ hash[key] = value.to_s
57
+ end
58
+ hash
59
+ end
60
+
61
+ def to_hash
62
+ self.class.stringify_hash_values(super)
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,19 @@
1
+ require 'active_support/cache'
2
+
3
+ module DataComApi
4
+ module Responses
5
+ class Base
6
+
7
+ def initialize(api_client)
8
+ @client = api_client
9
+ end
10
+
11
+ protected
12
+
13
+ def client
14
+ @client
15
+ end
16
+
17
+ end
18
+ end
19
+ end