hubspot-ruby 0.1.8 → 0.2.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 +4 -4
- data/Gemfile +2 -22
- data/Gemfile.lock +14 -11
- data/LICENSE.txt +0 -2
- data/README.md +8 -6
- data/RELEASING.md +4 -5
- data/Rakefile +2 -17
- data/hubspot-ruby.gemspec +20 -157
- data/lib/hubspot-ruby.rb +10 -0
- data/lib/hubspot/blog.rb +1 -2
- data/lib/hubspot/company.rb +149 -0
- data/lib/hubspot/company_properties.rb +59 -0
- data/lib/hubspot/config.rb +10 -4
- data/lib/hubspot/connection.rb +12 -4
- data/lib/hubspot/contact.rb +52 -31
- data/lib/hubspot/contact_list.rb +16 -16
- data/lib/hubspot/contact_properties.rb +53 -6
- data/lib/hubspot/deal.rb +2 -2
- data/lib/hubspot/deal_pipeline.rb +43 -0
- data/lib/hubspot/deal_properties.rb +59 -0
- data/lib/hubspot/engagement.rb +133 -0
- data/lib/hubspot/exceptions.rb +1 -1
- data/lib/hubspot/form.rb +20 -20
- data/lib/hubspot/owner.rb +49 -0
- data/lib/hubspot/properties.rb +119 -0
- data/lib/hubspot/railtie.rb +10 -0
- data/lib/hubspot/topic.rb +2 -2
- data/lib/hubspot/utils.rb +106 -3
- data/spec/lib/hubspot/blog_spec.rb +2 -0
- data/spec/lib/hubspot/company_properties_spec.rb +239 -0
- data/spec/lib/hubspot/company_spec.rb +190 -0
- data/spec/lib/hubspot/config_spec.rb +1 -1
- data/spec/lib/hubspot/connection_spec.rb +33 -27
- data/spec/lib/hubspot/contact_list_spec.rb +61 -61
- data/spec/lib/hubspot/contact_properties_spec.rb +234 -3
- data/spec/lib/hubspot/contact_spec.rb +140 -71
- data/spec/lib/hubspot/deal_properties_spec.rb +254 -0
- data/spec/lib/hubspot/engagement_spec.rb +87 -0
- data/spec/lib/hubspot/form_spec.rb +72 -60
- data/spec/lib/hubspot/owner_spec.rb +56 -0
- data/spec/lib/hubspot/properties_spec.rb +45 -0
- data/spec/lib/hubspot/topic_spec.rb +0 -1
- data/spec/lib/hubspot/utils_spec.rb +113 -15
- data/spec/lib/tasks/properties_spec.rb +90 -0
- data/spec/live/companies_integration_spec.rb +23 -0
- data/spec/live/companies_properties_integration_spec.rb +120 -0
- data/spec/live/contacts_integration_spec.rb +1 -1
- data/spec/live/contacts_properties_integration_spec.rb +120 -0
- data/spec/live/deal_properties_integration_spec.rb +123 -0
- data/spec/live/deals_integration_spec.rb +1 -1
- data/spec/support/cassette_helper.rb +1 -1
- data/spec/support/tests_helper.rb +3 -3
- metadata +39 -78
- data/.document +0 -5
- data/lib/hubspot/version.rb +0 -9
- data/spec/fixtures/vcr_cassettes/add_contacts_to_lists.yml +0 -281
- data/spec/fixtures/vcr_cassettes/blog_list.yml +0 -180
- data/spec/fixtures/vcr_cassettes/blog_posts.yml +0 -107
- data/spec/fixtures/vcr_cassettes/blog_posts_list.yml +0 -6463
- data/spec/fixtures/vcr_cassettes/contact_create.yml +0 -64
- data/spec/fixtures/vcr_cassettes/contact_create_existing_email.yml +0 -62
- data/spec/fixtures/vcr_cassettes/contact_create_invalid_email.yml +0 -63
- data/spec/fixtures/vcr_cassettes/contact_create_with_params.yml +0 -64
- data/spec/fixtures/vcr_cassettes/contact_destroy.yml +0 -131
- data/spec/fixtures/vcr_cassettes/contact_example.yml +0 -32
- data/spec/fixtures/vcr_cassettes/contact_find_by_email.yml +0 -59
- data/spec/fixtures/vcr_cassettes/contact_find_by_email_batch_mode.yml +0 -509
- data/spec/fixtures/vcr_cassettes/contact_find_by_id.yml +0 -59
- data/spec/fixtures/vcr_cassettes/contact_find_by_id_batch_mode.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_find_by_utk.yml +0 -83
- data/spec/fixtures/vcr_cassettes/contact_find_by_utk_batch_mode.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_list_batch_find.yml +0 -65
- data/spec/fixtures/vcr_cassettes/contact_list_destroy.yml +0 -63
- data/spec/fixtures/vcr_cassettes/contact_list_example.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_list_find.yml +0 -96
- data/spec/fixtures/vcr_cassettes/contact_list_refresh.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_list_update.yml +0 -36
- data/spec/fixtures/vcr_cassettes/contact_update.yml +0 -66
- data/spec/fixtures/vcr_cassettes/contacts_among_list.yml +0 -189
- data/spec/fixtures/vcr_cassettes/create_form.yml +0 -39
- data/spec/fixtures/vcr_cassettes/create_list.yml +0 -36
- data/spec/fixtures/vcr_cassettes/create_list_with_filters.yml +0 -36
- data/spec/fixtures/vcr_cassettes/deal_create.yml +0 -61
- data/spec/fixtures/vcr_cassettes/deal_example.yml +0 -166
- data/spec/fixtures/vcr_cassettes/deal_find.yml +0 -115
- data/spec/fixtures/vcr_cassettes/destroy_deal.yml +0 -221
- data/spec/fixtures/vcr_cassettes/fail_to_create_form.yml +0 -35
- data/spec/fixtures/vcr_cassettes/fail_to_create_list.yml +0 -35
- data/spec/fixtures/vcr_cassettes/field_among_form.yml +0 -34
- data/spec/fixtures/vcr_cassettes/fields_among_form.yml +0 -35
- data/spec/fixtures/vcr_cassettes/find_all_contacts.yml +0 -297
- data/spec/fixtures/vcr_cassettes/find_all_dynamic_lists.yml +0 -104
- data/spec/fixtures/vcr_cassettes/find_all_forms.yml +0 -15378
- data/spec/fixtures/vcr_cassettes/find_all_lists.yml +0 -138
- data/spec/fixtures/vcr_cassettes/find_all_recent_contacts.yml +0 -33
- data/spec/fixtures/vcr_cassettes/find_all_recent_updated_deals.yml +0 -130
- data/spec/fixtures/vcr_cassettes/find_all_stastic_lists.yml +0 -21876
- data/spec/fixtures/vcr_cassettes/form_destroy.yml +0 -64
- data/spec/fixtures/vcr_cassettes/form_example.yml +0 -39
- data/spec/fixtures/vcr_cassettes/form_find.yml +0 -69
- data/spec/fixtures/vcr_cassettes/form_post.yml +0 -31
- data/spec/fixtures/vcr_cassettes/form_submit_data.yml +0 -130
- data/spec/fixtures/vcr_cassettes/form_update.yml +0 -77
- data/spec/fixtures/vcr_cassettes/one_month_blog_posts_filter_state.yml +0 -19127
- data/spec/fixtures/vcr_cassettes/one_month_blog_posts_list.yml +0 -34963
- data/spec/fixtures/vcr_cassettes/remove_contacts_from_lists.yml +0 -315
- data/spec/fixtures/vcr_cassettes/topic_list.yml +0 -48
- data/spec/fixtures/vcr_cassettes/topics_list.yml +0 -86
|
@@ -1,76 +1,109 @@
|
|
|
1
1
|
describe Hubspot::Contact do
|
|
2
2
|
let(:example_contact_hash) do
|
|
3
|
-
VCR.use_cassette(
|
|
4
|
-
HTTParty.get(
|
|
3
|
+
VCR.use_cassette('contact_example', record: :none) do
|
|
4
|
+
HTTParty.get('https://api.hubapi.com/contacts/v1/contact/email/testingapis@hubspot.com/profile?hapikey=demo').parsed_response
|
|
5
5
|
end
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
before{ Hubspot.configure(hapikey:
|
|
8
|
+
before{ Hubspot.configure(hapikey: 'demo') }
|
|
9
9
|
|
|
10
|
-
describe
|
|
10
|
+
describe '#initialize' do
|
|
11
11
|
subject{ Hubspot::Contact.new(example_contact_hash) }
|
|
12
12
|
it{ should be_an_instance_of Hubspot::Contact }
|
|
13
|
-
its([
|
|
14
|
-
its([
|
|
15
|
-
its([
|
|
16
|
-
its([
|
|
17
|
-
its(:utk){ should ==
|
|
13
|
+
its(['email']){ should == 'testingapis@hubspot.com' }
|
|
14
|
+
its(['firstname']){ should == 'Clint' }
|
|
15
|
+
its(['lastname']){ should == 'Eastwood' }
|
|
16
|
+
its(['phone']){ should == '555-555-5432' }
|
|
17
|
+
its(:utk){ should == '1234567890' }
|
|
18
18
|
its(:vid){ should == 82325 }
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
describe
|
|
22
|
-
cassette
|
|
21
|
+
describe '.create!' do
|
|
22
|
+
cassette 'contact_create'
|
|
23
23
|
let(:params){{}}
|
|
24
24
|
subject{ Hubspot::Contact.create!(email, params) }
|
|
25
|
-
context
|
|
25
|
+
context 'with a new email' do
|
|
26
26
|
let(:email){ "newcontact#{Time.now.to_i}@hsgem.com" }
|
|
27
27
|
it{ should be_an_instance_of Hubspot::Contact }
|
|
28
28
|
its(:email){ should match /newcontact.*@hsgem.com/ } # Due to VCR the email may not match exactly
|
|
29
29
|
|
|
30
|
-
context
|
|
31
|
-
cassette
|
|
30
|
+
context 'and some params' do
|
|
31
|
+
cassette 'contact_create_with_params'
|
|
32
32
|
let(:email){ "newcontact_x_#{Time.now.to_i}@hsgem.com" }
|
|
33
|
-
let(:params){ {firstname:
|
|
34
|
-
its([
|
|
35
|
-
its([
|
|
33
|
+
let(:params){ {firstname: 'Hugh', lastname: 'Jackman' } }
|
|
34
|
+
its(['firstname']){ should == 'Hugh'}
|
|
35
|
+
its(['lastname']){ should == 'Jackman'}
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
|
-
context
|
|
39
|
-
cassette
|
|
40
|
-
let(:email){
|
|
41
|
-
it
|
|
38
|
+
context 'with an existing email' do
|
|
39
|
+
cassette 'contact_create_existing_email'
|
|
40
|
+
let(:email){ 'testingapis@hubspot.com' }
|
|
41
|
+
it 'raises a RequestError' do
|
|
42
42
|
expect{ subject }.to raise_error Hubspot::RequestError
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
-
context
|
|
46
|
-
cassette
|
|
47
|
-
let(:email){
|
|
48
|
-
it
|
|
45
|
+
context 'with an invalid email' do
|
|
46
|
+
cassette 'contact_create_invalid_email'
|
|
47
|
+
let(:email){ 'not_an_email' }
|
|
48
|
+
it 'raises a RequestError' do
|
|
49
49
|
expect{ subject }.to raise_error Hubspot::RequestError
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
describe
|
|
54
|
+
describe '.createOrUpdate' do
|
|
55
|
+
cassette 'contact_create_or_update'
|
|
56
|
+
let(:params){{}}
|
|
57
|
+
subject{ Hubspot::Contact.createOrUpdate(email, params) }
|
|
58
|
+
context 'with a new email' do
|
|
59
|
+
let(:email){ "newcontact#{Time.now.to_i}@hsgem.com" }
|
|
60
|
+
it{ should be_an_instance_of Hubspot::Contact }
|
|
61
|
+
its(:email){ should match /newcontact.*@hsgem.com/ } # Due to VCR the email may not match exactly
|
|
62
|
+
|
|
63
|
+
context 'and some params' do
|
|
64
|
+
cassette 'contact_create_or_update_with_params'
|
|
65
|
+
let(:email){ "newcontact_x_#{Time.now.to_i}@hsgem.com" }
|
|
66
|
+
let(:params){ {firstname: 'Hugh', lastname: 'Jackman' } }
|
|
67
|
+
its(['firstname']){ should == 'Hugh'}
|
|
68
|
+
its(['lastname']){ should == 'Jackman'}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
context 'with an existing email' do
|
|
72
|
+
cassette 'contact_create_or_update_existing_email'
|
|
73
|
+
let(:email){ 'testingapis@hubspot.com' }
|
|
74
|
+
let(:params){ { firstname: 'Hugh', lastname: 'Jackman, Jr.' } }
|
|
75
|
+
its(['firstname']){ should == 'Hugh'}
|
|
76
|
+
its(['lastname']){ should == 'Jackman, Jr.'}
|
|
77
|
+
end
|
|
78
|
+
context 'with an invalid email' do
|
|
79
|
+
cassette 'contact_create_or_update_invalid_email'
|
|
80
|
+
let(:email){ 'not_an_email' }
|
|
81
|
+
it 'raises a RequestError' do
|
|
82
|
+
expect{ subject }.to raise_error Hubspot::RequestError
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe '.find_by_email' do
|
|
55
88
|
context 'given an uniq email' do
|
|
56
|
-
cassette
|
|
89
|
+
cassette 'contact_find_by_email'
|
|
57
90
|
subject{ Hubspot::Contact.find_by_email(email) }
|
|
58
91
|
|
|
59
|
-
context
|
|
60
|
-
let(:email){
|
|
92
|
+
context 'when the contact is found' do
|
|
93
|
+
let(:email){ 'testingapis@hubspot.com' }
|
|
61
94
|
it{ should be_an_instance_of Hubspot::Contact }
|
|
62
95
|
its(:vid){ should == 82325 }
|
|
63
96
|
end
|
|
64
97
|
|
|
65
|
-
context
|
|
66
|
-
it 'raises an error' do
|
|
98
|
+
context 'when the contact cannot be found' do
|
|
99
|
+
it 'raises an error' do
|
|
67
100
|
expect { Hubspot::Contact.find_by_email('notacontact@test.com') }.to raise_error(Hubspot::RequestError)
|
|
68
101
|
end
|
|
69
102
|
end
|
|
70
103
|
end
|
|
71
104
|
|
|
72
|
-
context 'batch mode' do
|
|
73
|
-
cassette
|
|
105
|
+
context 'batch mode' do
|
|
106
|
+
cassette 'contact_find_by_email_batch_mode'
|
|
74
107
|
|
|
75
108
|
it 'find lists of contacts' do
|
|
76
109
|
emails = ['testingapis@hubspot.com', 'testingapisawesomeandstuff@hubspot.com']
|
|
@@ -80,54 +113,61 @@ describe Hubspot::Contact do
|
|
|
80
113
|
end
|
|
81
114
|
end
|
|
82
115
|
|
|
83
|
-
describe
|
|
84
|
-
|
|
85
|
-
|
|
116
|
+
describe '.find_by_id' do
|
|
117
|
+
before do
|
|
118
|
+
@s = StringIO.new
|
|
119
|
+
Hubspot::Config.logger = Logger.new(@s)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context 'given an uniq id' do
|
|
123
|
+
cassette 'contact_find_by_id'
|
|
86
124
|
subject{ Hubspot::Contact.find_by_id(vid) }
|
|
87
125
|
|
|
88
|
-
context
|
|
126
|
+
context 'when the contact is found' do
|
|
89
127
|
let(:vid){ 82325 }
|
|
90
128
|
it{ should be_an_instance_of Hubspot::Contact }
|
|
91
|
-
its(:email){ should ==
|
|
129
|
+
its(:email){ should == 'testingapis@hubspot.com' }
|
|
92
130
|
end
|
|
93
131
|
|
|
94
|
-
context
|
|
132
|
+
context 'when the contact cannot be found' do
|
|
95
133
|
it 'raises an error' do
|
|
96
|
-
expect { Hubspot::Contact.find_by_id(9999999) }.to raise_error(Hubspot::RequestError)
|
|
134
|
+
expect { Hubspot::Contact.find_by_id(9999999) }.to raise_error(Hubspot::RequestError)
|
|
135
|
+
expect(@s.string).to include 'Response: 404'
|
|
97
136
|
end
|
|
98
137
|
end
|
|
99
138
|
end
|
|
100
139
|
|
|
101
|
-
context 'batch mode' do
|
|
102
|
-
cassette
|
|
140
|
+
context 'batch mode' do
|
|
141
|
+
cassette 'contact_find_by_id_batch_mode'
|
|
103
142
|
|
|
104
143
|
# NOTE: error currently appends on API endpoint
|
|
105
144
|
it 'find lists of contacts' do
|
|
106
145
|
expect { Hubspot::Contact.find_by_id([82325]) }.to raise_error(Hubspot::ApiError)
|
|
146
|
+
expect(@s.string).to include('Response: 200')
|
|
107
147
|
end
|
|
108
148
|
end
|
|
109
149
|
end
|
|
110
150
|
|
|
111
|
-
describe
|
|
112
|
-
context 'given an uniq utk' do
|
|
113
|
-
cassette
|
|
151
|
+
describe '.find_by_utk' do
|
|
152
|
+
context 'given an uniq utk' do
|
|
153
|
+
cassette 'contact_find_by_utk'
|
|
114
154
|
subject{ Hubspot::Contact.find_by_utk(utk) }
|
|
115
155
|
|
|
116
|
-
context
|
|
117
|
-
let(:utk){
|
|
156
|
+
context 'when the contact is found' do
|
|
157
|
+
let(:utk){ 'f844d2217850188692f2610c717c2e9b' }
|
|
118
158
|
it{ should be_an_instance_of Hubspot::Contact }
|
|
119
|
-
its(:utk){ should ==
|
|
159
|
+
its(:utk){ should == 'f844d2217850188692f2610c717c2e9b' }
|
|
120
160
|
end
|
|
121
161
|
|
|
122
|
-
context
|
|
123
|
-
it 'raises an error' do
|
|
124
|
-
expect { Hubspot::Contact.find_by_utk(
|
|
162
|
+
context 'when the contact cannot be found' do
|
|
163
|
+
it 'raises an error' do
|
|
164
|
+
expect { Hubspot::Contact.find_by_utk('invalid') }.to raise_error(Hubspot::RequestError)
|
|
125
165
|
end
|
|
126
166
|
end
|
|
127
167
|
end
|
|
128
168
|
|
|
129
|
-
context 'batch mode' do
|
|
130
|
-
cassette
|
|
169
|
+
context 'batch mode' do
|
|
170
|
+
cassette 'contact_find_by_utk_batch_mode'
|
|
131
171
|
|
|
132
172
|
it 'find lists of contacts' do
|
|
133
173
|
utks = ['f844d2217850188692f2610c717c2e9b', 'j94344d22178501692f2610c717c2e9b']
|
|
@@ -136,9 +176,38 @@ describe Hubspot::Contact do
|
|
|
136
176
|
end
|
|
137
177
|
end
|
|
138
178
|
|
|
179
|
+
describe '.search' do
|
|
180
|
+
subject { Hubspot::Contact.search(query, options) }
|
|
181
|
+
|
|
182
|
+
cassette 'contact_search'
|
|
183
|
+
|
|
184
|
+
let(:options) { {} }
|
|
185
|
+
|
|
186
|
+
context 'when query returns contacts' do
|
|
187
|
+
let(:query) { '@hubspot.com' }
|
|
188
|
+
|
|
189
|
+
it { expect(subject['has-more']).to eq(true) }
|
|
190
|
+
it { subject['contacts'].each { |contact| expect(contact).to be_an_instance_of(Hubspot::Contact) } }
|
|
191
|
+
|
|
192
|
+
context 'when query finds more than count, but is limited' do
|
|
193
|
+
let(:options) { { count: 1 } }
|
|
194
|
+
|
|
195
|
+
it { expect(subject['has-more']).to eq(true) }
|
|
196
|
+
it { expect(subject['total'] > 1).to eq(true) }
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context 'when the query returns no results' do
|
|
201
|
+
let(:query) { 'something_that_does_not_exist' }
|
|
202
|
+
|
|
203
|
+
it { expect(subject['total']).to eq(0) }
|
|
204
|
+
it { expect(subject['has-more']).to eq(false) }
|
|
205
|
+
it { expect(subject['contacts']).to be_empty }
|
|
206
|
+
end
|
|
207
|
+
end
|
|
139
208
|
|
|
140
209
|
describe '.all' do
|
|
141
|
-
context 'all contacts' do
|
|
210
|
+
context 'all contacts' do
|
|
142
211
|
cassette 'find_all_contacts'
|
|
143
212
|
|
|
144
213
|
it 'must get the contacts list' do
|
|
@@ -177,7 +246,7 @@ describe Hubspot::Contact do
|
|
|
177
246
|
end
|
|
178
247
|
end
|
|
179
248
|
|
|
180
|
-
context 'recent contacts' do
|
|
249
|
+
context 'recent contacts' do
|
|
181
250
|
cassette 'find_all_recent_contacts'
|
|
182
251
|
|
|
183
252
|
it 'must get the contacts list' do
|
|
@@ -194,45 +263,45 @@ describe Hubspot::Contact do
|
|
|
194
263
|
end
|
|
195
264
|
end
|
|
196
265
|
|
|
197
|
-
describe
|
|
198
|
-
cassette
|
|
266
|
+
describe '#update!' do
|
|
267
|
+
cassette 'contact_update'
|
|
199
268
|
let(:contact){ Hubspot::Contact.new(example_contact_hash) }
|
|
200
|
-
let(:params){ {firstname:
|
|
269
|
+
let(:params){ {firstname: 'Steve', lastname: 'Cunningham'} }
|
|
201
270
|
subject{ contact.update!(params) }
|
|
202
271
|
|
|
203
272
|
it{ should be_an_instance_of Hubspot::Contact }
|
|
204
|
-
its([
|
|
205
|
-
its([
|
|
273
|
+
its(['firstname']){ should == 'Steve' }
|
|
274
|
+
its(['lastname']){ should == 'Cunningham' }
|
|
206
275
|
|
|
207
|
-
context
|
|
208
|
-
let(:contact){ Hubspot::Contact.new({
|
|
209
|
-
it
|
|
276
|
+
context 'when the request is not successful' do
|
|
277
|
+
let(:contact){ Hubspot::Contact.new({'vid' => 'invalid', 'properties' => {}})}
|
|
278
|
+
it 'raises an error' do
|
|
210
279
|
expect{ subject }.to raise_error Hubspot::RequestError
|
|
211
280
|
end
|
|
212
281
|
end
|
|
213
282
|
end
|
|
214
283
|
|
|
215
|
-
describe
|
|
216
|
-
cassette
|
|
284
|
+
describe '#destroy!' do
|
|
285
|
+
cassette 'contact_destroy'
|
|
217
286
|
let(:contact){ Hubspot::Contact.create!("newcontact_y_#{Time.now.to_i}@hsgem.com") }
|
|
218
287
|
subject{ contact.destroy! }
|
|
219
288
|
it { should be_true }
|
|
220
|
-
it
|
|
289
|
+
it 'should be destroyed' do
|
|
221
290
|
subject
|
|
222
291
|
contact.destroyed?.should be_true
|
|
223
292
|
end
|
|
224
|
-
context
|
|
225
|
-
let(:contact){ Hubspot::Contact.new({
|
|
226
|
-
it
|
|
293
|
+
context 'when the request is not successful' do
|
|
294
|
+
let(:contact){ Hubspot::Contact.new({'vid' => 'invalid', 'properties' => {}})}
|
|
295
|
+
it 'raises an error' do
|
|
227
296
|
expect{ subject }.to raise_error Hubspot::RequestError
|
|
228
297
|
contact.destroyed?.should be_false
|
|
229
298
|
end
|
|
230
299
|
end
|
|
231
300
|
end
|
|
232
301
|
|
|
233
|
-
describe
|
|
302
|
+
describe '#destroyed?' do
|
|
234
303
|
let(:contact){ Hubspot::Contact.new(example_contact_hash) }
|
|
235
304
|
subject{ contact }
|
|
236
305
|
its(:destroyed?){ should be_false }
|
|
237
306
|
end
|
|
238
|
-
end
|
|
307
|
+
end
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
describe Hubspot::DealProperties do
|
|
2
|
+
describe '.add_default_parameters' do
|
|
3
|
+
subject { Hubspot::DealProperties.add_default_parameters({}) }
|
|
4
|
+
context 'default parameters' do
|
|
5
|
+
its([:property]) { should == 'email' }
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:example_groups) do
|
|
10
|
+
VCR.use_cassette('deal_groups_example', record: :once) do
|
|
11
|
+
HTTParty.get('https://api.hubapi.com/deals/v1/groups?hapikey=demo').parsed_response
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:example_properties) do
|
|
16
|
+
VCR.use_cassette('deal_properties_example', record: :once) do
|
|
17
|
+
HTTParty.get('https://api.hubapi.com/deals/v1/properties?hapikey=demo').parsed_response
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
before { Hubspot.configure(hapikey: 'demo') }
|
|
22
|
+
|
|
23
|
+
describe 'Properties' do
|
|
24
|
+
describe '.all' do
|
|
25
|
+
context 'with no filter' do
|
|
26
|
+
cassette 'deal_all_properties'
|
|
27
|
+
|
|
28
|
+
it 'should return all properties' do
|
|
29
|
+
expect(Hubspot::DealProperties.all).to eql(example_properties)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
let(:groups) { %w(calltrackinginfo emailinformation) }
|
|
34
|
+
|
|
35
|
+
context 'with included groups' do
|
|
36
|
+
cassette 'deal_properties_in_groups'
|
|
37
|
+
|
|
38
|
+
it 'should return properties for the specified group[s]' do
|
|
39
|
+
response = Hubspot::DealProperties.all({}, { include: groups })
|
|
40
|
+
response.each { |p| expect(groups.include?(p['groupName'])).to be_true }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with excluded groups' do
|
|
45
|
+
cassette 'deal_properties_not_in_groups'
|
|
46
|
+
|
|
47
|
+
it 'should return properties for the non-specified group[s]' do
|
|
48
|
+
response = Hubspot::DealProperties.all({}, { exclude: groups })
|
|
49
|
+
response.each { |p| expect(groups.include?(p['groupName'])).to be_false }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
let(:params) { {
|
|
55
|
+
'name' => 'my_new_property',
|
|
56
|
+
'label' => 'This is my new property',
|
|
57
|
+
'description' => 'How much money do you have?',
|
|
58
|
+
'groupName' => 'dealinformation',
|
|
59
|
+
'type' => 'string',
|
|
60
|
+
'fieldType' => 'text',
|
|
61
|
+
'hidden' => false,
|
|
62
|
+
'options' => [{
|
|
63
|
+
'description' => '',
|
|
64
|
+
'value' => 'Over $50K',
|
|
65
|
+
'readOnly' => false,
|
|
66
|
+
'label' => 'Over $50K',
|
|
67
|
+
'displayOrder' => 0,
|
|
68
|
+
'hidden' => false,
|
|
69
|
+
'doubleData' => 0.0
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
'description' => '',
|
|
73
|
+
'value' => 'Under $50K',
|
|
74
|
+
'readOnly' => false,
|
|
75
|
+
'label' => 'Under $50K',
|
|
76
|
+
'displayOrder' => 1,
|
|
77
|
+
'hidden' => false,
|
|
78
|
+
'doubleData' => 0.0
|
|
79
|
+
}],
|
|
80
|
+
'deleted' => false,
|
|
81
|
+
'displayOrder' => 0,
|
|
82
|
+
'formField' => true,
|
|
83
|
+
'readOnlyValue' => false,
|
|
84
|
+
'readOnlyDefinition' => false,
|
|
85
|
+
'mutableDefinitionNotDeletable' => false,
|
|
86
|
+
'calculated' => false,
|
|
87
|
+
'externalOptions' => false,
|
|
88
|
+
'displayMode' => 'current_value'
|
|
89
|
+
} }
|
|
90
|
+
|
|
91
|
+
describe '.create!' do
|
|
92
|
+
context 'with no valid parameters' do
|
|
93
|
+
cassette 'deal_fail_to_create_property'
|
|
94
|
+
|
|
95
|
+
it 'should return nil' do
|
|
96
|
+
expect(Hubspot::DealProperties.create!({})).to be(nil)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context 'with all valid parameters' do
|
|
101
|
+
cassette 'deal_create_property'
|
|
102
|
+
|
|
103
|
+
it 'should return the valid parameters' do
|
|
104
|
+
response = Hubspot::DealProperties.create!(params)
|
|
105
|
+
expect(Hubspot::DealProperties.same?(params, response)).to be_true
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe '.update!' do
|
|
111
|
+
context 'with no valid parameters' do
|
|
112
|
+
|
|
113
|
+
it 'should return nil ' do
|
|
114
|
+
expect(Hubspot::DealProperties.update!(params['name'], {})).to be(nil)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context 'with mixed parameters' do
|
|
119
|
+
cassette 'deal_update_property'
|
|
120
|
+
|
|
121
|
+
it 'should return the valid parameters' do
|
|
122
|
+
params['description'] = 'What is their favorite flavor?'
|
|
123
|
+
|
|
124
|
+
response = Hubspot::DealProperties.update!(params['name'], params)
|
|
125
|
+
expect(Hubspot::DealProperties.same?(response, params)).to be_true
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe '.delete!' do
|
|
131
|
+
let(:name) { params['name'] }
|
|
132
|
+
|
|
133
|
+
context 'with existing property' do
|
|
134
|
+
cassette 'deal_delete_property'
|
|
135
|
+
|
|
136
|
+
it 'should return nil' do
|
|
137
|
+
expect(Hubspot::DealProperties.delete!(name)).to eq(nil)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
context 'with non-existent property' do
|
|
142
|
+
cassette 'deal_delete_non_property'
|
|
143
|
+
|
|
144
|
+
it 'should raise an error' do
|
|
145
|
+
expect { Hubspot::DealProperties.delete!(name) }.to raise_error(Hubspot::RequestError)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
describe 'Groups' do
|
|
152
|
+
describe '.groups' do
|
|
153
|
+
context 'with no filter' do
|
|
154
|
+
cassette 'deal_all_groups'
|
|
155
|
+
|
|
156
|
+
it 'should return all groups' do
|
|
157
|
+
expect(Hubspot::DealProperties.groups).to eql(example_groups)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
let(:groups) { %w(calltrackinginfo emailinformation) }
|
|
162
|
+
|
|
163
|
+
context 'with included groups' do
|
|
164
|
+
cassette 'deal_groups_included'
|
|
165
|
+
|
|
166
|
+
it 'should return the specified groups' do
|
|
167
|
+
response = Hubspot::DealProperties.groups({}, { include: groups })
|
|
168
|
+
response.each { |p| expect(groups.include?(p['name'])).to be_true }
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
context 'with excluded groups' do
|
|
173
|
+
cassette 'deal_groups_not_excluded'
|
|
174
|
+
|
|
175
|
+
it 'should return groups that were not excluded' do
|
|
176
|
+
response = Hubspot::DealProperties.groups({}, { exclude: groups })
|
|
177
|
+
response.each { |p| expect(groups.include?(p['name'])).to be_false }
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
let(:params) { { 'name' => 'ff_group1', 'displayName' => 'Test Group One', 'displayOrder' => 100, 'badParam' => 99 } }
|
|
183
|
+
|
|
184
|
+
describe '.create_group!' do
|
|
185
|
+
context 'with no valid parameters' do
|
|
186
|
+
it 'should return nil' do
|
|
187
|
+
expect(Hubspot::DealProperties.create_group!({})).to be(nil)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
context 'with mixed parameters' do
|
|
192
|
+
cassette 'deal_create_group'
|
|
193
|
+
|
|
194
|
+
it 'should return the valid parameters' do
|
|
195
|
+
response = Hubspot::DealProperties.create_group!(params)
|
|
196
|
+
expect(Hubspot::DealProperties.same?(response, params)).to be_true
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context 'with some valid parameters' do
|
|
201
|
+
cassette 'deal_create_group_some_params'
|
|
202
|
+
|
|
203
|
+
let(:sub_params) { params.select { |k, _| k != 'displayName' } }
|
|
204
|
+
|
|
205
|
+
it 'should return the valid parameters' do
|
|
206
|
+
params['name'] = 'ff_group234'
|
|
207
|
+
response = Hubspot::DealProperties.create_group!(sub_params)
|
|
208
|
+
expect(Hubspot::DealProperties.same?(response, sub_params)).to be_true
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
describe '.update_group!' do
|
|
214
|
+
context 'with no valid parameters' do
|
|
215
|
+
|
|
216
|
+
it 'should return nil ' do
|
|
217
|
+
expect(Hubspot::DealProperties.update_group!(params['name'], {})).to be(nil)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
context 'with mixed parameters' do
|
|
222
|
+
cassette 'deal_update_group'
|
|
223
|
+
|
|
224
|
+
it 'should return the valid parameters' do
|
|
225
|
+
params['displayName'] = 'Test Group OneA'
|
|
226
|
+
|
|
227
|
+
response = Hubspot::DealProperties.update_group!(params['name'], params)
|
|
228
|
+
expect(Hubspot::DealProperties.same?(response, params)).to be_true
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
describe '.delete_group!' do
|
|
235
|
+
let(:name) { params['name'] }
|
|
236
|
+
|
|
237
|
+
context 'with existing group' do
|
|
238
|
+
cassette 'deal_delete_group'
|
|
239
|
+
|
|
240
|
+
it 'should return nil' do
|
|
241
|
+
expect(Hubspot::DealProperties.delete_group!(name)).to eq(nil)
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
context 'with non-existent group' do
|
|
246
|
+
cassette 'deal_delete_non_group'
|
|
247
|
+
|
|
248
|
+
it 'should raise an error' do
|
|
249
|
+
expect { Hubspot::DealProperties.delete_group!(name) }.to raise_error(Hubspot::RequestError)
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|