data-com-api 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,229 @@
1
+ require 'uri'
2
+ require 'singleton'
3
+ require 'webmock'
4
+ require 'faker'
5
+ require 'data-com-api/api_uri'
6
+ require 'data-com-api/client'
7
+ require 'data-com-api/query_parameters'
8
+
9
+ class DataComApiStubRequestsBase
10
+ include Singleton
11
+ include WebMock::API
12
+
13
+ def stub_contacts(contact_ids, options={})
14
+ options = {
15
+ username: Faker::Internet.user_name,
16
+ password: Faker::Internet.password,
17
+ purchase_flag: false,
18
+ total_hits: 1,
19
+ used_points: Faker::Number.number(2).to_i,
20
+ purchased_contacts: 1,
21
+ point_balance: Faker::Number.number(2).to_i,
22
+ contacts: nil
23
+ }.merge!(options)
24
+
25
+ stub_request(
26
+ :get,
27
+ URI.join(
28
+ DataComApi::Client.base_uri, DataComApi::ApiURI.contacts(
29
+ contact_ids
30
+ )
31
+ ).to_s
32
+ ).with(
33
+ query: hash_including(DataComApi::QueryParameters.new(
34
+ username: options[:username],
35
+ password: options[:password],
36
+ purchase_flag: options[:purchase_flag]
37
+ ).to_hash)
38
+ ).to_return(
39
+ body: FactoryGirl.build(
40
+ :data_com_contacts_response,
41
+ pointsUsed: options[:used_points],
42
+ totalHits: options[:total_hits],
43
+ numberOfContactsPurchased: options[:purchased_contacts],
44
+ pointBalance: options[:point_balance],
45
+ contacts: options[:contacts]
46
+ ).to_json
47
+ )
48
+ end
49
+
50
+ def stub_company_contact_count(company_id, options={})
51
+ options = {
52
+ total_count: 10
53
+ }.merge!(options)
54
+
55
+ stub_request(
56
+ :get,
57
+ URI.join(
58
+ DataComApi::Client.base_uri, DataComApi::ApiURI.company_contact_count(
59
+ company_id
60
+ )
61
+ ).to_s
62
+ ).with(
63
+ query: hash_including({})
64
+ ).to_return(
65
+ body: FactoryGirl.build(
66
+ :data_com_company_contact_count_response,
67
+ totalCount: options[:total_count]
68
+ ).to_json
69
+ )
70
+ end
71
+
72
+ def stub_search_few_contacts(options={})
73
+ options = {
74
+ page_size: DataComApi::Client::BASE_PAGE_SIZE,
75
+ total_hits: 0,
76
+ include_size_request: true,
77
+ size_request_only: false,
78
+ query: {},
79
+ records: []
80
+ }.merge!(options)
81
+
82
+ if options[:include_size_request]
83
+ stub_request(
84
+ :get,
85
+ URI.join(
86
+ DataComApi::Client.base_uri, DataComApi::ApiURI.search_contact
87
+ ).to_s
88
+ ).with(
89
+ query: hash_including(DataComApi::QueryParameters.new(
90
+ options[:query].merge(
91
+ page_size: DataComApi::Client::SIZE_ONLY_PAGE_SIZE,
92
+ offset: DataComApi::Client::BASE_OFFSET
93
+ )
94
+ ).to_hash)
95
+ ).to_return(
96
+ body: FactoryGirl.build(
97
+ :data_com_search_contact_response,
98
+ page_size: 0,
99
+ totalHits: options[:total_hits],
100
+ contacts: []
101
+ ).to_json
102
+ )
103
+ end
104
+
105
+ unless options[:size_request_only]
106
+ stub_request(
107
+ :get,
108
+ URI.join(
109
+ DataComApi::Client.base_uri, DataComApi::ApiURI.search_contact
110
+ ).to_s
111
+ ).with(
112
+ query: hash_including(DataComApi::QueryParameters.new(
113
+ options[:query].merge(
114
+ page_size: options[:page_size],
115
+ offset: DataComApi::Client::BASE_OFFSET
116
+ )
117
+ ).to_hash)
118
+ ).to_return(
119
+ body: FactoryGirl.build(
120
+ :data_com_search_contact_response,
121
+ # Used because we want a response with only amount of records requested
122
+ page_size: options[:records].size,
123
+ totalHits: options[:total_hits],
124
+ contacts: options[:records]
125
+ ).to_json
126
+ )
127
+ end
128
+ end
129
+
130
+ def stub_search_contact(options={})
131
+ options = {
132
+ page_size: DataComApi::Client::BASE_PAGE_SIZE,
133
+ include_size_request: true,
134
+ total_hits: 0,
135
+ size_request_only: false
136
+ }.merge!(options)
137
+ last_page_records = 0
138
+
139
+ if options[:include_size_request]
140
+ stub_request(
141
+ :get,
142
+ URI.join(
143
+ DataComApi::Client.base_uri, DataComApi::ApiURI.search_contact
144
+ ).to_s
145
+ ).with(
146
+ # XXX: Big webmock bug, values of hashes in query must be strings
147
+ query: hash_including(DataComApi::QueryParameters.new(
148
+ page_size: DataComApi::Client::SIZE_ONLY_PAGE_SIZE,
149
+ offset: DataComApi::Client::BASE_OFFSET
150
+ ).to_hash)
151
+ ).to_return(
152
+ body: FactoryGirl.build(
153
+ :data_com_search_contact_response,
154
+ page_size: 0,
155
+ totalHits: options[:total_hits]
156
+ ).to_json
157
+ )
158
+ end
159
+
160
+ if !options[:size_request_only] &&
161
+ options[:page_size] > 0 &&
162
+ options[:total_hits] > 0
163
+
164
+ total_pages = options[:total_hits] / options[:page_size]
165
+ last_page_records = options[:total_hits] % options[:page_size]
166
+
167
+ total_pages.times do |page_index|
168
+ stub_request(
169
+ :get,
170
+ URI.join(
171
+ DataComApi::Client.base_uri, DataComApi::ApiURI.search_contact
172
+ ).to_s
173
+ ).with(
174
+ query: hash_including(DataComApi::QueryParameters.new(
175
+ page_size: options[:page_size],
176
+ offset: page_index * options[:page_size]
177
+ ).to_hash)
178
+ ).to_return(
179
+ body: FactoryGirl.build(
180
+ :data_com_search_contact_response,
181
+ page_size: options[:page_size],
182
+ totalHits: options[:total_hits]
183
+ ).to_json
184
+ )
185
+ end
186
+ elsif options[:total_hits] == 0 && !options[:size_request_only]
187
+ stub_request(
188
+ :get,
189
+ URI.join(
190
+ DataComApi::Client.base_uri, DataComApi::ApiURI.search_contact
191
+ ).to_s
192
+ ).with(
193
+ query: hash_including(DataComApi::QueryParameters.new(
194
+ page_size: options[:page_size],
195
+ offset: DataComApi::Client::BASE_OFFSET
196
+ ).to_hash)
197
+ ).to_return(
198
+ body: FactoryGirl.build(
199
+ :data_com_search_contact_response,
200
+ page_size: 0,
201
+ totalHits: options[:total_hits]
202
+ ).to_json
203
+ )
204
+ end
205
+
206
+ if last_page_records > 0
207
+ stub_request(
208
+ :get,
209
+ URI.join(
210
+ DataComApi::Client.base_uri, DataComApi::ApiURI.search_contact
211
+ ).to_s
212
+ ).with(
213
+ query: hash_including(DataComApi::QueryParameters.new(
214
+ page_size: options[:page_size],
215
+ offset: total_pages * options[:page_size]
216
+ ).to_hash)
217
+ ).to_return(
218
+ body: FactoryGirl.build(
219
+ :data_com_search_contact_response,
220
+ page_size: last_page_records,
221
+ totalHits: options[:total_hits]
222
+ ).to_json
223
+ )
224
+ end
225
+ end
226
+
227
+ end
228
+
229
+ DataComApiStubRequests = DataComApiStubRequestsBase.instance
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data-com-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fire-Dragon-DoL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.12.0
19
+ version: '0.12'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.12.0
26
+ version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rspec
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -182,11 +210,37 @@ files:
182
210
  - Rakefile
183
211
  - data-com-api.gemspec
184
212
  - lib/data-com-api.rb
213
+ - lib/data-com-api/api_uri.rb
185
214
  - lib/data-com-api/client.rb
215
+ - lib/data-com-api/company.rb
216
+ - lib/data-com-api/company_contact_count/department.rb
217
+ - lib/data-com-api/company_contact_count/level.rb
218
+ - lib/data-com-api/contact.rb
219
+ - lib/data-com-api/errors.rb
220
+ - lib/data-com-api/query_parameters.rb
221
+ - lib/data-com-api/responses/base.rb
222
+ - lib/data-com-api/responses/company_contact_count.rb
223
+ - lib/data-com-api/responses/contacts.rb
224
+ - lib/data-com-api/responses/search_base.rb
225
+ - lib/data-com-api/responses/search_company.rb
226
+ - lib/data-com-api/responses/search_contact.rb
186
227
  - lib/data-com-api/version.rb
187
- - spec/factories.rb
188
- - spec/requests/client_spec.rb
228
+ - spec/factories/client_factory.rb
229
+ - spec/factories/data-com/company_contact_count/department_factory.rb
230
+ - spec/factories/data-com/company_contact_count/level_factory.rb
231
+ - spec/factories/data-com/company_contact_count_response_factory.rb
232
+ - spec/factories/data-com/contact_factory.rb
233
+ - spec/factories/data-com/contacts_response_factory.rb
234
+ - spec/factories/data-com/search_contact_response_factory.rb
235
+ - spec/factories/query_parameters_factory.rb
236
+ - spec/factories/responses/search_contact_factory.rb
237
+ - spec/integration/client_spec.rb
238
+ - spec/integration/webmock_spec.rb
239
+ - spec/models/client_spec.rb
240
+ - spec/models/query_parameters_spec.rb
241
+ - spec/models/search_base_spec.rb
189
242
  - spec/spec_helper.rb
243
+ - spec/support/data_com_api_stub_requests.rb
190
244
  homepage: https://github.com/Fire-Dragon-DoL/data-com-api
191
245
  licenses:
192
246
  - MIT
@@ -212,6 +266,19 @@ signing_key:
212
266
  specification_version: 4
213
267
  summary: Allows to interface with Data.com API ( Salesforce, ex Jigsaw )
214
268
  test_files:
215
- - spec/factories.rb
216
- - spec/requests/client_spec.rb
269
+ - spec/factories/client_factory.rb
270
+ - spec/factories/data-com/company_contact_count/department_factory.rb
271
+ - spec/factories/data-com/company_contact_count/level_factory.rb
272
+ - spec/factories/data-com/company_contact_count_response_factory.rb
273
+ - spec/factories/data-com/contact_factory.rb
274
+ - spec/factories/data-com/contacts_response_factory.rb
275
+ - spec/factories/data-com/search_contact_response_factory.rb
276
+ - spec/factories/query_parameters_factory.rb
277
+ - spec/factories/responses/search_contact_factory.rb
278
+ - spec/integration/client_spec.rb
279
+ - spec/integration/webmock_spec.rb
280
+ - spec/models/client_spec.rb
281
+ - spec/models/query_parameters_spec.rb
282
+ - spec/models/search_base_spec.rb
217
283
  - spec/spec_helper.rb
284
+ - spec/support/data_com_api_stub_requests.rb
data/spec/factories.rb DELETED
@@ -1,4 +0,0 @@
1
- FactoryGirl.define do
2
-
3
-
4
- end
@@ -1,6 +0,0 @@
1
- require 'spec_helper'
2
- require 'data-com-api/client'
3
-
4
- describe DataComApi::Client do
5
-
6
- end