hubspot-api-ruby 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,25 @@
1
1
  describe Hubspot::Form do
2
- let(:guid) { '78c2891f-ebdd-44c0-bd94-15c012bbbfbf' } # '561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0'
3
2
  let(:example_form_hash) do
4
3
  VCR.use_cassette('form_example') do
5
- HTTParty.get("https://api.hubapi.com#{Hubspot::Form::FORMS_PATH}/#{guid}/?hapikey=demo").parsed_response
4
+ HTTParty.get("https://api.hubapi.com#{Hubspot::Form::FORMS_PATH}/038e819c-5262-4c13-8550-8cabe38c4309/?hapikey=demo").parsed_response
6
5
  end
7
6
  end
8
7
 
8
+ let(:create_params) do
9
+ {
10
+ name: "Demo Form #{SecureRandom.hex}",
11
+ action: '',
12
+ method: 'POST',
13
+ cssClass: 'hs-form stacked',
14
+ redirect: '',
15
+ submitText: 'Sign Up',
16
+ followUpId: '',
17
+ leadNurturingCampaignId: '',
18
+ notifyRecipients: '',
19
+ embeddedCode: ''
20
+ }
21
+ end
22
+
9
23
  describe '#initialize' do
10
24
  subject { Hubspot::Form.new(example_form_hash) }
11
25
 
@@ -14,14 +28,13 @@ describe Hubspot::Form do
14
28
  its(:properties) { should be_a(Hash) }
15
29
  end
16
30
 
17
- before { Hubspot.configure(hapikey: 'demo', portal_id: '62515') }
18
-
19
31
  describe '.all' do
32
+ before { Hubspot.configure(hapikey: 'demo') }
33
+
20
34
  cassette 'find_all_forms'
21
35
 
22
36
  it 'returns all forms' do
23
37
  forms = Hubspot::Form.all
24
- expect(forms.count).to be > 20
25
38
 
26
39
  form = forms.first
27
40
  expect(form).to be_a(Hubspot::Form)
@@ -29,8 +42,10 @@ describe Hubspot::Form do
29
42
  end
30
43
 
31
44
  describe '.find' do
45
+ before { Hubspot.configure(hapikey: 'demo') }
46
+
32
47
  cassette 'form_find'
33
- subject { Hubspot::Form.find(guid) }
48
+ subject { Hubspot::Form.find(Hubspot::Form.all.first.guid) }
34
49
 
35
50
  context 'when the form is found' do
36
51
  it { should be_an_instance_of Hubspot::Form }
@@ -39,31 +54,17 @@ describe Hubspot::Form do
39
54
 
40
55
  context 'when the form is not found' do
41
56
  it 'raises an error' do
42
- expect { Hubspot::Form.find(-1) }.to raise_error(Hubspot::RequestError)
57
+ expect { Hubspot::Form.find(-1) }.to raise_error(Hubspot::NotFoundError)
43
58
  end
44
59
  end
45
60
  end
46
61
 
47
62
  describe '.create' do
48
- subject { Hubspot::Form.create!(params) }
63
+ subject { Hubspot::Form.create!(create_params) }
49
64
 
50
65
  context 'with all required parameters' do
51
66
  cassette 'create_form'
52
67
 
53
- let(:params) do
54
- {
55
- name: "Demo Form #{Time.now.to_i}",
56
- action: '',
57
- method: 'POST',
58
- cssClass: 'hs-form stacked',
59
- redirect: '',
60
- submitText: 'Sign Up',
61
- followUpId: '',
62
- leadNurturingCampaignId: '',
63
- notifyRecipients: '',
64
- embeddedCode: ''
65
- }
66
- end
67
68
  it { should be_an_instance_of Hubspot::Form }
68
69
  its(:guid) { should be_a(String) }
69
70
  end
@@ -78,6 +79,7 @@ describe Hubspot::Form do
78
79
  end
79
80
 
80
81
  describe '#fields' do
82
+ before { Hubspot.configure(hapikey: 'demo') }
81
83
  context 'returning all the fields' do
82
84
  cassette 'fields_among_form'
83
85
 
@@ -117,11 +119,11 @@ describe Hubspot::Form do
117
119
  describe '#submit' do
118
120
  cassette 'form_submit_data'
119
121
 
120
- let(:form) { Hubspot::Form.find('561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
122
+ let(:form) { Hubspot::Form.create!(create_params) }
121
123
 
122
124
  context 'with a valid portal id' do
123
125
  before do
124
- Hubspot.configure(hapikey: 'demo', portal_id: '62515')
126
+ Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
125
127
  end
126
128
 
127
129
  it 'returns true if the form submission is successful' do
@@ -133,7 +135,7 @@ describe Hubspot::Form do
133
135
 
134
136
  context 'with an invalid portal id' do
135
137
  before do
136
- Hubspot.configure(hapikey: 'demo', portal_id: 'xxxx')
138
+ Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY"), portal_id: "xxx")
137
139
  end
138
140
 
139
141
  it 'returns false in case of errors' do
@@ -144,13 +146,15 @@ describe Hubspot::Form do
144
146
  end
145
147
 
146
148
  context 'when initializing Hubspot::Form directly' do
147
- let(:form) { Hubspot::Form.new('guid' => '561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
149
+ let(:f) { Hubspot::Form.new('guid' => form.guid) }
148
150
 
149
- before { Hubspot.configure(hapikey: 'demo', portal_id: '62515') }
151
+ before do
152
+ Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
153
+ end
150
154
 
151
155
  it 'returns true if the form submission is successful' do
152
156
  params = {}
153
- result = form.submit(params)
157
+ result = f.submit(params)
154
158
  result.should be true
155
159
  end
156
160
  end
@@ -159,16 +163,16 @@ describe Hubspot::Form do
159
163
  describe '#update!' do
160
164
  cassette 'form_update'
161
165
 
162
- new_name = 'updated form name 1424709912'
166
+ new_name = "updated form name #{SecureRandom.hex}"
163
167
  redirect = 'http://hubspot.com'
164
168
 
165
- let(:form) { Hubspot::Form.find('561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
169
+ let(:form) { Hubspot::Form.create!(create_params) }
166
170
  let(:params) { { name: new_name, redirect: redirect } }
167
171
  subject { form.update!(params) }
168
172
 
169
173
  it { should be_an_instance_of Hubspot::Form }
170
174
  it 'updates properties' do
171
- subject.properties['name'].should be == new_name
175
+ subject.properties['name'].should start_with('updated form name ')
172
176
  subject.properties['redirect'].should be == redirect
173
177
  end
174
178
  end
@@ -176,8 +180,7 @@ describe Hubspot::Form do
176
180
  describe '#destroy!' do
177
181
  cassette 'form_destroy'
178
182
 
179
- # NOTE: form previous created via the create! method
180
- let(:form) { Hubspot::Form.find('beb92950-ca65-4daf-87ae-a42c054e429f') }
183
+ let(:form) { Hubspot::Form.create!(create_params) }
181
184
  subject { form.destroy! }
182
185
  it { should be true }
183
186
 
@@ -0,0 +1,75 @@
1
+ RSpec.describe Hubspot::Meeting do
2
+
3
+ let(:hubspot_owner_id) { 123 }
4
+ let(:hs_meeting_title) { 'hs_meeting_title' }
5
+ let(:hs_meeting_body) { 'hs_meeting_body' }
6
+ let(:hs_meeting_start_time) { DateTime.strptime('2022-05-03T10:00:00+01:00', '%Y-%m-%dT%H:%M:%S%z') }
7
+ let(:hs_meeting_end_time) { DateTime.strptime('2022-05-03T10:15:00+01:00', '%Y-%m-%dT%H:%M:%S%z') }
8
+
9
+ describe '.create' do
10
+ context 'with properties' do
11
+
12
+ subject do
13
+ described_class.create!(hubspot_owner_id,
14
+ hs_meeting_title,
15
+ hs_meeting_body,
16
+ hs_meeting_start_time,
17
+ hs_meeting_end_time)
18
+ end
19
+
20
+ it 'creates a new meeting with valid properties' do
21
+ VCR.use_cassette 'meeting' do
22
+ expect(subject[:id]).not_to be_nil
23
+ expect(DateTime.parse(subject[:properties][:hs_meeting_start_time])).to eq(hs_meeting_start_time)
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'with an invalid hs_meeting_start_time' do
29
+ subject { described_class.create!(hubspot_owner_id,
30
+ hs_meeting_title,
31
+ hs_meeting_body,
32
+ 'invalid',
33
+ hs_meeting_end_time) }
34
+
35
+ it 'raises an error' do
36
+ VCR.use_cassette 'meeting_error' do
37
+ expect { subject }.to raise_error(Hubspot::RequestError)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '#destroy!' do
44
+ let(:meeting) do
45
+ Hubspot::Meeting.create!(hubspot_owner_id,
46
+ hs_meeting_title,
47
+ hs_meeting_body,
48
+ hs_meeting_start_time,
49
+ hs_meeting_end_time)
50
+ end
51
+
52
+ it "should be destroyed" do
53
+ VCR.use_cassette 'meeting_destroy' do
54
+ expect(Hubspot::Meeting.destroy!(meeting[:id])).to be_truthy
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#associate!' do
60
+ let(:contact) { create :contact }
61
+ let(:meeting) do
62
+ Hubspot::Meeting.create!(hubspot_owner_id,
63
+ hs_meeting_title,
64
+ hs_meeting_body,
65
+ hs_meeting_start_time,
66
+ hs_meeting_end_time)
67
+ end
68
+
69
+ it "should be success" do
70
+ VCR.use_cassette 'meeting_associate' do
71
+ expect(Hubspot::Meeting.associate!(meeting[:id], contact.id)).to be_truthy
72
+ end
73
+ end
74
+ end
75
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ SimpleCov.start do
10
10
  add_filter "/.bundle/"
11
11
  end
12
12
 
13
- require 'dotenv/load'
13
+ require 'dotenv'
14
14
  require 'rspec'
15
15
  require 'rspec/its'
16
16
  require 'webmock/rspec'
@@ -19,6 +19,8 @@ require 'faker'
19
19
  require 'byebug'
20
20
  require 'hubspot-api-ruby'
21
21
 
22
+ Dotenv.load('.env.test')
23
+
22
24
  # Requires supporting files with custom matchers and macros, etc,
23
25
  # in ./support/ and its subdirectories.
24
26
  Dir["#{RSPEC_ROOT}/support/**/*.rb"].each {|f| require f}
@@ -27,10 +29,18 @@ Dir["#{RSPEC_ROOT}/support/**/*.rb"].each {|f| require f}
27
29
  Dir["#{RSPEC_ROOT}/shared_examples/**/*.rb"].each {|f| require f}
28
30
 
29
31
  RSpec.configure do |config|
30
- config.after(:each) do
31
- Hubspot::Config.reset!
32
+ config.before(:all) do
33
+ Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY"))
34
+ end
35
+
36
+ config.before(:each) do
37
+ Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY"))
32
38
  end
33
39
 
40
+ # config.after(:each) do
41
+ # Hubspot::Config.reset!
42
+ # end
43
+
34
44
  config.filter_run_when_matching :focus
35
45
 
36
46
  # Setup FactoryBot
@@ -40,5 +50,4 @@ RSpec.configure do |config|
40
50
  end
41
51
 
42
52
  config.extend CassetteHelper
43
- config.extend TestsHelper
44
53
  end
data/spec/support/vcr.rb CHANGED
@@ -1,16 +1,13 @@
1
1
  require "vcr"
2
2
 
3
3
  def vcr_record_mode
4
- if ENV["VCR_RECORD"] == "1"
5
- :new_episodes
6
- else
7
- :none
8
- end
4
+ ENV["VCR_RECORD_MODE"]&.to_sym || :none
9
5
  end
10
6
 
11
7
  VCR.configure do |c|
12
8
  c.cassette_library_dir = "#{RSPEC_ROOT}/fixtures/vcr_cassettes"
13
9
  c.hook_into :webmock
14
10
  c.default_cassette_options = { record: vcr_record_mode }
15
- c.filter_sensitive_data("<HAPI_KEY>") { ENV.fetch("HUBSPOT_HAPI_KEY", "demo") }
11
+ c.filter_sensitive_data("<HAPI_KEY>") { ENV.fetch("HUBSPOT_HAPI_KEY") }
12
+ c.filter_sensitive_data("<PORTAL_ID>") { ENV.fetch("HUBSPOT_PORTAL_ID") }
16
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubspot-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-31 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.10'
41
- - !ruby/object:Gem::Dependency
42
- name: appraisal
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.2'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.2'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: dotenv
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -288,6 +274,7 @@ files:
288
274
  - lib/hubspot/contact.rb
289
275
  - lib/hubspot/contact_list.rb
290
276
  - lib/hubspot/contact_properties.rb
277
+ - lib/hubspot/custom_event.rb
291
278
  - lib/hubspot/deal.rb
292
279
  - lib/hubspot/deal_pipeline.rb
293
280
  - lib/hubspot/deal_properties.rb
@@ -297,6 +284,7 @@ files:
297
284
  - lib/hubspot/exceptions.rb
298
285
  - lib/hubspot/file.rb
299
286
  - lib/hubspot/form.rb
287
+ - lib/hubspot/meeting.rb
300
288
  - lib/hubspot/oauth.rb
301
289
  - lib/hubspot/owner.rb
302
290
  - lib/hubspot/paged_collection.rb
@@ -319,6 +307,7 @@ files:
319
307
  - spec/lib/hubspot/contact_list_spec.rb
320
308
  - spec/lib/hubspot/contact_properties_spec.rb
321
309
  - spec/lib/hubspot/contact_spec.rb
310
+ - spec/lib/hubspot/custom_event_spec.rb
322
311
  - spec/lib/hubspot/deal_pipeline_spec.rb
323
312
  - spec/lib/hubspot/deal_properties_spec.rb
324
313
  - spec/lib/hubspot/deal_spec.rb
@@ -327,10 +316,10 @@ files:
327
316
  - spec/lib/hubspot/event_spec.rb
328
317
  - spec/lib/hubspot/file_spec.rb
329
318
  - spec/lib/hubspot/form_spec.rb
319
+ - spec/lib/hubspot/meeting_spec.rb
330
320
  - spec/lib/hubspot/owner_spec.rb
331
321
  - spec/lib/hubspot/properties_spec.rb
332
322
  - spec/lib/hubspot/resource_spec.rb
333
- - spec/lib/hubspot/topic_spec.rb
334
323
  - spec/lib/hubspot/utils_spec.rb
335
324
  - spec/lib/tasks/hubspot_spec.rb
336
325
  - spec/shared_examples/saveable_resource.rb
@@ -340,14 +329,13 @@ files:
340
329
  - spec/support/cassette_helper.rb
341
330
  - spec/support/hubspot_api_helpers.rb
342
331
  - spec/support/rake.rb
343
- - spec/support/tests_helper.rb
344
332
  - spec/support/vcr.rb
345
- homepage: http://github.com/lounna-sas/hubspot-api-ruby
333
+ homepage: https://github.com/captaincontrat/hubspot-api-ruby
346
334
  licenses:
347
335
  - MIT
348
336
  metadata:
349
- changelog_uri: https://github.com/lounna-sas/hubspot-api-ruby/blob/master/History.md
350
- post_install_message:
337
+ changelog_uri: https://github.com/captaincontrat/hubspot-api-ruby/blob/master/History.md
338
+ post_install_message:
351
339
  rdoc_options: []
352
340
  require_paths:
353
341
  - lib
@@ -362,8 +350,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
362
350
  - !ruby/object:Gem::Version
363
351
  version: '0'
364
352
  requirements: []
365
- rubygems_version: 3.0.1
366
- signing_key:
353
+ rubygems_version: 3.2.32
354
+ signing_key:
367
355
  specification_version: 4
368
356
  summary: hubspot-api-ruby is a wrapper for the HubSpot REST API
369
357
  test_files: []
@@ -1,23 +0,0 @@
1
- describe Hubspot::Topic do
2
- before do
3
- Hubspot.configure(hapikey: "demo")
4
- end
5
-
6
- describe ".list" do
7
- cassette "topics_list"
8
- let(:topics) { Hubspot::Topic.list }
9
-
10
- it "should have a list of topics" do
11
- topics.count.should be(3)
12
- end
13
- end
14
-
15
- describe ".find_by_topic_id" do
16
- cassette "topics_list"
17
-
18
- it "should find a specific topic" do
19
- topic = Hubspot::Topic.find_by_topic_id(349001328)
20
- topic['id'].should eq(349001328)
21
- end
22
- end
23
- end
@@ -1,17 +0,0 @@
1
- module TestsHelper
2
- def expect_count_and_offset(&block)
3
- it 'returns only the number of objects specified by count' do
4
- result = block.call(count: 2)
5
- expect(result.size).to eql 2
6
-
7
- result = block.call(count: 4)
8
- expect(result.size).to eql 4
9
- end
10
-
11
- it 'returns objects by a specified offset' do
12
- non_offset_objects = block.call(count: 2)
13
- objects_with_offset = block.call(count: 2, offset: 2)
14
- expect(non_offset_objects).to_not eql objects_with_offset
15
- end
16
- end
17
- end