hubspot-api-ruby 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -154
- data/Rakefile +0 -2
- data/hubspot-api-ruby.gemspec +5 -7
- data/lib/hubspot/association.rb +106 -0
- data/lib/hubspot/company.rb +2 -13
- data/lib/hubspot/config.rb +14 -9
- data/lib/hubspot/connection.rb +20 -14
- data/lib/hubspot/contact.rb +5 -1
- data/lib/hubspot/contact_list.rb +0 -7
- data/lib/hubspot/custom_event.rb +25 -0
- data/lib/hubspot/deal.rb +53 -32
- data/lib/hubspot/engagement.rb +0 -1
- data/lib/hubspot/exceptions.rb +2 -0
- data/lib/hubspot/file.rb +2 -2
- data/lib/hubspot/meeting.rb +44 -0
- data/lib/hubspot/properties.rb +1 -1
- data/lib/hubspot/railtie.rb +0 -4
- data/lib/hubspot/resource.rb +4 -4
- data/lib/hubspot/utils.rb +0 -30
- data/lib/hubspot-api-ruby.rb +3 -0
- data/spec/lib/hubspot/association_spec.rb +165 -0
- data/spec/lib/hubspot/blog_spec.rb +10 -21
- data/spec/lib/hubspot/company_properties_spec.rb +8 -11
- data/spec/lib/hubspot/company_spec.rb +18 -36
- data/spec/lib/hubspot/config_spec.rb +24 -14
- data/spec/lib/hubspot/connection_spec.rb +44 -55
- data/spec/lib/hubspot/contact_list_spec.rb +82 -71
- data/spec/lib/hubspot/contact_properties_spec.rb +5 -34
- data/spec/lib/hubspot/contact_spec.rb +2 -4
- data/spec/lib/hubspot/custom_event_spec.rb +28 -0
- data/spec/lib/hubspot/deal_pipeline_spec.rb +4 -15
- data/spec/lib/hubspot/deal_properties_spec.rb +11 -58
- data/spec/lib/hubspot/deal_spec.rb +46 -47
- data/spec/lib/hubspot/engagement_spec.rb +21 -40
- data/spec/lib/hubspot/event_spec.rb +3 -2
- data/spec/lib/hubspot/file_spec.rb +16 -30
- data/spec/lib/hubspot/form_spec.rb +34 -34
- data/spec/lib/hubspot/meeting_spec.rb +81 -0
- data/spec/lib/hubspot/owner_spec.rb +2 -3
- data/spec/lib/hubspot/resource_spec.rb +41 -1
- data/spec/lib/hubspot/utils_spec.rb +6 -39
- data/spec/lib/hubspot-ruby_spec.rb +1 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/vcr.rb +4 -6
- metadata +11 -27
- data/lib/tasks/hubspot.rake +0 -53
- data/spec/lib/hubspot/topic_spec.rb +0 -23
- data/spec/lib/tasks/hubspot_spec.rb +0 -119
- data/spec/support/capture_output.rb +0 -21
- data/spec/support/rake.rb +0 -46
- data/spec/support/tests_helper.rb +0 -17
@@ -1,16 +1,38 @@
|
|
1
1
|
describe Hubspot::ContactList do
|
2
|
+
# uncomment if you need to create test data in your panel.
|
3
|
+
# note that sandboxes have a limit of 5 dynamic lists
|
4
|
+
# before(:all) do
|
5
|
+
# VCR.use_cassette("create_all_lists") do
|
6
|
+
# 25.times { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
7
|
+
# 3.times { Hubspot::ContactList.create!(name: SecureRandom.hex, dynamic: true, filters: [[{ operator: "EQ", value: "@hubspot", property: "twitterhandle", type: "string"}]]) }
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
|
2
11
|
let(:example_contact_list_hash) do
|
3
12
|
VCR.use_cassette("contact_list_example") do
|
4
|
-
|
13
|
+
headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
|
14
|
+
response = HTTParty.get("https://api.hubapi.com/contacts/v1/lists/static?count=1", headers: headers).parsed_response
|
15
|
+
response['lists'].first
|
5
16
|
end
|
6
17
|
end
|
7
18
|
|
8
|
-
let(:static_list)
|
9
|
-
|
19
|
+
let(:static_list) do
|
20
|
+
Hubspot::ContactList.create!(name: "static list #{SecureRandom.hex}")
|
21
|
+
end
|
22
|
+
|
23
|
+
shared_examples "count and offset" do |params|
|
24
|
+
it 'returns only the number of objects specified by count' do
|
25
|
+
result = instance_exec(count: 2, ¶ms[:block])
|
26
|
+
expect(result.size).to eql 2
|
10
27
|
|
11
|
-
|
12
|
-
|
13
|
-
|
28
|
+
result = instance_exec(count: 4, ¶ms[:block])
|
29
|
+
expect(result.size).to eql 4
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns objects by a specified offset' do
|
33
|
+
non_offset_objects = instance_exec(count: 2, ¶ms[:block])
|
34
|
+
objects_with_offset = instance_exec(count: 2, offset: 2, ¶ms[:block])
|
35
|
+
expect(non_offset_objects).to_not eql objects_with_offset
|
14
36
|
end
|
15
37
|
end
|
16
38
|
|
@@ -21,25 +43,27 @@ describe Hubspot::ContactList do
|
|
21
43
|
its(:id) { should be_an(Integer) }
|
22
44
|
its(:portal_id) { should be_a(Integer) }
|
23
45
|
its(:name) { should_not be_empty }
|
24
|
-
its(:dynamic) { should be
|
46
|
+
its(:dynamic) { should be false }
|
25
47
|
its(:properties) { should be_a(Hash) }
|
26
48
|
end
|
27
49
|
|
28
|
-
before { Hubspot.configure(hapikey: "demo") }
|
29
|
-
|
30
50
|
describe '#contacts' do
|
31
51
|
cassette 'contacts_among_list'
|
32
52
|
|
33
|
-
let(:list) {
|
53
|
+
let(:list) { @list }
|
34
54
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
55
|
+
before(:all) do
|
56
|
+
VCR.use_cassette 'create_and_add_all_contacts' do
|
57
|
+
@list = Hubspot::ContactList.create!(name: "contacts list #{SecureRandom.hex}")
|
58
|
+
25.times do
|
59
|
+
contact = Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com")
|
60
|
+
@list.add(contact)
|
61
|
+
end
|
62
|
+
end
|
39
63
|
end
|
40
64
|
|
41
65
|
it 'returns by default 20 contact lists with paging data' do
|
42
|
-
contact_data = list.contacts({paged: true})
|
66
|
+
contact_data = list.contacts({bypass_cache: true, paged: true})
|
43
67
|
contacts = contact_data['contacts']
|
44
68
|
|
45
69
|
expect(contact_data).to have_key 'vid-offset'
|
@@ -48,16 +72,10 @@ describe Hubspot::ContactList do
|
|
48
72
|
expect(contacts.count).to eql 20
|
49
73
|
contact = contacts.first
|
50
74
|
expect(contact).to be_a(Hubspot::Contact)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'add default properties to the contacts returned' do
|
54
|
-
contact = list.contacts.first
|
55
75
|
expect(contact.email).to_not be_empty
|
56
76
|
end
|
57
77
|
|
58
|
-
|
59
|
-
Hubspot::ContactList.find(1).contacts(params)
|
60
|
-
end
|
78
|
+
it_behaves_like 'count and offset', {block: ->(r) { Hubspot::ContactList.find(list.id).contacts(r) }}
|
61
79
|
end
|
62
80
|
|
63
81
|
describe '.create' do
|
@@ -66,7 +84,7 @@ describe Hubspot::ContactList do
|
|
66
84
|
context 'with all required parameters' do
|
67
85
|
cassette 'create_list'
|
68
86
|
|
69
|
-
let(:name) {
|
87
|
+
let(:name) { "testing list #{SecureRandom.hex}" }
|
70
88
|
it { should be_an_instance_of Hubspot::ContactList }
|
71
89
|
its(:id) { should be_an(Integer) }
|
72
90
|
its(:portal_id) { should be_an(Integer) }
|
@@ -76,7 +94,7 @@ describe Hubspot::ContactList do
|
|
76
94
|
cassette 'create_list_with_filters'
|
77
95
|
|
78
96
|
it 'returns a ContactList object with filters set' do
|
79
|
-
name =
|
97
|
+
name = "list with filters #{SecureRandom.hex}"
|
80
98
|
filters_param = [[{ operator: "EQ", value: "@hubspot", property: "twitterhandle", type: "string"}]]
|
81
99
|
list_with_filters = Hubspot::ContactList.create!({ name: name, filters: filters_param })
|
82
100
|
expect(list_with_filters).to be_a(Hubspot::ContactList)
|
@@ -107,7 +125,7 @@ describe Hubspot::ContactList do
|
|
107
125
|
expect(list.id).to be_an(Integer)
|
108
126
|
end
|
109
127
|
|
110
|
-
|
128
|
+
it_behaves_like 'count and offset', {block: ->(r) { Hubspot::ContactList.all(r) }}
|
111
129
|
end
|
112
130
|
|
113
131
|
context 'static lists' do
|
@@ -115,7 +133,7 @@ describe Hubspot::ContactList do
|
|
115
133
|
|
116
134
|
it 'returns by defaut all the static contact lists' do
|
117
135
|
lists = Hubspot::ContactList.all(static: true)
|
118
|
-
expect(lists.count).to be >
|
136
|
+
expect(lists.count).to be > 2
|
119
137
|
|
120
138
|
list = lists.first
|
121
139
|
expect(list).to be_a(Hubspot::ContactList)
|
@@ -126,9 +144,9 @@ describe Hubspot::ContactList do
|
|
126
144
|
context 'dynamic lists' do
|
127
145
|
cassette 'find_all_dynamic_lists'
|
128
146
|
|
129
|
-
it 'returns by defaut all the
|
147
|
+
it 'returns by defaut all the dynamic contact lists' do
|
130
148
|
lists = Hubspot::ContactList.all(dynamic: true)
|
131
|
-
expect(lists.count).to be >
|
149
|
+
expect(lists.count).to be > 2
|
132
150
|
|
133
151
|
list = lists.first
|
134
152
|
expect(list).to be_a(Hubspot::ContactList)
|
@@ -142,24 +160,28 @@ describe Hubspot::ContactList do
|
|
142
160
|
cassette "contact_list_find"
|
143
161
|
subject { Hubspot::ContactList.find(id) }
|
144
162
|
|
163
|
+
let(:list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
164
|
+
|
145
165
|
context 'when the contact list is found' do
|
146
|
-
let(:id) {
|
166
|
+
let(:id) { list.id.to_i }
|
147
167
|
it { should be_an_instance_of Hubspot::ContactList }
|
148
|
-
its(:name) { should ==
|
168
|
+
its(:name) { should == list.name }
|
149
169
|
|
150
|
-
|
151
|
-
|
170
|
+
context "string id" do
|
171
|
+
let(:id) { list.id.to_s }
|
172
|
+
it { should be_an_instance_of Hubspot::ContactList }
|
173
|
+
end
|
152
174
|
end
|
153
175
|
|
154
176
|
context 'Wrong parameter type given' do
|
155
177
|
it 'raises an error' do
|
156
|
-
expect { Hubspot::ContactList.find(
|
178
|
+
expect { Hubspot::ContactList.find({ foo: :bar }) }.to raise_error(Hubspot::InvalidParams)
|
157
179
|
end
|
158
180
|
end
|
159
181
|
|
160
182
|
context 'when the contact list is not found' do
|
161
183
|
it 'raises an error' do
|
162
|
-
expect { Hubspot::ContactList.find(-1) }.to raise_error(Hubspot::
|
184
|
+
expect { Hubspot::ContactList.find(-1) }.to raise_error(Hubspot::NotFoundError)
|
163
185
|
end
|
164
186
|
end
|
165
187
|
end
|
@@ -167,13 +189,17 @@ describe Hubspot::ContactList do
|
|
167
189
|
context 'given a list of ids' do
|
168
190
|
cassette "contact_list_batch_find"
|
169
191
|
|
192
|
+
let(:list1) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
193
|
+
let(:list2) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
194
|
+
let(:list3) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
195
|
+
|
170
196
|
it 'find lists of contacts' do
|
171
|
-
lists = Hubspot::ContactList.find([
|
197
|
+
lists = Hubspot::ContactList.find([list1.id,list2.id,list3.id])
|
172
198
|
list = lists.first
|
173
199
|
expect(list).to be_a(Hubspot::ContactList)
|
174
|
-
expect(list.id).to be ==
|
175
|
-
expect(lists.second.id).to be ==
|
176
|
-
expect(lists.last.id).to be ==
|
200
|
+
expect(list.id).to be == list1.id
|
201
|
+
expect(lists.second.id).to be == list2.id
|
202
|
+
expect(lists.last.id).to be == list3.id
|
177
203
|
end
|
178
204
|
end
|
179
205
|
end
|
@@ -182,8 +208,8 @@ describe Hubspot::ContactList do
|
|
182
208
|
context "for a static list" do
|
183
209
|
it "adds the contact to the contact list" do
|
184
210
|
VCR.use_cassette("contact_lists/add_contact") do
|
185
|
-
contact = Hubspot::Contact.create("
|
186
|
-
contact_list_params = { name: "my-contacts-list" }
|
211
|
+
contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
|
212
|
+
contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
|
187
213
|
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
188
214
|
|
189
215
|
result = contact_list.add([contact])
|
@@ -198,15 +224,15 @@ describe Hubspot::ContactList do
|
|
198
224
|
context "when the contact already exists in the contact list" do
|
199
225
|
it "returns false" do
|
200
226
|
VCR.use_cassette("contact_lists/add_existing_contact") do
|
201
|
-
contact = Hubspot::Contact.create("
|
227
|
+
contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
|
202
228
|
|
203
|
-
contact_list_params = { name: "my-contacts-list" }
|
229
|
+
contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
|
204
230
|
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
205
231
|
contact_list.add([contact])
|
206
232
|
|
207
233
|
result = contact_list.add([contact])
|
208
234
|
|
209
|
-
expect(result).to be
|
235
|
+
expect(result).to be true
|
210
236
|
|
211
237
|
contact.delete
|
212
238
|
contact_list.destroy!
|
@@ -218,9 +244,9 @@ describe Hubspot::ContactList do
|
|
218
244
|
context "for a dynamic list" do
|
219
245
|
it "raises an error as dynamic lists add contacts via on filters" do
|
220
246
|
VCR.use_cassette("contact_list/add_contact_to_dynamic_list") do
|
221
|
-
contact = Hubspot::Contact.create("
|
247
|
+
contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
|
222
248
|
contact_list_params = {
|
223
|
-
name: "my-contacts-list",
|
249
|
+
name: "my-contacts-list-#{SecureRandom.hex}",
|
224
250
|
dynamic: true,
|
225
251
|
"filters": [
|
226
252
|
[
|
@@ -248,54 +274,39 @@ describe Hubspot::ContactList do
|
|
248
274
|
|
249
275
|
context 'static list' do
|
250
276
|
it 'returns true if removes all contacts in batch mode' do
|
251
|
-
|
252
|
-
|
277
|
+
list = Hubspot::ContactList.new(example_contact_list_hash)
|
278
|
+
contacts = list.contacts(count: 2)
|
279
|
+
expect(list.remove([contacts.first, contacts.last])).to be true
|
253
280
|
end
|
254
281
|
|
255
282
|
it 'returns false if the contact cannot be removed' do
|
256
|
-
contact_not_present_in_list = Hubspot::Contact.new(
|
283
|
+
contact_not_present_in_list = Hubspot::Contact.new(1234)
|
257
284
|
expect(static_list.remove(contact_not_present_in_list)).to be false
|
258
285
|
end
|
259
286
|
end
|
260
|
-
|
261
|
-
context 'dynamic list' do
|
262
|
-
it 'raises error if try to remove a contact from a dynamic list' do
|
263
|
-
contact = dynamic_list.contacts(recent: true, count: 1).first
|
264
|
-
expect { dynamic_list.remove(contact) }.to raise_error(Hubspot::RequestError)
|
265
|
-
end
|
266
|
-
end
|
267
287
|
end
|
268
288
|
|
269
289
|
describe '#update!' do
|
270
290
|
cassette "contact_list_update"
|
271
291
|
|
272
|
-
let(:
|
273
|
-
|
274
|
-
subject { contact_list.update!(params) }
|
292
|
+
let(:params) { { name: "updated list name" } }
|
293
|
+
subject { static_list.update!(params) }
|
275
294
|
|
276
295
|
it { should be_an_instance_of Hubspot::ContactList }
|
277
|
-
its(:name){ should ==
|
296
|
+
its(:name){ should == params[:name] }
|
297
|
+
|
298
|
+
after { static_list.destroy! }
|
278
299
|
end
|
279
300
|
|
280
301
|
describe '#destroy!' do
|
281
302
|
cassette "contact_list_destroy"
|
282
303
|
|
283
|
-
|
284
|
-
subject{ contact_list.destroy! }
|
304
|
+
subject{ static_list.destroy! }
|
285
305
|
it { should be true }
|
286
306
|
|
287
307
|
it "should be destroyed" do
|
288
308
|
subject
|
289
|
-
expect(
|
309
|
+
expect(static_list).to be_destroyed
|
290
310
|
end
|
291
311
|
end
|
292
|
-
|
293
|
-
describe '#refresh' do
|
294
|
-
cassette "contact_list_refresh"
|
295
|
-
|
296
|
-
let(:contact_list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
297
|
-
subject { contact_list.refresh }
|
298
|
-
|
299
|
-
it { should be true }
|
300
|
-
end
|
301
312
|
end
|
@@ -14,29 +14,8 @@ describe Hubspot::ContactProperties do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:example_groups) do
|
18
|
-
VCR.use_cassette('contact_properties/groups_example') do
|
19
|
-
HTTParty.get('https://api.hubapi.com/contacts/v2/groups?hapikey=demo').parsed_response
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:example_properties) do
|
24
|
-
VCR.use_cassette('contact_properties/properties_example') do
|
25
|
-
HTTParty.get('https://api.hubapi.com/contacts/v2/properties?hapikey=demo').parsed_response
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
before { Hubspot.configure(hapikey: 'demo') }
|
30
|
-
|
31
17
|
describe 'Properties' do
|
32
18
|
describe '.all' do
|
33
|
-
context 'with no filter' do
|
34
|
-
cassette 'contact_properties/all_properties'
|
35
|
-
|
36
|
-
it 'should return all properties' do
|
37
|
-
expect(Hubspot::ContactProperties.all).to eql(example_properties)
|
38
|
-
end
|
39
|
-
end
|
40
19
|
|
41
20
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
42
21
|
|
@@ -133,7 +112,7 @@ describe Hubspot::ContactProperties do
|
|
133
112
|
cassette 'contact_properties/delete_non_property'
|
134
113
|
|
135
114
|
it 'should raise an error' do
|
136
|
-
expect { Hubspot::ContactProperties.delete!(name) }.to raise_error(Hubspot::
|
115
|
+
expect { Hubspot::ContactProperties.delete!(name) }.to raise_error(Hubspot::NotFoundError)
|
137
116
|
end
|
138
117
|
end
|
139
118
|
end
|
@@ -141,14 +120,6 @@ describe Hubspot::ContactProperties do
|
|
141
120
|
|
142
121
|
describe 'Groups' do
|
143
122
|
describe '.groups' do
|
144
|
-
context 'with no filter' do
|
145
|
-
cassette 'contact_properties/all_groups'
|
146
|
-
|
147
|
-
it 'should return all groups' do
|
148
|
-
expect(Hubspot::ContactProperties.groups).to eql(example_groups)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
123
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
153
124
|
|
154
125
|
context 'with included groups' do
|
@@ -193,10 +164,10 @@ describe Hubspot::ContactProperties do
|
|
193
164
|
|
194
165
|
let(:sub_params) { params.select { |k, _| k != 'displayName' } }
|
195
166
|
|
196
|
-
it 'should return the valid parameters' do
|
197
|
-
params['name'] =
|
167
|
+
it 'should return the valid parameters' do |example|
|
168
|
+
params['name'] = "ff_group_#{SecureRandom.hex}"
|
198
169
|
response = Hubspot::ContactProperties.create_group!(sub_params)
|
199
|
-
expect(Hubspot::ContactProperties.same?(response, sub_params)).to be true
|
170
|
+
expect(Hubspot::ContactProperties.same?(response.except("name"), sub_params.except("name"))).to be true
|
200
171
|
end
|
201
172
|
end
|
202
173
|
end
|
@@ -237,7 +208,7 @@ describe Hubspot::ContactProperties do
|
|
237
208
|
cassette 'contact_properties/delete_non_group'
|
238
209
|
|
239
210
|
it 'should raise an error' do
|
240
|
-
expect { Hubspot::ContactProperties.delete_group!(name) }.to raise_error(Hubspot::
|
211
|
+
expect { Hubspot::ContactProperties.delete_group!(name) }.to raise_error(Hubspot::NotFoundError)
|
241
212
|
end
|
242
213
|
end
|
243
214
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
RSpec.describe Hubspot::Contact do
|
2
2
|
|
3
|
-
before{ Hubspot.configure(hapikey: 'demo') }
|
4
|
-
|
5
3
|
it_behaves_like "a saveable resource", :contact do
|
6
4
|
def set_property(contact)
|
7
5
|
contact.firstname = "foobar"
|
@@ -35,7 +33,7 @@ RSpec.describe Hubspot::Contact do
|
|
35
33
|
it 'raises an error' do
|
36
34
|
expect {
|
37
35
|
subject
|
38
|
-
}.to raise_error(Hubspot::
|
36
|
+
}.to raise_error(Hubspot::NotFoundError, /contact does not exist/)
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
@@ -211,7 +209,7 @@ RSpec.describe Hubspot::Contact do
|
|
211
209
|
|
212
210
|
let!(:contact1) { create :contact }
|
213
211
|
|
214
|
-
subject { contact1.merge(
|
212
|
+
subject { contact1.merge(contact1.id) }
|
215
213
|
|
216
214
|
it 'raises an error' do
|
217
215
|
expect {
|
@@ -0,0 +1,28 @@
|
|
1
|
+
RSpec.describe Hubspot::CustomEvent do
|
2
|
+
before do
|
3
|
+
Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"),
|
4
|
+
custom_event_prefix: 'foobar')
|
5
|
+
end
|
6
|
+
|
7
|
+
describe '.trigger' do
|
8
|
+
let(:event_name) { 'my_awesome_event' }
|
9
|
+
let(:email) { 'testingapis@hubspot.com' }
|
10
|
+
let(:properties) { { prop_foo: 'bar' } }
|
11
|
+
let(:options) { {} }
|
12
|
+
let(:base_url) { 'https://api.hubapi.com' }
|
13
|
+
let(:url) { "#{base_url}/events/v3/send" }
|
14
|
+
|
15
|
+
subject { described_class.trigger(event_name, email, properties, options) }
|
16
|
+
|
17
|
+
before { stub_request(:post, url).to_return(status: 204, body: JSON.generate({})) }
|
18
|
+
|
19
|
+
it('sends a request to trigger the event') { is_expected.to be true }
|
20
|
+
|
21
|
+
context 'with headers' do
|
22
|
+
let(:headers) { { 'User-Agent' => 'something' } }
|
23
|
+
let(:options) { { headers: headers } }
|
24
|
+
|
25
|
+
it('sends headers') { is_expected.to be true }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
RSpec.describe Hubspot::DealPipeline do
|
2
|
-
before do
|
3
|
-
Hubspot.configure hapikey: 'demo'
|
4
|
-
end
|
5
2
|
|
6
3
|
describe ".find" do
|
7
4
|
it "retrieves a record by id" do
|
8
5
|
VCR.use_cassette("find_deal_pipeline") do
|
9
|
-
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
6
|
+
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
10
7
|
id = deal_pipeline.pipeline_id
|
11
8
|
|
12
9
|
result = Hubspot::DealPipeline.find(deal_pipeline.pipeline_id)
|
13
10
|
|
14
|
-
assert_requested :get, hubspot_api_url("/deals/v1/pipelines/#{id}")
|
15
11
|
expect(result).to be_a(Hubspot::DealPipeline)
|
16
12
|
|
17
13
|
deal_pipeline.destroy!
|
@@ -22,11 +18,10 @@ RSpec.describe Hubspot::DealPipeline do
|
|
22
18
|
describe ".all" do
|
23
19
|
it "returns a list" do
|
24
20
|
VCR.use_cassette("all_deal_pipelines") do
|
25
|
-
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
21
|
+
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
26
22
|
|
27
23
|
results = Hubspot::DealPipeline.all
|
28
24
|
|
29
|
-
assert_requested :get, hubspot_api_url("/deals/v1/pipelines")
|
30
25
|
expect(results).to be_kind_of(Array)
|
31
26
|
expect(results.first).to be_a(Hubspot::DealPipeline)
|
32
27
|
|
@@ -38,9 +33,8 @@ RSpec.describe Hubspot::DealPipeline do
|
|
38
33
|
describe ".create!" do
|
39
34
|
it "creates a new record" do
|
40
35
|
VCR.use_cassette("create_deal_pipeline") do
|
41
|
-
result = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
36
|
+
result = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
42
37
|
|
43
|
-
assert_requested :post, hubspot_api_url("/deals/v1/pipelines")
|
44
38
|
expect(result).to be_a(Hubspot::DealPipeline)
|
45
39
|
|
46
40
|
result.destroy!
|
@@ -51,12 +45,11 @@ RSpec.describe Hubspot::DealPipeline do
|
|
51
45
|
describe "#destroy!" do
|
52
46
|
it "deletes the record" do
|
53
47
|
VCR.use_cassette("delete_deal_pipeline") do
|
54
|
-
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
48
|
+
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
55
49
|
id = deal_pipeline.pipeline_id
|
56
50
|
|
57
51
|
result = deal_pipeline.destroy!
|
58
52
|
|
59
|
-
assert_requested :delete, hubspot_api_url("/deals/v1/pipelines/#{id}")
|
60
53
|
expect(result).to be_a(HTTParty::Response)
|
61
54
|
end
|
62
55
|
end
|
@@ -78,8 +71,4 @@ RSpec.describe Hubspot::DealPipeline do
|
|
78
71
|
expect(result).to eq(data["stages"][0])
|
79
72
|
end
|
80
73
|
end
|
81
|
-
|
82
|
-
def hubspot_api_url(path)
|
83
|
-
URI.join(Hubspot::Config.base_url, path, "?hapikey=demo")
|
84
|
-
end
|
85
74
|
end
|
@@ -14,30 +14,9 @@ describe Hubspot::DealProperties do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:example_groups) do
|
18
|
-
VCR.use_cassette('deal_groups_example') do
|
19
|
-
HTTParty.get('https://api.hubapi.com/deals/v1/groups?hapikey=demo').parsed_response
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:example_properties) do
|
24
|
-
VCR.use_cassette('deal_properties_example') do
|
25
|
-
HTTParty.get('https://api.hubapi.com/deals/v1/properties?hapikey=demo').parsed_response
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
before { Hubspot.configure(hapikey: 'demo') }
|
30
17
|
|
31
18
|
describe 'Properties' do
|
32
19
|
describe '.all' do
|
33
|
-
context 'with no filter' do
|
34
|
-
cassette 'deal_all_properties'
|
35
|
-
|
36
|
-
it 'should return all properties' do
|
37
|
-
expect(Hubspot::DealProperties.all).to eql(example_properties)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
20
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
42
21
|
|
43
22
|
context 'with included groups' do
|
@@ -60,31 +39,13 @@ describe Hubspot::DealProperties do
|
|
60
39
|
end
|
61
40
|
|
62
41
|
let(:params) { {
|
63
|
-
'name' =>
|
42
|
+
'name' => "my_new_property_#{SecureRandom.hex}",
|
64
43
|
'label' => 'This is my new property',
|
65
44
|
'description' => 'How much money do you have?',
|
66
45
|
'groupName' => 'dealinformation',
|
67
46
|
'type' => 'string',
|
68
47
|
'fieldType' => 'text',
|
69
48
|
'hidden' => false,
|
70
|
-
'options' => [{
|
71
|
-
'description' => '',
|
72
|
-
'value' => 'Over $50K',
|
73
|
-
'readOnly' => false,
|
74
|
-
'label' => 'Over $50K',
|
75
|
-
'displayOrder' => 0,
|
76
|
-
'hidden' => false,
|
77
|
-
'doubleData' => 0.0
|
78
|
-
},
|
79
|
-
{
|
80
|
-
'description' => '',
|
81
|
-
'value' => 'Under $50K',
|
82
|
-
'readOnly' => false,
|
83
|
-
'label' => 'Under $50K',
|
84
|
-
'displayOrder' => 1,
|
85
|
-
'hidden' => false,
|
86
|
-
'doubleData' => 0.0
|
87
|
-
}],
|
88
49
|
'deleted' => false,
|
89
50
|
'displayOrder' => 0,
|
90
51
|
'formField' => true,
|
@@ -110,7 +71,7 @@ describe Hubspot::DealProperties do
|
|
110
71
|
|
111
72
|
it 'should return the valid parameters' do
|
112
73
|
response = Hubspot::DealProperties.create!(params)
|
113
|
-
expect(Hubspot::DealProperties.same?(params, response)).to be true
|
74
|
+
expect(Hubspot::DealProperties.same?(params.except("name"), response.compact.except("name", "options"))).to be true
|
114
75
|
end
|
115
76
|
end
|
116
77
|
end
|
@@ -127,22 +88,22 @@ describe Hubspot::DealProperties do
|
|
127
88
|
cassette 'deal_update_property'
|
128
89
|
|
129
90
|
it 'should return the valid parameters' do
|
91
|
+
properties = Hubspot::DealProperties.create!(params)
|
130
92
|
params['description'] = 'What is their favorite flavor?'
|
131
93
|
|
132
|
-
response = Hubspot::DealProperties.update!(
|
133
|
-
expect(Hubspot::DealProperties.same?(response, params)).to be true
|
94
|
+
response = Hubspot::DealProperties.update!(properties['name'], params)
|
95
|
+
expect(Hubspot::DealProperties.same?(response.compact.except("name"), params.except("name"))).to be true
|
134
96
|
end
|
135
97
|
end
|
136
98
|
end
|
137
99
|
|
138
100
|
describe '.delete!' do
|
139
|
-
let(:name) { params['name'] }
|
140
|
-
|
141
101
|
context 'with existing property' do
|
142
102
|
cassette 'deal_delete_property'
|
143
103
|
|
144
104
|
it 'should return nil' do
|
145
|
-
|
105
|
+
properties = Hubspot::DealProperties.create!(params)
|
106
|
+
expect(Hubspot::DealProperties.delete!(properties["name"])).to eq(nil)
|
146
107
|
end
|
147
108
|
end
|
148
109
|
|
@@ -150,7 +111,7 @@ describe Hubspot::DealProperties do
|
|
150
111
|
cassette 'deal_delete_non_property'
|
151
112
|
|
152
113
|
it 'should raise an error' do
|
153
|
-
expect { Hubspot::DealProperties.delete!(
|
114
|
+
expect { Hubspot::DealProperties.delete!("i_do_not_exist") }.to raise_error(Hubspot::NotFoundError)
|
154
115
|
end
|
155
116
|
end
|
156
117
|
end
|
@@ -158,14 +119,6 @@ describe Hubspot::DealProperties do
|
|
158
119
|
|
159
120
|
describe 'Groups' do
|
160
121
|
describe '.groups' do
|
161
|
-
context 'with no filter' do
|
162
|
-
cassette 'deal_all_groups'
|
163
|
-
|
164
|
-
it 'should return all groups' do
|
165
|
-
expect(Hubspot::DealProperties.groups).to eql(example_groups)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
122
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
170
123
|
|
171
124
|
context 'with included groups' do
|
@@ -211,9 +164,9 @@ describe Hubspot::DealProperties do
|
|
211
164
|
let(:sub_params) { params.select { |k, _| k != 'displayName' } }
|
212
165
|
|
213
166
|
it 'should return the valid parameters' do
|
214
|
-
params['name'] =
|
167
|
+
params['name'] = "ff_group_#{SecureRandom.hex}"
|
215
168
|
response = Hubspot::DealProperties.create_group!(sub_params)
|
216
|
-
expect(Hubspot::DealProperties.same?(response, sub_params)).to be true
|
169
|
+
expect(Hubspot::DealProperties.same?(response.except("name"), sub_params.except("name"))).to be true
|
217
170
|
end
|
218
171
|
end
|
219
172
|
end
|
@@ -254,7 +207,7 @@ describe Hubspot::DealProperties do
|
|
254
207
|
cassette 'deal_delete_non_group'
|
255
208
|
|
256
209
|
it 'should raise an error' do
|
257
|
-
expect { Hubspot::DealProperties.delete_group!(name) }.to raise_error(Hubspot::
|
210
|
+
expect { Hubspot::DealProperties.delete_group!(name) }.to raise_error(Hubspot::NotFoundError)
|
258
211
|
end
|
259
212
|
end
|
260
213
|
end
|