hubspot-api-ruby 0.9.0 → 0.11.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 +30 -10
- data/Rakefile +0 -2
- data/hubspot-api-ruby.gemspec +1 -2
- data/lib/hubspot/company_properties.rb +10 -0
- data/lib/hubspot/config.rb +4 -0
- data/lib/hubspot/contact_properties.rb +10 -0
- data/lib/hubspot/deal_properties.rb +10 -0
- data/lib/hubspot/engagement.rb +0 -1
- data/lib/hubspot/file.rb +2 -2
- data/lib/hubspot/properties.rb +8 -0
- data/lib/hubspot/railtie.rb +0 -4
- data/lib/hubspot/utils.rb +0 -30
- data/spec/lib/hubspot/blog_spec.rb +2 -7
- data/spec/lib/hubspot/company_properties_spec.rb +40 -0
- 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 +21 -33
- data/spec/lib/hubspot/contact_properties_spec.rb +40 -0
- data/spec/lib/hubspot/contact_spec.rb +1 -1
- data/spec/lib/hubspot/custom_event_spec.rb +5 -4
- data/spec/lib/hubspot/deal_properties_spec.rb +40 -0
- data/spec/lib/hubspot/engagement_spec.rb +3 -11
- data/spec/lib/hubspot/event_spec.rb +3 -2
- data/spec/lib/hubspot/file_spec.rb +20 -9
- data/spec/lib/hubspot/form_spec.rb +8 -11
- data/spec/lib/hubspot/meeting_spec.rb +7 -1
- data/spec/lib/hubspot/owner_spec.rb +2 -3
- data/spec/lib/hubspot/utils_spec.rb +6 -39
- data/spec/lib/hubspot-ruby_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/support/vcr.rb +1 -0
- metadata +6 -10
- data/lib/tasks/hubspot.rake +0 -53
- data/spec/lib/tasks/hubspot_spec.rb +0 -119
- data/spec/support/capture_output.rb +0 -21
- data/spec/support/rake.rb +0 -46
@@ -1,18 +1,12 @@
|
|
1
1
|
describe Hubspot::Connection do
|
2
|
-
before do
|
3
|
-
Hubspot.configure hapikey: 'fake'
|
4
|
-
end
|
5
|
-
|
6
2
|
describe ".get_json" do
|
7
3
|
it "returns the parsed response from the GET request" do
|
8
4
|
path = "/some/path"
|
9
5
|
body = { key: "value" }
|
10
6
|
|
11
|
-
stub_request(:get, "https://api.hubapi.com/some/path
|
12
|
-
to_return(status: 200, body: JSON.generate(body))
|
7
|
+
stub_request(:get, "https://api.hubapi.com/some/path").to_return(status: 200, body: JSON.generate(body))
|
13
8
|
|
14
9
|
result = Hubspot::Connection.get_json(path, {})
|
15
|
-
|
16
10
|
expect(result).to eq({ "key" => "value" })
|
17
11
|
end
|
18
12
|
end
|
@@ -22,11 +16,9 @@ describe Hubspot::Connection do
|
|
22
16
|
path = "/some/path"
|
23
17
|
body = { id: 1, name: "ABC" }
|
24
18
|
|
25
|
-
stub_request(:post, "https://api.hubapi.com/some/path?
|
26
|
-
to_return(status: 200, body: JSON.generate(body))
|
19
|
+
stub_request(:post, "https://api.hubapi.com/some/path?name=ABC").to_return(status: 200, body: JSON.generate(body))
|
27
20
|
|
28
21
|
result = Hubspot::Connection.post_json(path, params: { name: "ABC" })
|
29
|
-
|
30
22
|
expect(result).to eq({ "id" => 1, "name" => "ABC" })
|
31
23
|
end
|
32
24
|
end
|
@@ -35,11 +27,9 @@ describe Hubspot::Connection do
|
|
35
27
|
it "returns the response from the DELETE request" do
|
36
28
|
path = "/some/path"
|
37
29
|
|
38
|
-
stub_request(:delete, "https://api.hubapi.com/some/path
|
39
|
-
to_return(status: 204, body: JSON.generate({}))
|
30
|
+
stub_request(:delete, "https://api.hubapi.com/some/path").to_return(status: 204, body: JSON.generate({}))
|
40
31
|
|
41
32
|
result = Hubspot::Connection.delete_json(path, {})
|
42
|
-
|
43
33
|
expect(result.code).to eq(204)
|
44
34
|
end
|
45
35
|
end
|
@@ -49,20 +39,18 @@ describe Hubspot::Connection do
|
|
49
39
|
path = "/some/path"
|
50
40
|
update_options = { params: {}, body: {} }
|
51
41
|
|
52
|
-
stub_request(:put, "https://api.hubapi.com/some/path
|
53
|
-
to_return(status: 200, body: JSON.generate(vid: 123))
|
42
|
+
stub_request(:put, "https://api.hubapi.com/some/path").to_return(status: 200, body: JSON.generate(vid: 123))
|
54
43
|
|
55
44
|
response = Hubspot::Connection.put_json(path, update_options)
|
56
45
|
|
57
46
|
assert_requested(
|
58
47
|
:put,
|
59
|
-
"https://api.hubapi.com/some/path
|
48
|
+
"https://api.hubapi.com/some/path",
|
60
49
|
{
|
61
50
|
body: "{}",
|
62
51
|
headers: { "Content-Type" => "application/json" },
|
63
52
|
}
|
64
53
|
)
|
65
|
-
|
66
54
|
expect(response).to eq({ "vid" => 123 })
|
67
55
|
end
|
68
56
|
|
@@ -72,13 +60,13 @@ describe Hubspot::Connection do
|
|
72
60
|
|
73
61
|
logger = stub_logger
|
74
62
|
|
75
|
-
stub_request(:put, "https://api.hubapi.com/some/path
|
76
|
-
|
63
|
+
stub_request(:put, "https://api.hubapi.com/some/path").to_return(status: 200,
|
64
|
+
body: JSON.generate("response body"))
|
77
65
|
|
78
66
|
Hubspot::Connection.put_json(path, update_options)
|
79
67
|
|
80
68
|
expect(logger).to have_received(:info).with(<<~MSG)
|
81
|
-
Hubspot: https://api.hubapi.com/some/path
|
69
|
+
Hubspot: https://api.hubapi.com/some/path.
|
82
70
|
Body: {}.
|
83
71
|
Response: 200 "response body"
|
84
72
|
MSG
|
@@ -88,8 +76,7 @@ describe Hubspot::Connection do
|
|
88
76
|
path = "/some/path"
|
89
77
|
update_options = { params: {}, body: {} }
|
90
78
|
|
91
|
-
stub_request(:put, "https://api.hubapi.com/some/path
|
92
|
-
to_return(status: 401)
|
79
|
+
stub_request(:put, "https://api.hubapi.com/some/path").to_return(status: 401)
|
93
80
|
|
94
81
|
expect {
|
95
82
|
Hubspot::Connection.put_json(path, update_options)
|
@@ -99,80 +86,85 @@ describe Hubspot::Connection do
|
|
99
86
|
|
100
87
|
context 'private methods' do
|
101
88
|
describe ".generate_url" do
|
102
|
-
let(:path){ "/test/:email/profile" }
|
103
|
-
let(:params){{email: "test"}}
|
104
|
-
let(:options){{}}
|
105
|
-
subject{ Hubspot::Connection.send(:generate_url, path, params, options) }
|
106
|
-
before{ Hubspot.configure(hapikey: "demo", portal_id: "62515") }
|
89
|
+
let(:path) { "/test/:email/profile" }
|
90
|
+
let(:params) { { email: "test" } }
|
91
|
+
let(:options) { {} }
|
92
|
+
subject { Hubspot::Connection.send(:generate_url, path, params, options) }
|
107
93
|
|
108
94
|
it "doesn't modify params" do
|
109
|
-
expect{ subject }.to_not change{params}
|
95
|
+
expect { subject }.to_not change{params}
|
110
96
|
end
|
111
97
|
|
112
98
|
context "with a portal_id param" do
|
113
|
-
let(:path){ "/test/:portal_id/profile" }
|
114
|
-
let(:params){{}}
|
115
|
-
|
99
|
+
let(:path) { "/test/:portal_id/profile" }
|
100
|
+
let(:params) { {} }
|
101
|
+
|
102
|
+
before do
|
103
|
+
Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
|
104
|
+
end
|
105
|
+
|
106
|
+
it { should == "https://api.hubapi.com/test/#{ENV.fetch('HUBSPOT_PORTAL_ID')}/profile" }
|
116
107
|
end
|
117
108
|
|
118
109
|
context "when configure hasn't been called" do
|
119
|
-
before{ Hubspot::Config.reset! }
|
110
|
+
before { Hubspot::Config.reset! }
|
120
111
|
it "raises a config exception" do
|
121
|
-
expect{ subject }.to raise_error Hubspot::ConfigurationError
|
112
|
+
expect { subject }.to raise_error Hubspot::ConfigurationError
|
122
113
|
end
|
123
114
|
end
|
124
115
|
|
125
116
|
context "with interpolations but no params" do
|
126
|
-
let(:params){{}}
|
117
|
+
let(:params) { {} }
|
118
|
+
|
127
119
|
it "raises an interpolation exception" do
|
128
120
|
expect{ subject }.to raise_error Hubspot::MissingInterpolation
|
129
121
|
end
|
130
122
|
end
|
131
123
|
|
132
124
|
context "with an interpolated param" do
|
133
|
-
let(:params){ {email: "email@address.com"} }
|
134
|
-
it{ should == "https://api.hubapi.com/test/email%40address.com/profile
|
125
|
+
let(:params) { { email: "email@address.com" } }
|
126
|
+
it { should == "https://api.hubapi.com/test/email%40address.com/profile" }
|
135
127
|
end
|
136
128
|
|
137
129
|
context "with multiple interpolated params" do
|
138
|
-
let(:path){ "/test/:email/:id/profile" }
|
139
|
-
let(:params){{email: "email@address.com", id: 1234}}
|
140
|
-
it{ should == "https://api.hubapi.com/test/email%40address.com/1234/profile
|
130
|
+
let(:path) { "/test/:email/:id/profile" }
|
131
|
+
let(:params) { { email: "email@address.com", id: 1234 } }
|
132
|
+
it { should == "https://api.hubapi.com/test/email%40address.com/1234/profile" }
|
141
133
|
end
|
142
134
|
|
143
135
|
context "with query params" do
|
144
|
-
let(:params){{email: "email@address.com", id: 1234}}
|
145
|
-
it{ should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234
|
136
|
+
let(:params) { { email: "email@address.com", id: 1234 } }
|
137
|
+
it { should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234" }
|
146
138
|
|
147
139
|
context "containing a time" do
|
148
140
|
let(:start_time) { Time.now }
|
149
|
-
let(:params){{email: "email@address.com", id: 1234, start: start_time}}
|
150
|
-
it{ should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234&start=#{start_time.to_i * 1000}
|
141
|
+
let(:params) { { email: "email@address.com", id: 1234, start: start_time } }
|
142
|
+
it { should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234&start=#{start_time.to_i * 1000}" }
|
151
143
|
end
|
152
144
|
|
153
145
|
context "containing a range" do
|
154
146
|
let(:start_time) { Time.now }
|
155
147
|
let(:end_time) { Time.now + 1.year }
|
156
|
-
let(:params){{email: "email@address.com", id: 1234, created__range: start_time..end_time }
|
157
|
-
it{ should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234&created__range=#{start_time.to_i * 1000}&created__range=#{end_time.to_i * 1000}
|
148
|
+
let(:params) { { email: "email@address.com", id: 1234, created__range: start_time..end_time } }
|
149
|
+
it { should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234&created__range=#{start_time.to_i * 1000}&created__range=#{end_time.to_i * 1000}" }
|
158
150
|
end
|
159
151
|
|
160
152
|
context "containing an array of strings" do
|
161
|
-
let(:path){ "/test/emails" }
|
162
|
-
let(:params){{batch_email: %w(email1@example.com email2@example.com)}}
|
163
|
-
it{ should == "https://api.hubapi.com/test/emails?email=email1%40example.com&email=email2%40example.com
|
153
|
+
let(:path) { "/test/emails" }
|
154
|
+
let(:params) { { batch_email: %w(email1@example.com email2@example.com) } }
|
155
|
+
it { should == "https://api.hubapi.com/test/emails?email=email1%40example.com&email=email2%40example.com" }
|
164
156
|
end
|
165
157
|
end
|
166
158
|
|
167
159
|
context "with options" do
|
168
|
-
let(:options){ {base_url: "https://cool.com",
|
169
|
-
it{ should == "https://cool.com/test/test/profile"}
|
160
|
+
let(:options) { { base_url: "https://cool.com", access_token: false } }
|
161
|
+
it { should == "https://cool.com/test/test/profile" }
|
170
162
|
end
|
171
163
|
|
172
164
|
context "passing Array as parameters for batch mode, key is prefixed with batch_" do
|
173
165
|
let(:path) { Hubspot::ContactList::LIST_BATCH_PATH }
|
174
166
|
let(:params) { { batch_list_id: [1,2,3] } }
|
175
|
-
it{ should == "https://api.hubapi.com/contacts/v1/lists/batch?listId=1&listId=2&listId=3
|
167
|
+
it { should == "https://api.hubapi.com/contacts/v1/lists/batch?listId=1&listId=2&listId=3" }
|
176
168
|
end
|
177
169
|
end
|
178
170
|
end
|
@@ -191,10 +183,7 @@ describe Hubspot::EventConnection do
|
|
191
183
|
let(:headers) { nil }
|
192
184
|
|
193
185
|
subject { described_class.trigger(path, options) }
|
194
|
-
before
|
195
|
-
Hubspot.configure(hapikey: 'demo', portal_id: '62515')
|
196
|
-
allow(described_class).to receive(:get).and_return(true)
|
197
|
-
end
|
186
|
+
before { allow(described_class).to receive(:get).and_return(true) }
|
198
187
|
|
199
188
|
it 'calls get with a custom url' do
|
200
189
|
subject
|
@@ -1,7 +1,18 @@
|
|
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
|
|
@@ -9,12 +20,6 @@ describe Hubspot::ContactList do
|
|
9
20
|
Hubspot::ContactList.create!(name: "static list #{SecureRandom.hex}")
|
10
21
|
end
|
11
22
|
|
12
|
-
let(:example_contact_hash) do
|
13
|
-
VCR.use_cassette("contact_example") do
|
14
|
-
HTTParty.get("https://api.hubapi.com/contacts/v1/contact/email/testingapis@hubspot.com/profile?hapikey=demo").parsed_response
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
23
|
shared_examples "count and offset" do |params|
|
19
24
|
it 'returns only the number of objects specified by count' do
|
20
25
|
result = instance_exec(count: 2, ¶ms[:block])
|
@@ -38,7 +43,7 @@ describe Hubspot::ContactList do
|
|
38
43
|
its(:id) { should be_an(Integer) }
|
39
44
|
its(:portal_id) { should be_a(Integer) }
|
40
45
|
its(:name) { should_not be_empty }
|
41
|
-
its(:dynamic) { should be
|
46
|
+
its(:dynamic) { should be false }
|
42
47
|
its(:properties) { should be_a(Hash) }
|
43
48
|
end
|
44
49
|
|
@@ -57,12 +62,6 @@ describe Hubspot::ContactList do
|
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
|
-
it 'returns by default 20 contact lists' do
|
61
|
-
expect(list.contacts.count).to eql 20
|
62
|
-
contact = list.contacts.first
|
63
|
-
expect(contact).to be_a(Hubspot::Contact)
|
64
|
-
end
|
65
|
-
|
66
65
|
it 'returns by default 20 contact lists with paging data' do
|
67
66
|
contact_data = list.contacts({bypass_cache: true, paged: true})
|
68
67
|
contacts = contact_data['contacts']
|
@@ -73,15 +72,10 @@ describe Hubspot::ContactList do
|
|
73
72
|
expect(contacts.count).to eql 20
|
74
73
|
contact = contacts.first
|
75
74
|
expect(contact).to be_a(Hubspot::Contact)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'add default properties to the contacts returned' do
|
79
|
-
contact = list.contacts.first
|
80
75
|
expect(contact.email).to_not be_empty
|
81
76
|
end
|
82
77
|
|
83
78
|
it_behaves_like 'count and offset', {block: ->(r) { Hubspot::ContactList.find(list.id).contacts(r) }}
|
84
|
-
|
85
79
|
end
|
86
80
|
|
87
81
|
describe '.create' do
|
@@ -119,13 +113,6 @@ describe Hubspot::ContactList do
|
|
119
113
|
end
|
120
114
|
|
121
115
|
describe '.all' do
|
122
|
-
before(:all) do
|
123
|
-
VCR.use_cassette("create_all_lists") do
|
124
|
-
25.times { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
125
|
-
25.times { Hubspot::ContactList.create!(name: SecureRandom.hex, dynamic: true, filters: [[{ operator: "EQ", value: "@hubspot", property: "twitterhandle", type: "string"}]]) }
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
116
|
context 'all list types' do
|
130
117
|
cassette 'find_all_lists'
|
131
118
|
|
@@ -146,7 +133,7 @@ describe Hubspot::ContactList do
|
|
146
133
|
|
147
134
|
it 'returns by defaut all the static contact lists' do
|
148
135
|
lists = Hubspot::ContactList.all(static: true)
|
149
|
-
expect(lists.count).to be >
|
136
|
+
expect(lists.count).to be > 2
|
150
137
|
|
151
138
|
list = lists.first
|
152
139
|
expect(list).to be_a(Hubspot::ContactList)
|
@@ -159,7 +146,7 @@ describe Hubspot::ContactList do
|
|
159
146
|
|
160
147
|
it 'returns by defaut all the dynamic contact lists' do
|
161
148
|
lists = Hubspot::ContactList.all(dynamic: true)
|
162
|
-
expect(lists.count).to be >
|
149
|
+
expect(lists.count).to be > 2
|
163
150
|
|
164
151
|
list = lists.first
|
165
152
|
expect(list).to be_a(Hubspot::ContactList)
|
@@ -173,7 +160,7 @@ describe Hubspot::ContactList do
|
|
173
160
|
cassette "contact_list_find"
|
174
161
|
subject { Hubspot::ContactList.find(id) }
|
175
162
|
|
176
|
-
let(:list) { Hubspot::ContactList.
|
163
|
+
let(:list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
177
164
|
|
178
165
|
context 'when the contact list is found' do
|
179
166
|
let(:id) { list.id.to_i }
|
@@ -188,7 +175,7 @@ describe Hubspot::ContactList do
|
|
188
175
|
|
189
176
|
context 'Wrong parameter type given' do
|
190
177
|
it 'raises an error' do
|
191
|
-
expect { Hubspot::ContactList.find(
|
178
|
+
expect { Hubspot::ContactList.find({ foo: :bar }) }.to raise_error(Hubspot::InvalidParams)
|
192
179
|
end
|
193
180
|
end
|
194
181
|
|
@@ -287,12 +274,13 @@ describe Hubspot::ContactList do
|
|
287
274
|
|
288
275
|
context 'static list' do
|
289
276
|
it 'returns true if removes all contacts in batch mode' do
|
290
|
-
|
291
|
-
|
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
|
292
280
|
end
|
293
281
|
|
294
282
|
it 'returns false if the contact cannot be removed' do
|
295
|
-
contact_not_present_in_list = Hubspot::Contact.new(
|
283
|
+
contact_not_present_in_list = Hubspot::Contact.new(1234)
|
296
284
|
expect(static_list.remove(contact_not_present_in_list)).to be false
|
297
285
|
end
|
298
286
|
end
|
@@ -38,6 +38,26 @@ describe Hubspot::ContactProperties do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
describe '.find' do
|
42
|
+
context 'existing property' do
|
43
|
+
cassette 'contact_properties/existing_property'
|
44
|
+
|
45
|
+
it 'should return a contact property by name if it exists' do
|
46
|
+
response = Hubspot::ContactProperties.find('full_name')
|
47
|
+
expect(response['name']).to eq 'full_name'
|
48
|
+
expect(response['label']).to eq 'Full name'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'non-existent property' do
|
53
|
+
cassette 'contact_properties/non_existent_property'
|
54
|
+
|
55
|
+
it 'should return an error for a missing property' do
|
56
|
+
expect{ Hubspot::ContactProperties.find('this_does_not_exist') }.to raise_error(Hubspot::NotFoundError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
41
61
|
let(:params) { {
|
42
62
|
'name' => 'my_new_property',
|
43
63
|
'label' => 'This is my new property',
|
@@ -141,6 +161,26 @@ describe Hubspot::ContactProperties do
|
|
141
161
|
end
|
142
162
|
end
|
143
163
|
|
164
|
+
describe '.find_group' do
|
165
|
+
context 'existing group' do
|
166
|
+
cassette 'contact_properties/existing_group'
|
167
|
+
|
168
|
+
it 'should return a contact property by name if it exists' do
|
169
|
+
response = Hubspot::ContactProperties.find_group('contactinformation')
|
170
|
+
expect(response['name']).to eq 'contactinformation'
|
171
|
+
expect(response['displayName']).to eq 'Contact information'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'non-existent group' do
|
176
|
+
cassette 'contact_properties/non_existent_group'
|
177
|
+
|
178
|
+
it 'should return an error for a missing group' do
|
179
|
+
expect{ Hubspot::ContactProperties.find_group('this_does_not_exist') }.to raise_error(Hubspot::NotFoundError)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
144
184
|
let(:params) { { 'name' => 'ff_group1', 'displayName' => 'Test Group One', 'displayOrder' => 100, 'badParam' => 99 } }
|
145
185
|
|
146
186
|
describe '.create_group!' do
|
@@ -1,7 +1,8 @@
|
|
1
1
|
RSpec.describe Hubspot::CustomEvent do
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
5
6
|
|
6
7
|
describe '.trigger' do
|
7
8
|
let(:event_name) { 'my_awesome_event' }
|
@@ -9,7 +10,7 @@ RSpec.describe Hubspot::CustomEvent do
|
|
9
10
|
let(:properties) { { prop_foo: 'bar' } }
|
10
11
|
let(:options) { {} }
|
11
12
|
let(:base_url) { 'https://api.hubapi.com' }
|
12
|
-
let(:url) { "#{base_url}/events/v3/send
|
13
|
+
let(:url) { "#{base_url}/events/v3/send" }
|
13
14
|
|
14
15
|
subject { described_class.trigger(event_name, email, properties, options) }
|
15
16
|
|
@@ -37,6 +37,26 @@ describe Hubspot::DealProperties do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
describe '.find' do
|
42
|
+
context 'existing property' do
|
43
|
+
cassette 'deal_properties/existing_property'
|
44
|
+
|
45
|
+
it 'should return a deal property by name if it exists' do
|
46
|
+
response = Hubspot::DealProperties.find('hs_acv')
|
47
|
+
expect(response['name']).to eq 'hs_acv'
|
48
|
+
expect(response['label']).to eq 'Annual contract value'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'non-existent property' do
|
53
|
+
cassette 'deal_properties/non_existent_property'
|
54
|
+
|
55
|
+
it 'should return an error for a missing property' do
|
56
|
+
expect{ Hubspot::DealProperties.find('this_does_not_exist') }.to raise_error(Hubspot::NotFoundError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
40
60
|
|
41
61
|
let(:params) { {
|
42
62
|
'name' => "my_new_property_#{SecureRandom.hex}",
|
@@ -140,6 +160,26 @@ describe Hubspot::DealProperties do
|
|
140
160
|
end
|
141
161
|
end
|
142
162
|
|
163
|
+
describe '.find_group' do
|
164
|
+
context 'existing group' do
|
165
|
+
cassette 'deal_properties/existing_group'
|
166
|
+
|
167
|
+
it 'should return a deal property by name if it exists' do
|
168
|
+
response = Hubspot::DealProperties.find_group('deal_revenue')
|
169
|
+
expect(response['name']).to eq 'deal_revenue'
|
170
|
+
expect(response['displayName']).to eq 'Deal revenue'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'non-existent group' do
|
175
|
+
cassette 'deal_properties/non_existent_group'
|
176
|
+
|
177
|
+
it 'should return an error for a missing group' do
|
178
|
+
expect{ Hubspot::DealProperties.find_group('this_does_not_exist') }.to raise_error(Hubspot::NotFoundError)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
143
183
|
let(:params) { { 'name' => 'ff_group1', 'displayName' => 'Test Group One', 'displayOrder' => 100, 'badParam' => 99 } }
|
144
184
|
|
145
185
|
describe '.create_group!' do
|
@@ -1,22 +1,14 @@
|
|
1
1
|
describe Hubspot::Engagement do
|
2
|
-
|
3
2
|
let(:contact) { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
|
4
3
|
let(:engagement) { Hubspot::EngagementNote.create!(contact.id, "foo") }
|
5
|
-
let(:example_engagement_hash) do
|
6
|
-
VCR.use_cassette("engagement_example") do
|
7
|
-
HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/3981023?hapikey=demo").parsed_response
|
8
|
-
end
|
9
|
-
end
|
10
|
-
let(:example_associated_engagement_hash) do
|
11
|
-
VCR.use_cassette("engagement_associated_example") do
|
12
|
-
HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/58699206?hapikey=demo").parsed_response
|
13
|
-
end
|
14
|
-
end
|
15
4
|
|
16
5
|
# http://developers.hubspot.com/docs/methods/contacts/get_contact
|
17
6
|
|
18
7
|
describe "#initialize" do
|
19
8
|
subject{ Hubspot::Engagement.new(example_engagement_hash) }
|
9
|
+
|
10
|
+
let(:example_engagement_hash) { { 'engagement' => { 'id' => 3981023, 'portalId' => 62515, 'associations' => {} } } }
|
11
|
+
|
20
12
|
it { should be_an_instance_of Hubspot::Engagement }
|
21
13
|
its (:id) { should == 3981023 }
|
22
14
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
describe Hubspot::Event do
|
2
|
-
let(:portal_id) {
|
2
|
+
let(:portal_id) { ENV.fetch("HUBSPOT_PORTAL_ID") }
|
3
3
|
let(:sent_portal_id) { portal_id }
|
4
|
-
|
4
|
+
|
5
|
+
before { Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: portal_id) }
|
5
6
|
|
6
7
|
describe '.trigger' do
|
7
8
|
let(:event_id) { '000000001625' }
|
@@ -1,12 +1,23 @@
|
|
1
|
-
describe Hubspot do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
describe Hubspot::File do
|
2
|
+
let(:example_file_hash) do
|
3
|
+
VCR.use_cassette('file_example') do
|
4
|
+
headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
|
5
|
+
body = {
|
6
|
+
file: File.open(File::NULL, 'r'),
|
7
|
+
options: { access: 'PRIVATE', ttl: 'P1M', overwrite: false }.to_json,
|
8
|
+
folderPath: '/'
|
9
|
+
}
|
10
|
+
url = 'https://api.hubapi.com/filemanager/api/v3/files/upload'
|
11
|
+
HTTParty.post(url, body: body, headers: headers).parsed_response
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".find_by_id" do
|
16
|
+
it "should fetch specific file" do
|
17
|
+
VCR.use_cassette("file_find") do
|
18
|
+
id = example_file_hash['objects'].first['id']
|
19
|
+
file = Hubspot::File.find_by_id(id)
|
20
|
+
file.id.should eq(id)
|
10
21
|
end
|
11
22
|
end
|
12
23
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
describe Hubspot::Form do
|
2
2
|
let(:example_form_hash) do
|
3
3
|
VCR.use_cassette('form_example') do
|
4
|
-
|
4
|
+
guid = Hubspot::Form.all.first.guid
|
5
|
+
headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
|
6
|
+
HTTParty.get("https://api.hubapi.com#{Hubspot::Form::FORMS_PATH}/#{guid}", headers: headers).parsed_response
|
5
7
|
end
|
6
8
|
end
|
7
9
|
|
@@ -29,8 +31,6 @@ describe Hubspot::Form do
|
|
29
31
|
end
|
30
32
|
|
31
33
|
describe '.all' do
|
32
|
-
before { Hubspot.configure(hapikey: 'demo') }
|
33
|
-
|
34
34
|
cassette 'find_all_forms'
|
35
35
|
|
36
36
|
it 'returns all forms' do
|
@@ -42,8 +42,6 @@ describe Hubspot::Form do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe '.find' do
|
45
|
-
before { Hubspot.configure(hapikey: 'demo') }
|
46
|
-
|
47
45
|
cassette 'form_find'
|
48
46
|
subject { Hubspot::Form.find(Hubspot::Form.all.first.guid) }
|
49
47
|
|
@@ -79,7 +77,6 @@ describe Hubspot::Form do
|
|
79
77
|
end
|
80
78
|
|
81
79
|
describe '#fields' do
|
82
|
-
before { Hubspot.configure(hapikey: 'demo') }
|
83
80
|
context 'returning all the fields' do
|
84
81
|
cassette 'fields_among_form'
|
85
82
|
|
@@ -119,11 +116,11 @@ describe Hubspot::Form do
|
|
119
116
|
describe '#submit' do
|
120
117
|
cassette 'form_submit_data'
|
121
118
|
|
122
|
-
let(:form) { Hubspot::Form.
|
119
|
+
let(:form) { Hubspot::Form.all.first }
|
123
120
|
|
124
121
|
context 'with a valid portal id' do
|
125
122
|
before do
|
126
|
-
Hubspot.configure(
|
123
|
+
Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
|
127
124
|
end
|
128
125
|
|
129
126
|
it 'returns true if the form submission is successful' do
|
@@ -135,7 +132,7 @@ describe Hubspot::Form do
|
|
135
132
|
|
136
133
|
context 'with an invalid portal id' do
|
137
134
|
before do
|
138
|
-
Hubspot.configure(
|
135
|
+
Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: "xxx")
|
139
136
|
end
|
140
137
|
|
141
138
|
it 'returns false in case of errors' do
|
@@ -149,7 +146,7 @@ describe Hubspot::Form do
|
|
149
146
|
let(:f) { Hubspot::Form.new('guid' => form.guid) }
|
150
147
|
|
151
148
|
before do
|
152
|
-
Hubspot.configure(
|
149
|
+
Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
|
153
150
|
end
|
154
151
|
|
155
152
|
it 'returns true if the form submission is successful' do
|
@@ -170,8 +167,8 @@ describe Hubspot::Form do
|
|
170
167
|
let(:params) { { name: new_name, redirect: redirect } }
|
171
168
|
subject { form.update!(params) }
|
172
169
|
|
173
|
-
it { should be_an_instance_of Hubspot::Form }
|
174
170
|
it 'updates properties' do
|
171
|
+
should be_an_instance_of Hubspot::Form
|
175
172
|
subject.properties['name'].should start_with('updated form name ')
|
176
173
|
subject.properties['redirect'].should be == redirect
|
177
174
|
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
RSpec.describe Hubspot::Meeting do
|
2
2
|
|
3
|
-
let(:hubspot_owner_id)
|
3
|
+
let(:hubspot_owner_id) do
|
4
|
+
VCR.use_cassette('meeting_owner') do
|
5
|
+
headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
|
6
|
+
owners = HTTParty.get('https://api.hubapi.com/owners/v2/owners', headers: headers).parsed_response
|
7
|
+
owners.first['ownerId']
|
8
|
+
end
|
9
|
+
end
|
4
10
|
let(:hs_meeting_title) { 'hs_meeting_title' }
|
5
11
|
let(:hs_meeting_body) { 'hs_meeting_body' }
|
6
12
|
let(:hs_meeting_start_time) { DateTime.strptime('2022-05-03T10:00:00+01:00', '%Y-%m-%dT%H:%M:%S%z') }
|