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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rubocop.yml +487 -0
- data/.yardopts +6 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +641 -0
- data/Rakefile +33 -0
- data/e2e/activities_api_spec.rb +334 -0
- data/e2e/contacts_api_spec.rb +364 -0
- data/e2e/e2e_helper.rb +35 -0
- data/e2e/insights_api_spec.rb +29 -0
- data/lib/hive/activities/contact/contact_create_activity.rb +109 -0
- data/lib/hive/activities/contact/contact_form_activity.rb +31 -0
- data/lib/hive/activities/conversion/conversion_complete_activity.rb +33 -0
- data/lib/hive/activities/e_commerce/purchase_activity.rb +150 -0
- data/lib/hive/activities/factory.rb +71 -0
- data/lib/hive/activities/hotels/hotels_cancel_activity.rb +52 -0
- data/lib/hive/activities/hotels/hotels_confirmation_activity.rb +133 -0
- data/lib/hive/activities/hotels/hotels_purchase_activity.rb +48 -0
- data/lib/hive/activities/hotels/hotels_purchase_failed_activity.rb +59 -0
- data/lib/hive/activities/messaging/send_activity.rb +75 -0
- data/lib/hive/activities/music/album_fan_activity.rb +36 -0
- data/lib/hive/activities/music/album_share_activity.rb +23 -0
- data/lib/hive/activities/music/track_lyrics_activity.rb +38 -0
- data/lib/hive/activities/music/track_play_activity.rb +31 -0
- data/lib/hive/activities/music/track_played_activity.rb +31 -0
- data/lib/hive/activities/music/track_share_activity.rb +32 -0
- data/lib/hive/activities/music/track_skipped_activity.rb +31 -0
- data/lib/hive/activities/scheduler/scheduler_appointment_activity.rb +73 -0
- data/lib/hive/activity.rb +60 -0
- data/lib/hive/activity_summary.rb +24 -0
- data/lib/hive/connect/request/wix_api_request.rb +92 -0
- data/lib/hive/connect/response/error.rb +88 -0
- data/lib/hive/connect/response/parse_json.rb +29 -0
- data/lib/hive/connect/response/raise_error.rb +17 -0
- data/lib/hive/connect/wix_client.rb +148 -0
- data/lib/hive/contact.rb +153 -0
- data/lib/hive/cursor.rb +48 -0
- data/lib/hive/errors.rb +5 -0
- data/lib/hive/extensions/hashie_hash.rb +16 -0
- data/lib/hive/extensions/hashie_validate_enum.rb +11 -0
- data/lib/hive/rest/activities.rb +55 -0
- data/lib/hive/rest/api.rb +13 -0
- data/lib/hive/rest/contacts.rb +114 -0
- data/lib/hive/rest/insights.rb +17 -0
- data/lib/hive/util.rb +20 -0
- data/lib/hive/version.rb +14 -0
- data/lib/wix-hive-ruby.rb +5 -0
- data/samples/quick_start.rb +49 -0
- data/spec/hive/activities/contact/contact_create_activity_spec.rb +25 -0
- data/spec/hive/activities/contact/contact_form_activity_spec.rb +9 -0
- data/spec/hive/activities/conversion/conversion_complete_activity_spec.rb +9 -0
- data/spec/hive/activities/e_commerce/purchase_activity_spec.rb +19 -0
- data/spec/hive/activities/factory_spec.rb +78 -0
- data/spec/hive/activities/hotels/hotels_cancel_activity_spec.rb +22 -0
- data/spec/hive/activities/hotels/hotels_confirmation_activity_spec.rb +34 -0
- data/spec/hive/activities/hotels/hotels_purchase_activity_spec.rb +22 -0
- data/spec/hive/activities/hotels/hotels_purchase_failed_activity_spec.rb +22 -0
- data/spec/hive/activities/messaging/send_activity_spec.rb +13 -0
- data/spec/hive/activities/scheduler/scheduler_appointment_activity_spec.rb +10 -0
- data/spec/hive/activity_spec.rb +18 -0
- data/spec/hive/connect/request/wix_api_request_spec.rb +54 -0
- data/spec/hive/connect/response/error_spec.rb +31 -0
- data/spec/hive/connect/response/parse_json_spec.rb +28 -0
- data/spec/hive/connect/response/raise_error_spec.rb +19 -0
- data/spec/hive/connect/wix_client_spec.rb +103 -0
- data/spec/hive/contact_spec.rb +148 -0
- data/spec/hive/cursor_spec.rb +75 -0
- data/spec/hive/hashie_hash_spec.rb +23 -0
- data/spec/hive/rest/activities_spec.rb +87 -0
- data/spec/hive/rest/contacts_spec.rb +225 -0
- data/spec/hive/rest/insights_spec.rb +17 -0
- data/spec/hive/util_spec.rb +36 -0
- data/spec/spec_helper.rb +59 -0
- data/wix-hive-ruby.gemspec +38 -0
- metadata +392 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Cursor do
|
4
|
+
|
5
|
+
let(:client) { double(Hive::Client) }
|
6
|
+
let(:wix_request) { double(Hive::Request::WixAPIRequest, client: client, verb: 'get', path: '/path') }
|
7
|
+
subject(:cursor) {described_class.new( {total: '50', pageSize: '25', nextCursor: '2', previousCursor: '1', results: ['mock']}, String, wix_request)}
|
8
|
+
|
9
|
+
context '.next?' do
|
10
|
+
it 'be true when cursor exists' do
|
11
|
+
expect(cursor.next?).to be_truthy
|
12
|
+
end
|
13
|
+
it 'be false when cursor is 0' do
|
14
|
+
cursor.nextCursor = '0'
|
15
|
+
expect(cursor.next?).to be_falsey
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'be false when cursor is nil' do
|
19
|
+
cursor.nextCursor = nil
|
20
|
+
expect(cursor.next?).to be_falsey
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '.previous?' do
|
25
|
+
it 'be true when cursor exists' do
|
26
|
+
expect(cursor.previous?).to be_truthy
|
27
|
+
end
|
28
|
+
it 'be false when cursor is 0' do
|
29
|
+
cursor.previousCursor = '0'
|
30
|
+
expect(cursor.previous?).to be_falsey
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'be false when cursor is nil' do
|
34
|
+
cursor.previousCursor = nil
|
35
|
+
expect(cursor.previous?).to be_falsey
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context '.next_page' do
|
40
|
+
it 'should add the next cursor to the request params' do
|
41
|
+
params = {}
|
42
|
+
expect(wix_request).to receive(:params).and_return(params)
|
43
|
+
expect(wix_request).to receive(:perform_with_cursor).with(String).and_return(double(described_class))
|
44
|
+
|
45
|
+
cursor.next_page
|
46
|
+
|
47
|
+
expect(params).to include cursor: '2'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should throw an error when there is no previous cursor' do
|
51
|
+
cursor.nextCursor = nil
|
52
|
+
|
53
|
+
expect{ cursor.next_page }.to raise_error Hive::CursorOperationError
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
context '.previous_page' do
|
59
|
+
it 'should add the previous cursor to the request params' do
|
60
|
+
params = {}
|
61
|
+
expect(wix_request).to receive(:params).and_return(params)
|
62
|
+
expect(wix_request).to receive(:perform_with_cursor).with(String).and_return(double(described_class))
|
63
|
+
|
64
|
+
cursor.previous_page
|
65
|
+
|
66
|
+
expect(params).to include cursor: '1'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should throw an error when there is no previous cursor' do
|
70
|
+
cursor.previousCursor = nil
|
71
|
+
|
72
|
+
expect{ cursor.previous_page }.to raise_error Hive::CursorOperationError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hashie::Hash do
|
4
|
+
|
5
|
+
context '.flexibly_convert_to_hash' do
|
6
|
+
it 'does not raise an error when a class with property method is provided' do
|
7
|
+
class_with_method = Hive::Activities::Messaging::Recipient.new(method: 'EMAIL', destination: {target: 'localhost'})
|
8
|
+
expect { described_class.new.flexibly_convert_to_hash(class_with_method) }.not_to raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'calls the correct to_hash method' do
|
12
|
+
class WithCustomToHash < Hashie::Dash
|
13
|
+
property :test
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{passed: true}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(described_class.new.flexibly_convert_to_hash(WithCustomToHash.new(test: 'mock'))).to include passed: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::REST::Activities do
|
4
|
+
|
5
|
+
FACTORY = Hive::Activities
|
6
|
+
subject(:activities) { (Class.new { include Hive::Util; include Hive::REST::Activities }).new }
|
7
|
+
|
8
|
+
context '.new_activity' do
|
9
|
+
it 'with a valid activity' do
|
10
|
+
session_token = '1234'
|
11
|
+
|
12
|
+
activity = Hive::Activity.new(
|
13
|
+
type: FACTORY::MUSIC_ALBUM_FAN.type,
|
14
|
+
locationUrl: 'http://www.wix.com',
|
15
|
+
details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
|
16
|
+
info: { album: { name: 'Wix', id: '1234' } })
|
17
|
+
|
18
|
+
expect(activities).to receive(:perform_with_object).with(:post, 'v1/activities', Hive::ActivityResult, body: activity.to_json, params: { userSessionToken: session_token }).and_return(instance_double(Faraday::Response, body: 'mock'))
|
19
|
+
|
20
|
+
activities.new_activity(session_token, activity)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'with a read only activity' do
|
24
|
+
session_token = '1234'
|
25
|
+
|
26
|
+
activity = Hive::Activity.new(
|
27
|
+
type: FACTORY::CONTACTS_CREATE.type,
|
28
|
+
locationUrl: 'http://www.wix.com',
|
29
|
+
details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
|
30
|
+
info: FACTORY::CONTACTS_CREATE.klass.new)
|
31
|
+
|
32
|
+
expect { activities.new_activity(session_token, activity) }.to raise_error ArgumentError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it '.activity' do
|
37
|
+
expect(activities).to receive(:perform_with_object).with(:get, 'v1/activities/id', Hive::Activity).and_return(instance_double(Faraday::Response, body: 'mock'))
|
38
|
+
activities.activity('id')
|
39
|
+
end
|
40
|
+
|
41
|
+
context '.activities' do
|
42
|
+
it 'accepts a pageSize param and it passes it to the request' do
|
43
|
+
expect(activities).to receive(:perform_with_cursor).with(:get, 'v1/activities', Hive::Activity, {params: {pageSize: 50}}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
44
|
+
activities.activities(pageSize: 50)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'accepts activityTypes parameter and transforms it before passing it to the request' do
|
48
|
+
expect(activities).to receive(:perform_with_cursor).with(:get, 'v1/activities', Hive::Activity, {params: {activityTypes: 'type1,type2'}}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
49
|
+
activities.activities(activityTypes: %w(type1 type2))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context '.add_contact_activity' do
|
54
|
+
it 'with valid activity' do
|
55
|
+
contact_id = '1234'
|
56
|
+
|
57
|
+
activity = Hive::Activity.new(
|
58
|
+
type: FACTORY::MUSIC_ALBUM_FAN.type,
|
59
|
+
locationUrl: 'http://www.wix.com',
|
60
|
+
details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
|
61
|
+
info: { album: { name: 'Wix', id: '1234' } })
|
62
|
+
|
63
|
+
expect(activities).to receive(:perform_with_object).with(:post, "v1/contacts/#{contact_id}/activities", Hive::ActivityResult, body: activity.to_json).and_return(instance_double(Faraday::Response, body: 'mock'))
|
64
|
+
|
65
|
+
activities.add_contact_activity(contact_id, activity)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'with a read only activity' do
|
69
|
+
contact_id = '1234'
|
70
|
+
|
71
|
+
activity = Hive::Activity.new(
|
72
|
+
type: FACTORY::CONTACTS_CREATE.type,
|
73
|
+
locationUrl: 'http://www.wix.com',
|
74
|
+
details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
|
75
|
+
info: FACTORY::CONTACTS_CREATE.klass.new)
|
76
|
+
|
77
|
+
expect { activities.add_contact_activity(contact_id, activity) }.to raise_error ArgumentError
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it '.contact_activities' do
|
82
|
+
contact_id = '1234'
|
83
|
+
|
84
|
+
expect(activities).to receive(:perform_with_cursor).with(:get, "v1/contacts/#{contact_id}/activities", Hive::Activity, {params: {} }).and_return(instance_double(Faraday::Response, body: 'mock'))
|
85
|
+
activities.contact_activities(contact_id)
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::REST::Contacts do
|
4
|
+
|
5
|
+
time_now = Time.now
|
6
|
+
subject(:contacts) { (Class.new { include Hive::Util; include Hive::REST::Contacts }).new }
|
7
|
+
|
8
|
+
it '.contacts' do
|
9
|
+
expect(contacts).to receive(:perform_with_cursor).with(:get, 'v1/contacts', Hive::Contact, {params: {pageSize: 50}}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
10
|
+
contacts.contacts(pageSize: 50)
|
11
|
+
end
|
12
|
+
|
13
|
+
it '.contact' do
|
14
|
+
expect(contacts).to receive(:perform_with_object).with(:get, 'v1/contacts/id', Hive::Contact).and_return(instance_double(Faraday::Response, body: 'mock'))
|
15
|
+
contacts.contact('id')
|
16
|
+
end
|
17
|
+
|
18
|
+
it '.new_contact' do
|
19
|
+
contact = double('Contact')
|
20
|
+
expect(contact).to receive(:to_json).and_return('mock')
|
21
|
+
expect(contacts).to receive(:perform_with_object).with(:post, 'v1/contacts', Hashie::Mash, body: 'mock').and_return(instance_double(Faraday::Response, body: 'mock'))
|
22
|
+
contacts.new_contact(contact)
|
23
|
+
end
|
24
|
+
|
25
|
+
context '.upsert_contact' do
|
26
|
+
it 'with phone provided' do
|
27
|
+
expect(contacts).to receive(:perform_with_object).with(:put, 'v1/contacts', Hashie::Mash, body: '{"phone":"123456789"}').and_return(instance_double(Faraday::Response, body: 'mock'))
|
28
|
+
contacts.upsert_contact(phone: '123456789')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'with email provided' do
|
32
|
+
expect(contacts).to receive(:perform_with_object).with(:put, 'v1/contacts', Hashie::Mash, body: '{"email":"alext@wix.com"}').and_return(instance_double(Faraday::Response, body: 'mock'))
|
33
|
+
contacts.upsert_contact(email: 'alext@wix.com')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'without email or phone' do
|
37
|
+
expect { contacts.upsert_contact(nothing: nil) }.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it '.contacts_tags' do
|
42
|
+
expect(contacts).to receive(:perform_with_object).with(:get, 'v1/contacts/tags', Array).and_return(instance_double(Faraday::Response, body: 'mock'))
|
43
|
+
contacts.contacts_tags
|
44
|
+
end
|
45
|
+
|
46
|
+
it '.contacts_subscribers' do
|
47
|
+
expect(contacts).to receive(:perform_with_cursor).with(:get, 'v1/contacts/subscribers', Hive::ContactSubscriber).and_return(instance_double(Faraday::Response, body: 'mock'))
|
48
|
+
contacts.contacts_subscribers
|
49
|
+
end
|
50
|
+
|
51
|
+
it '.update_contact' do
|
52
|
+
id = '1234'
|
53
|
+
contact = double('Contact')
|
54
|
+
|
55
|
+
allow(Time).to receive(:now) { time_now }
|
56
|
+
expect(contact).to receive(:to_json).and_return('mock')
|
57
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{id}", Hive::Contact, body: 'mock', params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
58
|
+
|
59
|
+
pending('HAPI-3')
|
60
|
+
contacts.update_contact(id, contact)
|
61
|
+
end
|
62
|
+
|
63
|
+
it '.update_contact_name' do
|
64
|
+
contact_id = '1234'
|
65
|
+
contact_name = double('ContactName')
|
66
|
+
allow(Time).to receive(:now) { time_now }
|
67
|
+
expect(contact_name).to receive(:to_json).and_return('mock')
|
68
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/name", Hive::Contact, body: 'mock', params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
69
|
+
contacts.update_contact_name(contact_id, contact_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
it '.update_contact_company' do
|
73
|
+
contact_id = '1234'
|
74
|
+
company = Hive::Company.new
|
75
|
+
company.name = 'Wix'
|
76
|
+
allow(Time).to receive(:now) { time_now }
|
77
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/company", Hive::Contact, body: company.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
78
|
+
contacts.update_contact_company(contact_id, company)
|
79
|
+
end
|
80
|
+
|
81
|
+
it '.update_contact_picture' do
|
82
|
+
contact_id = '1234'
|
83
|
+
picture = 'http://example.com/img1.jpg'
|
84
|
+
allow(Time).to receive(:now) { time_now }
|
85
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/picture", Hive::Contact, body: picture.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
86
|
+
contacts.update_contact_picture(contact_id, picture)
|
87
|
+
end
|
88
|
+
|
89
|
+
it '.update_contact_address' do
|
90
|
+
contact_id = '1234'
|
91
|
+
address_id = '5678'
|
92
|
+
address = Hive::Address.new
|
93
|
+
address.address = 'Wix'
|
94
|
+
allow(Time).to receive(:now) { time_now }
|
95
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/address/#{address_id}", Hive::Contact, body: address.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
96
|
+
contacts.update_contact_address(contact_id, address_id, address)
|
97
|
+
end
|
98
|
+
|
99
|
+
it '.update_contact_email' do
|
100
|
+
contact_id = '1234'
|
101
|
+
email_id = '5678'
|
102
|
+
email = Hive::Email.new
|
103
|
+
|
104
|
+
email.tag = 'work'
|
105
|
+
email.email = 'alex@example.com'
|
106
|
+
|
107
|
+
allow(Time).to receive(:now) { time_now }
|
108
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/email/#{email_id}", Hive::Contact, body: email.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
109
|
+
contacts.update_contact_email(contact_id, email_id, email)
|
110
|
+
end
|
111
|
+
|
112
|
+
it '.update_contact_email' do
|
113
|
+
contact_id = '1234'
|
114
|
+
phone_id = '5678'
|
115
|
+
phone = Hive::Phone.new
|
116
|
+
|
117
|
+
phone.tag = 'work'
|
118
|
+
phone.phone = '18006666'
|
119
|
+
|
120
|
+
allow(Time).to receive(:now) { time_now }
|
121
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/phone/#{phone_id}", Hive::Contact, body: phone.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
122
|
+
contacts.update_contact_phone(contact_id, phone_id, phone)
|
123
|
+
end
|
124
|
+
|
125
|
+
it '.update_contact_date' do
|
126
|
+
contact_id = '1234'
|
127
|
+
date_id = '5678'
|
128
|
+
|
129
|
+
date = Hive::Date.new
|
130
|
+
date.date = Time.now.iso8601(3)
|
131
|
+
date.tag = 'update'
|
132
|
+
|
133
|
+
allow(Time).to receive(:now) { time_now }
|
134
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/date/#{date_id}", Hive::Contact, body: date.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
135
|
+
contacts.update_contact_date(contact_id, date_id, date)
|
136
|
+
end
|
137
|
+
|
138
|
+
it '.update_contact_note' do
|
139
|
+
contact_id = '1234'
|
140
|
+
note_id = '5678'
|
141
|
+
note = Hive::Note.new
|
142
|
+
note.content = 'Note'
|
143
|
+
note.modifiedAt = Time.now.iso8601(3)
|
144
|
+
|
145
|
+
allow(Time).to receive(:now) { time_now }
|
146
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/note/#{note_id}", Hive::Contact, body: note.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
147
|
+
contacts.update_contact_note(contact_id, note_id, note)
|
148
|
+
end
|
149
|
+
|
150
|
+
it '.update_contact_custom' do
|
151
|
+
contact_id = '1234'
|
152
|
+
custom_id = '5678'
|
153
|
+
|
154
|
+
custom = Hive::Custom.new
|
155
|
+
custom.field = 'custom_field'
|
156
|
+
custom.value = 'custom_value'
|
157
|
+
|
158
|
+
allow(Time).to receive(:now) { time_now }
|
159
|
+
expect(contacts).to receive(:perform_with_object).with(:put, "v1/contacts/#{contact_id}/custom/#{custom_id}", Hive::Contact, body: custom.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
160
|
+
contacts.update_contact_custom(contact_id, custom_id, custom)
|
161
|
+
end
|
162
|
+
|
163
|
+
it '.add_contact_address' do
|
164
|
+
contact_id = '1234'
|
165
|
+
address = Hive::Address.new
|
166
|
+
address.address = 'Wix'
|
167
|
+
|
168
|
+
allow(Time).to receive(:now) { time_now }
|
169
|
+
expect(contacts).to receive(:perform_with_object).with(:post, "v1/contacts/#{contact_id}/address", Hive::Contact, body: address.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
170
|
+
contacts.add_contact_address(contact_id, address)
|
171
|
+
end
|
172
|
+
|
173
|
+
it '.add_contact_email' do
|
174
|
+
contact_id = '1234'
|
175
|
+
email = Hive::Email.new
|
176
|
+
email.tag = 'work'
|
177
|
+
email.email = 'alex@example.com'
|
178
|
+
|
179
|
+
allow(Time).to receive(:now) { time_now }
|
180
|
+
expect(contacts).to receive(:perform_with_object).with(:post, "v1/contacts/#{contact_id}/email", Hive::Contact, body: email.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
181
|
+
contacts.add_contact_email(contact_id, email)
|
182
|
+
end
|
183
|
+
|
184
|
+
it '.add_contact_email' do
|
185
|
+
contact_id = '1234'
|
186
|
+
phone = Hive::Phone.new
|
187
|
+
phone.tag = 'work'
|
188
|
+
phone.phone = '18006666'
|
189
|
+
|
190
|
+
allow(Time).to receive(:now) { time_now }
|
191
|
+
expect(contacts).to receive(:perform_with_object).with(:post, "v1/contacts/#{contact_id}/phone", Hive::Contact, body: phone.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
192
|
+
contacts.add_contact_phone(contact_id, phone)
|
193
|
+
end
|
194
|
+
|
195
|
+
it '.add_contact_note' do
|
196
|
+
contact_id = '1234'
|
197
|
+
note = Hive::Note.new
|
198
|
+
note.content = 'Note'
|
199
|
+
note.modifiedAt = Time.now.iso8601(3)
|
200
|
+
|
201
|
+
allow(Time).to receive(:now) { time_now }
|
202
|
+
expect(contacts).to receive(:perform_with_object).with(:post, "v1/contacts/#{contact_id}/note", Hive::Contact, body: note.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
203
|
+
contacts.add_contact_note(contact_id, note)
|
204
|
+
end
|
205
|
+
|
206
|
+
it '.add_contact_custom' do
|
207
|
+
contact_id = '1234'
|
208
|
+
custom = Hive::Custom.new
|
209
|
+
custom.field = 'custom_update'
|
210
|
+
custom.value = 'custom_value'
|
211
|
+
|
212
|
+
allow(Time).to receive(:now) { time_now }
|
213
|
+
expect(contacts).to receive(:perform_with_object).with(:post, "v1/contacts/#{contact_id}/custom", Hive::Contact, body: custom.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
214
|
+
contacts.add_contact_custom(contact_id, custom)
|
215
|
+
end
|
216
|
+
|
217
|
+
it '.add_contact_tags' do
|
218
|
+
contact_id = '1234'
|
219
|
+
tags = ['crazy/tag', 'lalala/tag']
|
220
|
+
|
221
|
+
allow(Time).to receive(:now) { time_now }
|
222
|
+
expect(contacts).to receive(:perform_with_object).with(:post, "v1/contacts/#{contact_id}/tags", Hive::Contact, body: tags.to_json, params: {modifiedAt: time_now.iso8601(3)}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
223
|
+
contacts.add_contact_tags(contact_id, tags)
|
224
|
+
end
|
225
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::REST::Insights do
|
4
|
+
|
5
|
+
subject(:insights) { (Class.new { include Hive::Util; include Hive::REST::Insights }).new }
|
6
|
+
|
7
|
+
it '.activities_summary' do
|
8
|
+
expect(insights).to receive(:perform_with_object).with(:get, 'v1/insights/activities/summary', Hive::ActivitySummary, params: {}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
9
|
+
insights.activities_summary
|
10
|
+
end
|
11
|
+
|
12
|
+
it '.contact_activities_summary' do
|
13
|
+
contact_id = 'id'
|
14
|
+
expect(insights).to receive(:perform_with_object).with(:get, "v1/insights/contacts/#{contact_id}/activities/summary", Hive::ActivitySummary, params: {}).and_return(instance_double(Faraday::Response, body: 'mock'))
|
15
|
+
insights.contact_activities_summary(contact_id)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hive::Util do
|
4
|
+
let(:request) { instance_double(Hive::Request::WixAPIRequest) }
|
5
|
+
let(:mock_response) { instance_double(Faraday::Response, body: 'mock') }
|
6
|
+
subject(:util) { (Class.new { include Hive::Util }).new }
|
7
|
+
|
8
|
+
context '.perform' do
|
9
|
+
it 'should create and perform a request' do
|
10
|
+
expect(Hive::Request::WixAPIRequest).to receive(:new).with(util, 'get', '/path', {}).and_return(request)
|
11
|
+
expect(request).to receive(:perform).and_return(mock_response)
|
12
|
+
|
13
|
+
util.perform('get', '/path')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context '.perform_with_object' do
|
18
|
+
it 'should create and perform a request on the given class' do
|
19
|
+
expect(Hive::Request::WixAPIRequest).to receive(:new).with(util, 'get', '/path', {}).and_return(request)
|
20
|
+
expect(request).to receive(:perform_with_object).with(Hive::Contact).and_return(mock_response)
|
21
|
+
|
22
|
+
util.perform_with_object('get', '/path', Hive::Contact)
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context '.perform_with_cursor' do
|
28
|
+
it 'should create and perform a request and return a cursor' do
|
29
|
+
expect(Hive::Request::WixAPIRequest).to receive(:new).with(util, 'get', '/path', {}).and_return(request)
|
30
|
+
expect(request).to receive(:perform_with_cursor).with(Hive::Contact).and_return(mock_response)
|
31
|
+
|
32
|
+
util.perform_with_cursor('get', '/path', Hive::Contact)
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|