hubspot-api-ruby 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -154
  3. data/Rakefile +0 -2
  4. data/hubspot-api-ruby.gemspec +5 -7
  5. data/lib/hubspot/association.rb +106 -0
  6. data/lib/hubspot/company.rb +2 -13
  7. data/lib/hubspot/config.rb +14 -9
  8. data/lib/hubspot/connection.rb +20 -14
  9. data/lib/hubspot/contact.rb +5 -1
  10. data/lib/hubspot/contact_list.rb +0 -7
  11. data/lib/hubspot/custom_event.rb +25 -0
  12. data/lib/hubspot/deal.rb +53 -32
  13. data/lib/hubspot/engagement.rb +0 -1
  14. data/lib/hubspot/exceptions.rb +2 -0
  15. data/lib/hubspot/file.rb +2 -2
  16. data/lib/hubspot/meeting.rb +44 -0
  17. data/lib/hubspot/properties.rb +1 -1
  18. data/lib/hubspot/railtie.rb +0 -4
  19. data/lib/hubspot/resource.rb +4 -4
  20. data/lib/hubspot/utils.rb +0 -30
  21. data/lib/hubspot-api-ruby.rb +3 -0
  22. data/spec/lib/hubspot/association_spec.rb +165 -0
  23. data/spec/lib/hubspot/blog_spec.rb +10 -21
  24. data/spec/lib/hubspot/company_properties_spec.rb +8 -11
  25. data/spec/lib/hubspot/company_spec.rb +18 -36
  26. data/spec/lib/hubspot/config_spec.rb +24 -14
  27. data/spec/lib/hubspot/connection_spec.rb +44 -55
  28. data/spec/lib/hubspot/contact_list_spec.rb +82 -71
  29. data/spec/lib/hubspot/contact_properties_spec.rb +5 -34
  30. data/spec/lib/hubspot/contact_spec.rb +2 -4
  31. data/spec/lib/hubspot/custom_event_spec.rb +28 -0
  32. data/spec/lib/hubspot/deal_pipeline_spec.rb +4 -15
  33. data/spec/lib/hubspot/deal_properties_spec.rb +11 -58
  34. data/spec/lib/hubspot/deal_spec.rb +46 -47
  35. data/spec/lib/hubspot/engagement_spec.rb +21 -40
  36. data/spec/lib/hubspot/event_spec.rb +3 -2
  37. data/spec/lib/hubspot/file_spec.rb +16 -30
  38. data/spec/lib/hubspot/form_spec.rb +34 -34
  39. data/spec/lib/hubspot/meeting_spec.rb +81 -0
  40. data/spec/lib/hubspot/owner_spec.rb +2 -3
  41. data/spec/lib/hubspot/resource_spec.rb +41 -1
  42. data/spec/lib/hubspot/utils_spec.rb +6 -39
  43. data/spec/lib/hubspot-ruby_spec.rb +1 -1
  44. data/spec/spec_helper.rb +13 -4
  45. data/spec/support/vcr.rb +4 -6
  46. metadata +11 -27
  47. data/lib/tasks/hubspot.rake +0 -53
  48. data/spec/lib/hubspot/topic_spec.rb +0 -23
  49. data/spec/lib/tasks/hubspot_spec.rb +0 -119
  50. data/spec/support/capture_output.rb +0 -21
  51. data/spec/support/rake.rb +0 -46
  52. data/spec/support/tests_helper.rb +0 -17
@@ -1,16 +1,4 @@
1
1
  RSpec.describe Hubspot::Company do
2
- # let(:example_company_hash) do
3
- # VCR.use_cassette("company_example") do
4
- # HTTParty.get("https://api.hubapi.com/companies/v2/companies/21827084?hapikey=demo").parsed_response
5
- # end
6
- # end
7
- # let(:company_with_contacts_hash) do
8
- # VCR.use_cassette("company_with_contacts") do
9
- # HTTParty.get("https://api.hubapi.com/companies/v2/companies/115200636?hapikey=demo").parsed_response
10
- # end
11
- # end
12
-
13
- before{ Hubspot.configure(hapikey: "demo") }
14
2
 
15
3
  it_behaves_like "a saveable resource", :company do
16
4
  def set_property(company)
@@ -42,7 +30,7 @@ RSpec.describe Hubspot::Company do
42
30
  it 'raises an error' do
43
31
  expect {
44
32
  subject
45
- }.to raise_error(Hubspot::RequestError, /resource not found/)
33
+ }.to raise_error(Hubspot::NotFoundError, /resource not found/)
46
34
  end
47
35
  end
48
36
  end
@@ -175,7 +163,7 @@ RSpec.describe Hubspot::Company do
175
163
 
176
164
  expect {
177
165
  described_class.find subject.id
178
- }.to raise_error(Hubspot::RequestError)
166
+ }.to raise_error(Hubspot::NotFoundError)
179
167
  end
180
168
  end
181
169
  end
@@ -279,13 +267,11 @@ RSpec.describe Hubspot::Company do
279
267
  subject { described_class.add_contact company.id, contact.id }
280
268
 
281
269
  it 'returns success' do
282
- expect(subject).to be_truthy
270
+ expect(subject).to be true
283
271
  end
284
272
 
285
273
  it 'adds the contact to the company' do
286
- expect {
287
- subject
288
- }.to change { company.contact_ids }.by([contact.id])
274
+ expect { subject }.to change { company.contact_ids }.by([contact.id])
289
275
  end
290
276
  end
291
277
 
@@ -294,12 +280,10 @@ RSpec.describe Hubspot::Company do
294
280
 
295
281
  let(:company) { create :company }
296
282
 
297
- subject { described_class.add_contact company.id, 1 }
283
+ subject { described_class.add_contact company.id, 1234 }
298
284
 
299
- it 'raises an error' do
300
- expect {
301
- subject
302
- }.to raise_error(Hubspot::RequestError, /Contact with the vid/)
285
+ it 'returns false' do
286
+ expect(subject).to eq(false)
303
287
  end
304
288
  end
305
289
 
@@ -309,32 +293,30 @@ RSpec.describe Hubspot::Company do
309
293
  subject { described_class.add_contact 1, 1 }
310
294
 
311
295
  it 'raises an error' do
312
- expect {
313
- subject
314
- }.to raise_error(Hubspot::RequestError, /company with the ID/)
296
+ expect(subject).to eq(false)
315
297
  end
316
298
  end
317
299
  end
318
300
 
319
301
  describe '.remove_contact' do
320
302
  context 'with a valid company ID and contact ID' do
321
- cassette allow_playback_repeats: true
303
+ cassette
322
304
 
323
- let!(:company) { create :company }
324
- let!(:contact) { create :contact, associatedCompanyId: company.id }
305
+ let(:company) { create :company }
306
+ let(:contact) { create :contact }
325
307
 
308
+ before { described_class.add_contact(company.id, contact.id) }
326
309
  subject { described_class.remove_contact company.id, contact.id }
327
310
 
328
311
  it 'returns success' do
329
- expect(subject).to be_truthy
312
+ expect(subject).to be true
330
313
  end
331
314
 
332
- # Testing this turns out to be hard since using associatedCompanyId doesn't immediately add
333
- # the contact to the company but triggers some background job to perform the update. Since
334
- # we're testing the gem interface and not the API (that's Hubspot's job) this should be OK to
335
- # leave out.
336
- #
337
- # it 'removes the contact from the company'
315
+ it 'removes the contact from the company' do
316
+ expect(company.contact_ids.resources).to eq [contact.id]
317
+ subject
318
+ expect(company.contact_ids.resources).to eq []
319
+ end
338
320
  end
339
321
  end
340
322
  end
@@ -1,26 +1,23 @@
1
1
  describe Hubspot::Config do
2
2
  describe ".configure" do
3
- it "sets the hapikey config" do
4
- hapikey = "demo"
3
+ it "sets the access token config" do
4
+ access_token = "foobar"
5
5
 
6
- config = Hubspot::Config.configure(hapikey: hapikey)
6
+ config = Hubspot::Config.configure(access_token: access_token)
7
7
 
8
- expect(config.hapikey).to eq(hapikey)
8
+ expect(config.access_token).to eq(access_token)
9
9
  end
10
10
 
11
11
  it "changes the base_url" do
12
12
  base_url = "https://api.hubapi.com/v2"
13
13
 
14
- config = Hubspot::Config.configure(
15
- hapikey: "123abc",
16
- base_url: base_url
17
- )
14
+ config = Hubspot::Config.configure(base_url: base_url, access_token: 'foobar')
18
15
 
19
16
  expect(config.base_url).to eq(base_url)
20
17
  end
21
18
 
22
19
  it "sets a default value for base_url" do
23
- config = Hubspot::Config.configure(hapikey: "123abc")
20
+ config = Hubspot::Config.configure(access_token: 'foobar')
24
21
 
25
22
  expect(config.base_url).to eq("https://api.hubapi.com")
26
23
  end
@@ -29,7 +26,7 @@ describe Hubspot::Config do
29
26
  portal_id = "62515"
30
27
 
31
28
  config = Hubspot::Config.configure(
32
- hapikey: "123abc",
29
+ access_token: 'foobar',
33
30
  portal_id: portal_id
34
31
  )
35
32
 
@@ -50,15 +47,28 @@ describe Hubspot::Config do
50
47
  })
51
48
  }.to raise_error(Hubspot::ConfigurationError)
52
49
  end
50
+
51
+ context 'hapikey deprecation' do
52
+ it "sets the hapikey config and sends a deprecation warning" do
53
+ previous, $stderr = $stderr, StringIO.new
54
+
55
+ hapikey = 'demo'
56
+ config = Hubspot::Config.configure(hapikey: hapikey)
57
+ expect(config.hapikey).to eq(hapikey)
58
+ expect($stderr.string).to include 'please use access_token instead.'
59
+ ensure
60
+ $stderr = previous
61
+ end
62
+ end
53
63
  end
54
64
 
55
65
  describe ".reset!" do
56
66
  it "resets the config values" do
57
- Hubspot::Config.configure(hapikey: "123abc", portal_id: "456def")
67
+ Hubspot::Config.configure(access_token: "123abc", portal_id: "456def")
58
68
 
59
69
  Hubspot::Config.reset!
60
70
 
61
- expect(Hubspot::Config.hapikey).to be nil
71
+ expect(Hubspot::Config.access_token).to be nil
62
72
  expect(Hubspot::Config.portal_id).to be nil
63
73
  end
64
74
  end
@@ -66,7 +76,7 @@ describe Hubspot::Config do
66
76
  describe ".ensure!" do
67
77
  context "when a specified parameter is missing" do
68
78
  it "raises an error" do
69
- Hubspot::Config.configure(hapikey: "123abc")
79
+ Hubspot::Config.configure(access_token: "123abc")
70
80
 
71
81
  expect {
72
82
  Hubspot::Config.ensure!(:portal_id)
@@ -76,7 +86,7 @@ describe Hubspot::Config do
76
86
 
77
87
  context "when all specified parameters are present" do
78
88
  it "does not raise an error" do
79
- Hubspot::Config.configure(hapikey: "123abc", portal_id: "456def")
89
+ Hubspot::Config.configure(access_token: "123abc", portal_id: "456def")
80
90
 
81
91
  expect {
82
92
  Hubspot::Config.ensure!(:portal_id)
@@ -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?hapikey=fake").
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?hapikey=fake&name=ABC").
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?hapikey=fake").
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?hapikey=fake").
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?hapikey=fake",
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?hapikey=fake").
76
- to_return(status: 200, body: JSON.generate("response body"))
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?hapikey=fake.
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?hapikey=fake").
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
- it{ should == "https://api.hubapi.com/test/62515/profile?hapikey=demo" }
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?hapikey=demo" }
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?hapikey=demo" }
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&hapikey=demo" }
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}&hapikey=demo" }
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}&hapikey=demo" }
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&hapikey=demo" }
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", hapikey: false} }
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&hapikey=demo" }
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 do
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