wix-hive-ruby 0.9.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 (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rubocop.yml +487 -0
  4. data/.yardopts +6 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +11 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +641 -0
  9. data/Rakefile +33 -0
  10. data/e2e/activities_api_spec.rb +334 -0
  11. data/e2e/contacts_api_spec.rb +364 -0
  12. data/e2e/e2e_helper.rb +35 -0
  13. data/e2e/insights_api_spec.rb +29 -0
  14. data/lib/hive/activities/contact/contact_create_activity.rb +109 -0
  15. data/lib/hive/activities/contact/contact_form_activity.rb +31 -0
  16. data/lib/hive/activities/conversion/conversion_complete_activity.rb +33 -0
  17. data/lib/hive/activities/e_commerce/purchase_activity.rb +150 -0
  18. data/lib/hive/activities/factory.rb +71 -0
  19. data/lib/hive/activities/hotels/hotels_cancel_activity.rb +52 -0
  20. data/lib/hive/activities/hotels/hotels_confirmation_activity.rb +133 -0
  21. data/lib/hive/activities/hotels/hotels_purchase_activity.rb +48 -0
  22. data/lib/hive/activities/hotels/hotels_purchase_failed_activity.rb +59 -0
  23. data/lib/hive/activities/messaging/send_activity.rb +75 -0
  24. data/lib/hive/activities/music/album_fan_activity.rb +36 -0
  25. data/lib/hive/activities/music/album_share_activity.rb +23 -0
  26. data/lib/hive/activities/music/track_lyrics_activity.rb +38 -0
  27. data/lib/hive/activities/music/track_play_activity.rb +31 -0
  28. data/lib/hive/activities/music/track_played_activity.rb +31 -0
  29. data/lib/hive/activities/music/track_share_activity.rb +32 -0
  30. data/lib/hive/activities/music/track_skipped_activity.rb +31 -0
  31. data/lib/hive/activities/scheduler/scheduler_appointment_activity.rb +73 -0
  32. data/lib/hive/activity.rb +60 -0
  33. data/lib/hive/activity_summary.rb +24 -0
  34. data/lib/hive/connect/request/wix_api_request.rb +92 -0
  35. data/lib/hive/connect/response/error.rb +88 -0
  36. data/lib/hive/connect/response/parse_json.rb +29 -0
  37. data/lib/hive/connect/response/raise_error.rb +17 -0
  38. data/lib/hive/connect/wix_client.rb +148 -0
  39. data/lib/hive/contact.rb +153 -0
  40. data/lib/hive/cursor.rb +48 -0
  41. data/lib/hive/errors.rb +5 -0
  42. data/lib/hive/extensions/hashie_hash.rb +16 -0
  43. data/lib/hive/extensions/hashie_validate_enum.rb +11 -0
  44. data/lib/hive/rest/activities.rb +55 -0
  45. data/lib/hive/rest/api.rb +13 -0
  46. data/lib/hive/rest/contacts.rb +114 -0
  47. data/lib/hive/rest/insights.rb +17 -0
  48. data/lib/hive/util.rb +20 -0
  49. data/lib/hive/version.rb +14 -0
  50. data/lib/wix-hive-ruby.rb +5 -0
  51. data/samples/quick_start.rb +49 -0
  52. data/spec/hive/activities/contact/contact_create_activity_spec.rb +25 -0
  53. data/spec/hive/activities/contact/contact_form_activity_spec.rb +9 -0
  54. data/spec/hive/activities/conversion/conversion_complete_activity_spec.rb +9 -0
  55. data/spec/hive/activities/e_commerce/purchase_activity_spec.rb +19 -0
  56. data/spec/hive/activities/factory_spec.rb +78 -0
  57. data/spec/hive/activities/hotels/hotels_cancel_activity_spec.rb +22 -0
  58. data/spec/hive/activities/hotels/hotels_confirmation_activity_spec.rb +34 -0
  59. data/spec/hive/activities/hotels/hotels_purchase_activity_spec.rb +22 -0
  60. data/spec/hive/activities/hotels/hotels_purchase_failed_activity_spec.rb +22 -0
  61. data/spec/hive/activities/messaging/send_activity_spec.rb +13 -0
  62. data/spec/hive/activities/scheduler/scheduler_appointment_activity_spec.rb +10 -0
  63. data/spec/hive/activity_spec.rb +18 -0
  64. data/spec/hive/connect/request/wix_api_request_spec.rb +54 -0
  65. data/spec/hive/connect/response/error_spec.rb +31 -0
  66. data/spec/hive/connect/response/parse_json_spec.rb +28 -0
  67. data/spec/hive/connect/response/raise_error_spec.rb +19 -0
  68. data/spec/hive/connect/wix_client_spec.rb +103 -0
  69. data/spec/hive/contact_spec.rb +148 -0
  70. data/spec/hive/cursor_spec.rb +75 -0
  71. data/spec/hive/hashie_hash_spec.rb +23 -0
  72. data/spec/hive/rest/activities_spec.rb +87 -0
  73. data/spec/hive/rest/contacts_spec.rb +225 -0
  74. data/spec/hive/rest/insights_spec.rb +17 -0
  75. data/spec/hive/util_spec.rb +36 -0
  76. data/spec/spec_helper.rb +59 -0
  77. data/wix-hive-ruby.gemspec +38 -0
  78. metadata +392 -0
@@ -0,0 +1,33 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ # Default directory to look in is `/specs`
6
+ # Run with `rake spec`
7
+ RSpec::Core::RakeTask.new(:spec) do |task|
8
+ task.rspec_opts = %w[--color --format documentation]
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new(:end2end) do |task|
12
+ task.pattern = ['./e2e{,/*/**}/*_spec.rb']
13
+ task.rspec_opts = %w[-I e2e --color --format documentation]
14
+ end
15
+
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb']
18
+ task.fail_on_error = false
19
+ task.options = ['--auto-correct']
20
+ end
21
+
22
+ task default: [:spec, :rubocop, :coverage]
23
+ task test: :spec
24
+ task e2e: :end2end
25
+ task :acceptance do
26
+ ENV['ACCEPTANCE'] = 'true'
27
+ Rake::Task[:end2end].execute
28
+ end
29
+ task :rubocop
30
+ task :coverage do
31
+ ENV['COVERAGE'] = 'true'
32
+ Rake::Task[:spec].execute
33
+ end
@@ -0,0 +1,334 @@
1
+ require_relative './e2e_helper'
2
+
3
+ describe 'Activities API' do
4
+
5
+ FACTORY = Hive::Activities
6
+ session_id = '02594992c9c57f61148351a766cf2ab79f7a7007ce309a16fc2b6475b0895b5b09250b55ec2c4cdba152aef47daded4d1e60994d53964e647acf431e4f798bcd0b93ce826ad6aa27a9c95ffedb05f421b7b1419780cf6036d4fd8efd847f9877'
7
+
8
+ let(:base_activity) {
9
+ Hive::Activity.new(
10
+ type: FACTORY::MUSIC_ALBUM_FAN.type,
11
+ locationUrl: 'http://www.wix.com',
12
+ details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
13
+ info: { album: { name: 'Wix', id: '1234' } })
14
+ }
15
+
16
+ it '.new_activity' do
17
+ new_activity_result = client.new_activity(session_id, base_activity)
18
+
19
+ expect(new_activity_result.activityId).to be_truthy
20
+ end
21
+
22
+ it '.activity' do
23
+ new_activity_result = client.new_activity(session_id, base_activity)
24
+
25
+ expect(new_activity_result.activityId).to be_truthy
26
+
27
+ sleep(2)
28
+
29
+ expect(client.activity(new_activity_result.activityId)).to be_a Hive::Activity
30
+ end
31
+
32
+ context '.activities' do
33
+ it 'returns a cursor with activity results' do
34
+ cursored_result = client.activities
35
+ expect(cursored_result).to be_a Hive::Cursor
36
+ expect(cursored_result.results.first).to be_a Hive::Activity
37
+ end
38
+
39
+ it 'returns a cursor with activities filtered by activityTypes' do
40
+ cursored_result = client.activities(activityTypes: Hive::Activities::MUSIC_ALBUM_FAN.type)
41
+ expect(cursored_result).to be_a Hive::Cursor
42
+ expect(cursored_result.results.map{ |v| v.activityType } ).to all(eq Hive::Activities::MUSIC_ALBUM_FAN.type)
43
+ end
44
+
45
+ it 'returns a cursor with activities filtered by scope' do
46
+ app_result = client.activities(scope: :app)
47
+ site_result = client.activities(scope: :site)
48
+ expect(app_result).to be_a Hive::Cursor
49
+ expect(site_result).to be_a Hive::Cursor
50
+ end
51
+
52
+ it 'returns a cursor with activities limited by date range' do
53
+ now_result = client.activities(from: Time.now.iso8601(3), until: Time.now.iso8601(3))
54
+ day_ago = (Time.now - (60 * 60 * 24)).iso8601(3)
55
+ day_ago_result = client.activities(from: day_ago, until: Time.now.iso8601(3))
56
+
57
+ expect(now_result.results.size).to eq 0
58
+ expect(day_ago_result.results.size).to be >= 1
59
+ end
60
+ end
61
+
62
+ context 'create activities' do
63
+ it 'CONTACT_CONTACT_FORM' do
64
+
65
+ contacts_create = FACTORY::CONTACT_CONTACT_FORM.klass.new
66
+ contacts_create.add_field(name: 'name', value: 'value')
67
+
68
+ activity = Hive::Activity.new(
69
+ type: FACTORY::CONTACT_CONTACT_FORM.type,
70
+ locationUrl: 'http://www.wix.com',
71
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
72
+ info: contacts_create)
73
+
74
+ new_activity_result = client.new_activity(session_id, activity)
75
+
76
+ expect(new_activity_result.activityId).to be_truthy
77
+ end
78
+
79
+ it 'CONVERSION_COMPLETE' do
80
+ activity = Hive::Activity.new(
81
+ type: FACTORY::CONVERSION_COMPLETE.type,
82
+ locationUrl: 'http://www.wix.com',
83
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
84
+ info: {conversionType: 'PAGEVIEW'})
85
+
86
+ new_activity_result = client.new_activity(session_id, activity)
87
+
88
+ expect(new_activity_result.activityId).to be_truthy
89
+ end
90
+
91
+ it 'E_COMMERCE_PURCHASE' do
92
+ coupon = {total: '1', title: 'Dis'}
93
+ tax = {total: 1, formattedTotal: 1}
94
+ shipping = {total: 1, formattedTotal: 1}
95
+ payment = {total: '1', subtotal: '1', formattedTotal: '1.0', formattedSubtotal: '1.0', currency: 'EUR', coupon: coupon, tax: tax, shipping: shipping}
96
+ media = {thumbnail: 'PIC'}
97
+ item = {id: 1, sku: 'sky', title: 'title', quantity: 1, price: '1', formattedPrice: '1.1', currency: 'EUR', productLink: 'link', weight: '1', formattedWeight: '1.0KG', media: media, variants: [{title: 'title', value: '1'}]}
98
+ shipping_address = {firstName: 'Wix' , lastName: 'Cool', email: 'wix@example.com', phone: '12345566', country: 'Macedonia', countryCode: 'MK', region: 'Bitola', regionCode: '7000', city: 'Bitola', address1: 'Marshal Tito', address2: 'Marshal Tito', zip: '7000', company: 'Wix.com'}
99
+
100
+ purchase = FACTORY::E_COMMERCE_PURCHASE.klass.new(cartId: '11111',
101
+ storeId: '11111',
102
+ orderId: '11111',
103
+ items: [item],
104
+ payment: payment,
105
+ shippingAddress: shipping_address,
106
+ billingAddress: shipping_address,
107
+ paymentGateway: 'PAYPAL',
108
+ note: 'Note',
109
+ buyerAcceptsMarketing: true)
110
+
111
+ activity = Hive::Activity.new(
112
+ type: FACTORY::E_COMMERCE_PURCHASE.type,
113
+ locationUrl: 'http://www.wix.com',
114
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
115
+ info: purchase)
116
+
117
+ new_activity_result = client.new_activity(session_id, activity)
118
+
119
+ expect(new_activity_result.activityId).to be_truthy
120
+ end
121
+
122
+ it 'MESSAGING_SEND' do
123
+ recipient = {method: 'EMAIL', destination: {name: {first: 'Alex'}, target: 'localhost'}}
124
+
125
+ send = FACTORY::MESSAGING_SEND.klass.new(recipient: recipient)
126
+
127
+ activity = Hive::Activity.new(
128
+ type: FACTORY::MESSAGING_SEND.type,
129
+ locationUrl: 'http://www.wix.com',
130
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
131
+ info: send)
132
+
133
+ new_activity_result = client.new_activity(session_id, activity)
134
+
135
+ expect(new_activity_result.activityId).to be_truthy
136
+ end
137
+
138
+ it 'MUSIC_ALBUM_FAN' do
139
+ activity = Hive::Activity.new(
140
+ type: FACTORY::MUSIC_ALBUM_FAN.type,
141
+ locationUrl: 'http://www.wix.com',
142
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
143
+ info: { album: { name: 'Wix', id: '1234' } })
144
+
145
+ new_activity_result = client.new_activity(session_id, activity)
146
+
147
+ expect(new_activity_result.activityId).to be_truthy
148
+ end
149
+
150
+ it 'MUSIC_ALBUM_SHARE' do
151
+ activity = Hive::Activity.new(
152
+ type: FACTORY::MUSIC_ALBUM_SHARE.type,
153
+ locationUrl: 'http://www.wix.com',
154
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
155
+ info: { album: { name: 'Wix', id: '1234' }, sharedTo: 'FACEBOOK' })
156
+
157
+ new_activity_result = client.new_activity(session_id, activity)
158
+
159
+ expect(new_activity_result.activityId).to be_truthy
160
+ end
161
+
162
+ it 'MUSIC_TRACK_LYRICS' do
163
+ activity = Hive::Activity.new(
164
+ type: FACTORY::MUSIC_TRACK_LYRICS.type,
165
+ locationUrl: 'http://www.wix.com',
166
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
167
+ info: { album: { name: 'Wix', id: '1234' }, track: { name: 'Wix', id: '1234' } })
168
+
169
+ new_activity_result = client.new_activity(session_id, activity)
170
+
171
+ expect(new_activity_result.activityId).to be_truthy
172
+ end
173
+
174
+ it 'MUSIC_TRACK_PLAY' do
175
+ activity = Hive::Activity.new(
176
+ type: FACTORY::MUSIC_TRACK_PLAY.type,
177
+ locationUrl: 'http://www.wix.com',
178
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
179
+ info: { album: { name: 'Wix', id: '1234' }, track: { name: 'Wix', id: '1234' } })
180
+
181
+ new_activity_result = client.new_activity(session_id, activity)
182
+
183
+ expect(new_activity_result.activityId).to be_truthy
184
+ end
185
+
186
+ it 'MUSIC_TRACK_PLAYED' do
187
+ activity = Hive::Activity.new(
188
+ type: FACTORY::MUSIC_TRACK_PLAYED.type,
189
+ locationUrl: 'http://www.wix.com',
190
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
191
+ info: { album: { name: 'Wix', id: '1234' }, track: { name: 'Wix', id: '1234' } })
192
+
193
+ new_activity_result = client.new_activity(session_id, activity)
194
+
195
+ expect(new_activity_result.activityId).to be_truthy
196
+ end
197
+
198
+ it 'MUSIC_TRACK_SKIP' do
199
+ activity = Hive::Activity.new(
200
+ type: FACTORY::MUSIC_TRACK_SKIP.type,
201
+ locationUrl: 'http://www.wix.com',
202
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
203
+ info: { album: { name: 'Wix', id: '1234' }, track: { name: 'Wix', id: '1234' } })
204
+
205
+ new_activity_result = client.new_activity(session_id, activity)
206
+
207
+ expect(new_activity_result.activityId).to be_truthy
208
+ end
209
+
210
+ it 'MUSIC_TRACK_SHARE' do
211
+ activity = Hive::Activity.new(
212
+ type: FACTORY::MUSIC_TRACK_SHARE.type,
213
+ locationUrl: 'http://www.wix.com',
214
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
215
+ info: { album: { name: 'Wix', id: '1234' }, track: { name: 'Wix', id: '1234' }, sharedTo: 'FACEBOOK' })
216
+
217
+ new_activity_result = client.new_activity(session_id, activity)
218
+
219
+ expect(new_activity_result.activityId).to be_truthy
220
+ end
221
+
222
+ it 'HOTELS_CONFIRMATION' do
223
+ pending 'HAPI-36'
224
+ guest = { total: 1, adults: 1, children: 0 }
225
+
226
+ day_ago = (Time.now - (60 * 60 * 24)).iso8601(3)
227
+ stay = { checkin: day_ago, checkout: Time.now.iso8601(3) }
228
+
229
+ invoice = {total: '1', subtotal: '1', currency: 'EUR'}
230
+
231
+ activity = Hive::Activity.new(
232
+ type: FACTORY::HOTELS_CONFIRMATION.type,
233
+ locationUrl: 'http://www.wix.com',
234
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
235
+ info: { source: 'GUEST', guests: guest, stay: stay, invoice: invoice })
236
+
237
+ new_activity_result = client.new_activity(session_id, activity)
238
+
239
+ expect(new_activity_result.activityId).to be_truthy
240
+ end
241
+
242
+ it 'HOTELS_CANCEL' do
243
+ pending 'HAPI-36'
244
+ refund = {kind: 'FULL', total: 1, currency: 'EUR', destination: 'NYC'}
245
+
246
+ guest = { total: 1, adults: 1, children: 0 }
247
+
248
+ day_ago = (Time.now - (60 * 60 * 24)).iso8601(3)
249
+ stay = { checkin: day_ago, checkout: Time.now.iso8601(3) }
250
+
251
+ invoice = {total: '1', subtotal: '1', currency: 'EUR'}
252
+
253
+ activity = Hive::Activity.new(
254
+ type: FACTORY::HOTELS_CANCEL.type,
255
+ locationUrl: 'http://www.wix.com',
256
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
257
+ info: { cancelDate: day_ago, refund: refund, guests: guest,
258
+ stay: stay, invoice: invoice })
259
+
260
+ new_activity_result = client.new_activity(session_id, activity)
261
+
262
+ expect(new_activity_result.activityId).to be_truthy
263
+ end
264
+
265
+ it 'HOTELS_PURCHASE' do
266
+ guest = { total: 1, adults: 1, children: 0 }
267
+
268
+ day_ago = (Time.now - (60 * 60 * 24)).iso8601(3)
269
+ stay = { checkin: day_ago, checkout: Time.now.iso8601(3) }
270
+
271
+ invoice = {total: '1', subtotal: '1', currency: 'EUR'}
272
+
273
+ payment = {total: '1', subtotal: '1', currency: 'EUR', source: 'Cash'}
274
+
275
+ tax = {name: 'VAT', total: 1, currency: 'EUR'}
276
+
277
+ # TODO: @Alex: Currency is a int in the schema.
278
+ rate = {date: Time.now.iso8601(3), subtotal: '1', total: '1', currency: '1', tax: tax}
279
+
280
+ name = {prefix: 'prefix', first: 'Wix', middle: 'middle', last: 'Cool', suffix: 'suffix'}
281
+
282
+ customer = {contactId: '1234', isGuest: true, name: name, phone: '12345566', email: 'wix@example.com'}
283
+
284
+ bed = {kind: 'KING', sleeps: 1}
285
+
286
+ # TODO: @Alex: Amenities missing in the schema room object.
287
+ #room = {id: 1, beds: [bed], maxOccupancy: 1}
288
+
289
+ activity = Hive::Activity.new(
290
+ type: FACTORY::HOTELS_PURCHASE.type,
291
+ locationUrl: 'http://www.wix.com',
292
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
293
+ info: { source: 'GUEST', guests: guest, stay: stay, invoice: invoice, rates: [rate], payment: payment, customer: customer, rooms: [] })
294
+
295
+
296
+ new_activity_result = client.new_activity(session_id, activity)
297
+
298
+ expect(new_activity_result.activityId).to be_truthy
299
+ end
300
+
301
+ it 'HOTELS_PURCHASE_FAILED' do
302
+ guest = { total: 1, adults: 1, children: 0 }
303
+
304
+ day_ago = (Time.now - (60 * 60 * 24)).iso8601(3)
305
+ stay = { checkin: day_ago, checkout: Time.now.iso8601(3) }
306
+
307
+ invoice = {total: '1', subtotal: '1', currency: 'EUR'}
308
+
309
+ payment = {total: '1', subtotal: '1', currency: 'EUR', source: 'Cash', error: {errorCode: '-2801'}}
310
+
311
+ activity = Hive::Activity.new(
312
+ type: FACTORY::HOTELS_PURCHASE_FAILED.type,
313
+ locationUrl: 'http://www.wix.com',
314
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
315
+ info: { source: 'GUEST', guests: guest, stay: stay, invoice: invoice, payment: payment })
316
+
317
+ new_activity_result = client.new_activity(session_id, activity)
318
+
319
+ expect(new_activity_result.activityId).to be_truthy
320
+ end
321
+
322
+ it 'SCHEDULER_APPOINTMENT' do
323
+ activity = Hive::Activity.new(
324
+ type: FACTORY::SCHEDULER_APPOINTMENT.type,
325
+ locationUrl: 'http://www.wix.com',
326
+ details: {summary: 'test', additionalInfoUrl: 'http://www.wix.com'},
327
+ info: { title: 'test', description: 'test' })
328
+
329
+ new_activity_result = client.new_activity(session_id, activity)
330
+
331
+ expect(new_activity_result.activityId).to be_truthy
332
+ end
333
+ end
334
+ end
@@ -0,0 +1,364 @@
1
+ require_relative './e2e_helper'
2
+
3
+ describe 'Contacts API' do
4
+ let(:base_contact) {
5
+ contact = Hive::Contact.new
6
+ contact.name.first = 'Wix'
7
+ contact.name.last = 'Cool'
8
+ contact.add_email(email: 'alext@wix.com', tag: 'work')
9
+ contact.add_phone(phone: '123456789', tag: 'work')
10
+ contact
11
+ }
12
+
13
+ it '.new_contact' do
14
+ contact = Hive::Contact.new
15
+ contact.name.first = 'E2E'
16
+ contact.name.last = 'Cool'
17
+ contact.company.name = 'Wix'
18
+ contact.company.role = 'CEO'
19
+ contact.add_email(email: 'alext@wix.com', tag: 'work', emailStatus: 'transactional')
20
+ contact.add_phone(phone: '123456789', tag: 'work')
21
+ contact.add_address(tag: 'home', address: '28208 N Inca St.', neighborhood: 'LODO', city: 'Denver', region: 'CO', country: 'US', postalCode: '80202')
22
+ contact.add_date(date: Time.now.iso8601(3), tag: 'E2E')
23
+ contact.add_url(url: 'wix.com', tag: 'site')
24
+ contact.add_note(content: 'alex')
25
+ contact.add_custom(field: 'custom1', value: 'custom')
26
+ expect(client.new_contact(contact)).to include :contactId
27
+ end
28
+
29
+ it '.contact' do
30
+ expect(client.contact(create_base_contact)).to be_a Hive::Contact
31
+ end
32
+
33
+ context '.contacts' do
34
+ subject(:contacts) { client.contacts }
35
+
36
+ it 'should return a cursor' do
37
+ expect(contacts).to be_a Hive::Cursor
38
+ end
39
+
40
+ it 'should be able to fetch the next page' do
41
+ cursored_result = contacts.next_page
42
+ expect(cursored_result.results.size).to eq 25
43
+ expect(cursored_result.results).not_to eq contacts.results
44
+ expect(cursored_result.nextCursor).not_to eq contacts.nextCursor
45
+ end
46
+
47
+ it 'should be able to fetch the previous page' do
48
+ expect(contacts.next_page.previous_page.results.collect { |r| r.id }).to eq contacts.results.collect { |r| r.id }
49
+ end
50
+
51
+ it 'should be able to fetch the next 50 results given a pageSize' do
52
+ expect(client.contacts( pageSize: 50 ).results.size).to eq 50
53
+ end
54
+
55
+ it 'should be able to query by tag' do
56
+ expect(client.contacts( tag: 'contacts_server/new' ).results.size).to be > 0
57
+ end
58
+
59
+ it 'should be able to query by email' do
60
+ expect(client.contacts( email: 'alext@wix.com' ).results.size).to be > 0
61
+ end
62
+
63
+ it 'should be able to query by phone' do
64
+ expect(client.contacts( phone: '123456789' ).results.size).to be > 0
65
+ end
66
+
67
+ it 'should be able to query by firstName' do
68
+ expect(client.contacts( firstName: 'E2E' ).results.size).to be > 0
69
+ end
70
+
71
+ it 'should be able to query by lastName' do
72
+ expect(client.contacts( lastName:'Cool' ).results.size).to be > 0
73
+ end
74
+ end
75
+
76
+ it '.update_contact' do
77
+ contact = Hive::Contact.new
78
+ contact.name.first = 'E2E'
79
+ contact.name.last = 'Cool'
80
+ contact.add_email(email: 'alext@wix.com', tag: 'work', emailStatus: 'transactional')
81
+ contact.add_address(tag: 'home', address: '28208 N Inca St.', neighborhood: 'LODO', city: 'Denver', region: 'CO', country: 'US', postalCode: '80202')
82
+ contact.add_date(date: Time.now.iso8601(3), tag: 'E2E')
83
+ contact.add_url(url: 'wix.com', tag: 'site')
84
+
85
+ create_response = client.new_contact(contact)
86
+
87
+ expect(create_response).to include :contactId
88
+
89
+ # TODO: @Alex this test is crappy, refactor it.
90
+ contact_update = Hive::Contact.new
91
+ contact_update.add_email(email: 'wow@wix.com', tag: 'wow', emailStatus: 'transactional')
92
+ contact_update.add_address(tag: 'home2', address: '1625 Larimer', neighborhood: 'LODO', city: 'Denver', region: 'CO', country: 'US', postalCode: '80202')
93
+ contact_update.add_date(date: Time.now.iso8601(3), tag: 'E2E UPDATE')
94
+ contact_update.add_url(url: 'wix.com', tag: 'site2')
95
+
96
+ updated_contact = client.update_contact(create_response[:contactId], contact_update)
97
+
98
+ to_hash_without_id = lambda { |o| o.to_hash.tap { |hs| hs.delete(:id) } }
99
+
100
+ expect(updated_contact.emails.collect(&to_hash_without_id)).to include *contact_update.emails
101
+ expect(updated_contact.addresses.collect(&to_hash_without_id)).to include *contact_update.addresses
102
+ expect(updated_contact.urls.collect(&to_hash_without_id)).to include *contact_update.urls
103
+ end
104
+
105
+ context '.upsert_contact' do
106
+ it 'should upsert a contact given a phone' do
107
+ expect(client.upsert_contact(phone: rand(10**10))).to include :contactId
108
+ end
109
+
110
+ it 'should upsert a contact given a email' do
111
+ expect(client.upsert_contact(email: rand(36**10).to_s(36))).to include :contactId
112
+ end
113
+
114
+ it 'should upsert a contact given a email and phone' do
115
+ expect(client.upsert_contact(phone: rand(10**10), email: rand(36**10).to_s(36))).to include :contactId
116
+ end
117
+
118
+ it 'should return a contact given a exiting phone' do
119
+ expect(client.upsert_contact(phone: '123456789', email: 'alext@wix.com')).to include :contactId
120
+ end
121
+ end
122
+
123
+ it '.contacts_tags' do
124
+ pending 'CE-2311'
125
+ expect(client.contacts_tags).to_not be_empty
126
+ end
127
+
128
+ it '.contacts_subscribers' do
129
+ pending 'CE-2280'
130
+ expect(client.contacts_subscribers).to be_a Hive::Cursor
131
+ end
132
+
133
+ it '.update_contact_name' do
134
+ base_contact.name.first = 'Old_Name'
135
+
136
+ contact_id = create_base_contact
137
+
138
+ update_response = client.update_contact_name(contact_id, Hive::Name.new(first: 'New_Name'))
139
+
140
+ expect(update_response.name.first).to eq 'New_Name'
141
+ end
142
+
143
+ it '.update_contact_company' do
144
+
145
+ base_contact.company.name = 'Old_Company'
146
+ base_contact.company.role = 'CEO'
147
+
148
+ contact_id = create_base_contact
149
+
150
+ company = Hive::Company.new
151
+ company.name = 'New_Company'
152
+
153
+ update_response = client.update_contact_company(contact_id, company)
154
+
155
+ expect(update_response.company.name).to eq 'New_Company'
156
+ end
157
+
158
+ it '.update_contact_picture' do
159
+ base_contact.picture = 'http://wix.com/img1.jpg'
160
+
161
+ contact_id = create_base_contact
162
+
163
+ updated_picture = 'wix.com'
164
+
165
+ update_response = client.update_contact_picture(contact_id, updated_picture)
166
+
167
+ expect(update_response.picture).to eq updated_picture
168
+ end
169
+
170
+ it '.update_contact_address' do
171
+ base_contact.add_address(tag: 'home', address: '28208 N Inca St.', neighborhood: 'LODO', city: 'Denver', region: 'CO', country: 'US', postalCode: '80202')
172
+
173
+ contact = client.contact(create_base_contact)
174
+
175
+ updated_address = Hive::Address.new
176
+ updated_address.tag = 'work'
177
+ updated_address.address = '1625 Larimer St.'
178
+
179
+ update_response = client.update_contact_address(contact.id, contact.addresses.first.id, updated_address)
180
+
181
+ expect(update_response.addresses.first.tag).to eq updated_address.tag
182
+ expect(update_response.addresses.first.address).to eq updated_address.address
183
+ end
184
+
185
+ it '.update_contact_email' do
186
+ contact = client.contact(create_base_contact)
187
+
188
+ expect(contact.emails).not_to be_empty
189
+
190
+ updated_email = Hive::Email.new
191
+ updated_email.tag = 'work'
192
+ updated_email.email = 'alex@example.com'
193
+ updated_email.emailStatus = 'optOut'
194
+
195
+ update_response = client.update_contact_email(contact.id, contact.emails.first.id, updated_email)
196
+
197
+ expect(update_response.emails.first.tag).to eq updated_email.tag
198
+ expect(update_response.emails.first.email).to eq updated_email.email
199
+ end
200
+
201
+ it '.update_contact_phone' do
202
+ contact = client.contact(create_base_contact)
203
+
204
+ updated_phone = Hive::Phone.new
205
+ updated_phone.tag = 'work'
206
+ updated_phone.phone = '18006666'
207
+
208
+ update_response = client.update_contact_phone(contact.id, contact.phones.first.id, updated_phone)
209
+
210
+ expect(update_response.phones.first.tag).to eq updated_phone.tag
211
+ expect(update_response.phones.first.phone).to eq updated_phone.phone
212
+ end
213
+
214
+ it '.update_contact_date' do
215
+ base_contact.add_date(date: Time.now.iso8601(3), tag: 'E2E')
216
+
217
+ contact = client.contact(create_base_contact)
218
+
219
+ date = Hive::Date.new
220
+ date.date = Time.now.iso8601(3)
221
+ date.tag = 'update'
222
+
223
+ update_response = client.update_contact_date(contact.id, contact.dates.first.id, date)
224
+
225
+ expect(update_response.dates.first.tag).to eq date.tag
226
+ #Ignore timezones and all just compare the int values.
227
+ expect(update_response.dates.first.date.to_i).to eq date.date.to_i
228
+ end
229
+
230
+ it '.update_contact_note' do
231
+ pending 'CE-2301'
232
+ #base_contact.add_note(content: 'content', modifiedAt: Time.now.iso8601(3))
233
+ contact = client.contact(create_base_contact)
234
+
235
+ note = Hive::Note.new
236
+ note.content = 'Note'
237
+ note.modifiedAt = Time.now.iso8601(3)
238
+
239
+ update_response = client.update_contact_phone(contact.id, contact.notes.first.id, note)
240
+
241
+ expect(update_response.notes.first.content).to eq note
242
+ end
243
+
244
+ it '.update_contact_custom' do
245
+ pending 'CE-2301'
246
+ contact = client.contact(create_base_contact)
247
+
248
+ custom = Hive::Custom.new
249
+ custom.field = 'custom_update'
250
+ custom.value = 'custom_value'
251
+
252
+ update_response = client.update_contact_phone(contact.id, contact.custom.first.id, custom)
253
+
254
+ expect(update_response.custom.first.field).to eq custom.field
255
+ expect(update_response.custom.first.content).to eq custom.value
256
+ end
257
+
258
+ it '.add_contact_address' do
259
+ new_address = Hive::Address.new
260
+ new_address.tag = 'work'
261
+ new_address.address = '1625 Larimer St.'
262
+
263
+ add_response = client.add_contact_address(create_base_contact, new_address)
264
+
265
+ expect(add_response.addresses.last.tag).to eq new_address.tag
266
+ expect(add_response.addresses.last.address).to eq new_address.address
267
+ end
268
+
269
+ it '.add_contact_email' do
270
+ new_email = Hive::Email.new
271
+ new_email.tag = 'work_new'
272
+ new_email.email = 'alex_new@example.com'
273
+ new_email.emailStatus = 'optOut'
274
+
275
+ add_response = client.add_contact_email(create_base_contact, new_email)
276
+
277
+ expect(add_response.emails.last.tag).to eq new_email.tag
278
+ expect(add_response.emails.last.email).to eq new_email.email
279
+ end
280
+
281
+ it '.add_contact_phone' do
282
+ new_phone = Hive::Phone.new
283
+ new_phone.tag = 'work_new'
284
+ new_phone.phone = '18006666'
285
+
286
+ add_response = client.add_contact_phone(create_base_contact, new_phone)
287
+
288
+ expect(add_response.phones.last.tag).to eq new_phone.tag
289
+ expect(add_response.phones.last.phone).to eq new_phone.phone
290
+ end
291
+
292
+ it '.add_contact_note' do
293
+ note = Hive::Note.new
294
+ note.content = 'Note'
295
+
296
+ add_response = client.add_contact_note(create_base_contact, note)
297
+
298
+ expect(add_response.notes.last.content).to eq note.content
299
+ expect(add_response.notes.last.modifiedAt).to eq note.modifiedAt
300
+ end
301
+
302
+ it '.add_contact_custom' do
303
+ custom = Hive::Custom.new
304
+ custom.field = 'custom_update'
305
+ custom.value = 'custom_value'
306
+
307
+ add_response = client.add_contact_custom(create_base_contact, custom)
308
+
309
+ expect(add_response.custom.last.field).to eq custom.field
310
+ expect(add_response.custom.last.value).to eq custom.value
311
+ end
312
+
313
+ it '.add_contact_tags' do
314
+ pending 'CE-2312'
315
+ tags = ['crazy/tag', 'lalala/tag']
316
+
317
+ add_response = client.add_contact_tags(create_base_contact, tags)
318
+
319
+ expect(add_response.tags).to include tags
320
+ end
321
+
322
+ it '.add_contact_activity' do
323
+ contact_id = create_base_contact
324
+
325
+ activity = Hive::Activity.new(
326
+ type: FACTORY::MUSIC_ALBUM_FAN.type,
327
+ locationUrl: 'http://www.wix.com',
328
+ details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
329
+ info: { album: { name: 'Wix', id: '1234' } })
330
+
331
+ update_response = client.add_contact_activity(contact_id, activity)
332
+
333
+ expect(update_response.activityId).to be_truthy
334
+ expect(update_response.contactId).to eq contact_id
335
+ end
336
+
337
+ it '.contact_activities' do
338
+ contact_id = create_base_contact
339
+
340
+ activity = Hive::Activity.new(
341
+ type: FACTORY::MUSIC_ALBUM_FAN.type,
342
+ locationUrl: 'http://www.wix.com',
343
+ details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
344
+ info: { album: { name: 'Wix', id: '1234' } })
345
+
346
+ update_response = client.add_contact_activity(contact_id, activity)
347
+
348
+ expect(update_response.activityId).to be_truthy
349
+
350
+ cursored_result = client.contact_activities(contact_id)
351
+ expect(cursored_result).to be_a Hive::Cursor
352
+ expect(cursored_result.results.first).to be_a Hive::Activity
353
+ end
354
+
355
+ private
356
+
357
+ def create_base_contact
358
+ create_response = client.new_contact(base_contact)
359
+
360
+ expect(create_response).to include :contactId
361
+
362
+ create_response[:contactId]
363
+ end
364
+ end