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,25 +1,12 @@
1
1
  describe Hubspot::Deal do
2
- let(:portal_id) { 62515 }
3
- let(:company_id) { 8954037 }
4
- let(:vid) { 27136 }
2
+ let(:portal_id) { ENV.fetch("HUBSPOT_PORTAL_ID").to_i }
3
+ let(:company) { Hubspot::Company.create(name: SecureRandom.hex) }
4
+ let(:company_id) { company.id }
5
+ let(:contact) { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
6
+ let(:vid) { contact.id }
5
7
  let(:amount) { '30' }
6
8
  let(:deal) { Hubspot::Deal.create!(portal_id, [company_id], [vid], { amount: amount}) }
7
9
 
8
- let(:example_deal_hash) do
9
- VCR.use_cassette("deal_example") do
10
- HTTParty.get("https://api.hubapi.com/deals/v1/deal/3?hapikey=demo&portalId=#{portal_id}").parsed_response
11
- end
12
- end
13
-
14
- before{ Hubspot.configure(hapikey: "demo") }
15
-
16
- describe "#initialize" do
17
- subject{ Hubspot::Deal.new(example_deal_hash) }
18
- it { should be_an_instance_of Hubspot::Deal }
19
- its (:portal_id) { should == portal_id }
20
- its (:deal_id) { should == 3 }
21
- end
22
-
23
10
  describe ".create!" do
24
11
  cassette "deal_create"
25
12
  subject { Hubspot::Deal.create!(portal_id, [company_id], [vid], {}) }
@@ -108,6 +95,32 @@ describe Hubspot::Deal do
108
95
  end
109
96
  end
110
97
 
98
+ describe '.associate' do
99
+ cassette
100
+ let(:deal) { Hubspot::Deal.create!(portal_id, [], [], {}) }
101
+ let(:contact_id) { contact.id }
102
+
103
+ subject { Hubspot::Deal.associate!(deal.deal_id, [company.id], [contact_id]) }
104
+
105
+ it 'associates the deal to the contact and the company' do
106
+ subject
107
+ find_deal = Hubspot::Deal.find(deal.deal_id)
108
+ find_deal.company_ids.should eql [company.id]
109
+ find_deal.vids.should eql [contact.id]
110
+ end
111
+
112
+ context 'when an id is invalid' do
113
+ let(:contact_id) { 1234 }
114
+
115
+ it 'returns false and changes valid associations' do
116
+ expect(subject).to eq(false)
117
+ find_deal = Hubspot::Deal.find(deal.deal_id)
118
+ find_deal.company_ids.should eql [company.id]
119
+ find_deal.vids.should eql []
120
+ end
121
+ end
122
+ end
123
+
111
124
  describe ".find" do
112
125
  cassette "deal_find"
113
126
 
@@ -119,9 +132,8 @@ describe Hubspot::Deal do
119
132
  end
120
133
 
121
134
  describe '.find_by_company' do
122
- cassette 'deal_find_by_company'
123
- let(:company) { Hubspot::Company.create(name: 'Test Company') }
124
- let(:company_id) { company.id }
135
+ cassette
136
+ let!(:deal) { Hubspot::Deal.create!(portal_id, [company.id], [], { amount: amount }) }
125
137
 
126
138
  it 'returns company deals' do
127
139
  deals = Hubspot::Deal.find_by_company(company)
@@ -130,56 +142,43 @@ describe Hubspot::Deal do
130
142
  end
131
143
  end
132
144
 
145
+ describe '.find_by_contact' do
146
+ cassette
147
+ let!(:deal) { Hubspot::Deal.create!(portal_id, [], [contact.id], { amount: amount }) }
148
+
149
+ it 'returns contact deals' do
150
+ deals = Hubspot::Deal.find_by_contact(contact)
151
+ deals.first.deal_id.should eql deal.deal_id
152
+ deals.first.properties['amount'].should eql amount
153
+ end
154
+ end
155
+
133
156
  describe '.recent' do
134
157
  cassette 'find_all_recent_updated_deals'
135
158
 
136
159
  it 'must get the recents updated deals' do
160
+ deal
137
161
  deals = Hubspot::Deal.recent
138
162
 
139
163
  first = deals.first
140
- last = deals.last
141
164
 
142
165
  expect(first).to be_a Hubspot::Deal
143
- expect(first.properties['amount']).to eql '0'
144
- expect(first.properties['dealname']).to eql '1420787916-gou2rzdgjzx2@u2rzdgjzx2.com'
145
- expect(first.properties['dealstage']).to eql 'closedwon'
146
-
147
- expect(last).to be_a Hubspot::Deal
148
- expect(last.properties['amount']).to eql '250'
149
- expect(last.properties['dealname']).to eql '1420511993-U9862RD9XR@U9862RD9XR.com'
150
- expect(last.properties['dealstage']).to eql 'closedwon'
151
166
  end
152
167
 
153
168
  it 'must filter only 2 deals' do
169
+ 3.times { Hubspot::Deal.create!(portal_id, [company_id], [vid], { amount: amount}) }
154
170
  deals = Hubspot::Deal.recent(count: 2)
155
171
  expect(deals.size).to eql 2
156
172
  end
157
173
 
158
- it 'it must offset the deals' do
159
- deal = Hubspot::Deal.recent(count: 1, offset: 1).first
160
- expect(deal.properties['dealname']).to eql '1420704406-goy6v83a97nr@y6v83a97nr.com' # the third deal
161
- end
162
174
  end
163
175
 
164
176
  describe "#destroy!" do
165
177
  it "should remove from hubspot" do
166
178
  VCR.use_cassette("destroy_deal") do
167
179
  result = deal.destroy!
168
-
169
- assert_requested :delete, hubspot_api_url("/deals/v1/deal/#{deal.deal_id}?hapikey=demo")
170
-
171
180
  expect(result).to be true
172
181
  end
173
182
  end
174
183
  end
175
-
176
- describe '#[]' do
177
- subject{ Hubspot::Deal.new(example_deal_hash) }
178
-
179
- it 'should get a property' do
180
- subject.properties.each do |property, value|
181
- expect(subject[property]).to eql value
182
- end
183
- end
184
- end
185
184
  end
@@ -1,22 +1,16 @@
1
1
  describe Hubspot::Engagement do
2
- let(:example_engagement_hash) do
3
- VCR.use_cassette("engagement_example") do
4
- HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/51484873?hapikey=demo").parsed_response
5
- end
6
- end
7
- let(:example_associated_engagement_hash) do
8
- VCR.use_cassette("engagement_associated_example") do
9
- HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/58699206?hapikey=demo").parsed_response
10
- end
11
- end
2
+ let(:contact) { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
3
+ let(:engagement) { Hubspot::EngagementNote.create!(contact.id, "foo") }
12
4
 
13
5
  # http://developers.hubspot.com/docs/methods/contacts/get_contact
14
- before{ Hubspot.configure(hapikey: "demo") }
15
6
 
16
7
  describe "#initialize" do
17
8
  subject{ Hubspot::Engagement.new(example_engagement_hash) }
9
+
10
+ let(:example_engagement_hash) { { 'engagement' => { 'id' => 3981023, 'portalId' => 62515, 'associations' => {} } } }
11
+
18
12
  it { should be_an_instance_of Hubspot::Engagement }
19
- its (:id) { should == 51484873 }
13
+ its (:id) { should == 3981023 }
20
14
  end
21
15
 
22
16
  describe 'EngagementNote' do
@@ -30,7 +24,6 @@ describe Hubspot::Engagement do
30
24
 
31
25
  describe ".find" do
32
26
  cassette "engagement_find"
33
- let(:engagement) {Hubspot::EngagementNote.new(example_engagement_hash)}
34
27
 
35
28
  it 'must find by the engagement id' do
36
29
  find_engagement = Hubspot::EngagementNote.find(engagement.id)
@@ -41,10 +34,18 @@ describe Hubspot::Engagement do
41
34
 
42
35
  describe ".find_by_company" do
43
36
  cassette "engagement_find_by_country"
44
- let(:engagement) {Hubspot::EngagementNote.new(example_associated_engagement_hash)}
37
+
38
+ let(:company) { Hubspot::Company.create(name: SecureRandom.hex) }
39
+ before do
40
+ engagement.class.associate!(
41
+ engagement.id,
42
+ "Company",
43
+ company.id
44
+ )
45
+ end
45
46
 
46
47
  it 'must find by company id' do
47
- find_engagements = Hubspot::EngagementNote.find_by_company(engagement.associations["companyIds"].first)
48
+ find_engagements = Hubspot::EngagementNote.find_by_company(company.id)
48
49
  find_engagements.should_not be_nil
49
50
  find_engagements.any?{|engagement| engagement.id == engagement.id and engagement.body == engagement.body}.should be true
50
51
  end
@@ -52,7 +53,6 @@ describe Hubspot::Engagement do
52
53
 
53
54
  describe ".find_by_contact" do
54
55
  cassette "engagement_find_by_contact"
55
- let(:engagement) {Hubspot::EngagementNote.new(example_associated_engagement_hash)}
56
56
 
57
57
  it 'must find by contact id' do
58
58
  find_engagements = Hubspot::EngagementNote.find_by_contact(engagement.associations["contactIds"].first)
@@ -75,39 +75,26 @@ describe Hubspot::Engagement do
75
75
  cassette "find_all_engagements"
76
76
 
77
77
  it 'must get the engagements list' do
78
+ engagement
78
79
  engagements = Hubspot::Engagement.all
79
80
 
80
- expect(engagements['engagements'].size).to eql 100 # default page size
81
-
82
81
  first = engagements['engagements'].first
83
- last = engagements['engagements'].last
84
82
 
85
83
  expect(first).to be_a Hubspot::Engagement
86
- expect(first.engagement['id']).to eql 3981023
87
-
88
- expect(last).to be_a Hubspot::Engagement
89
- expect(last.engagement['id']).to eql 36579065
90
84
  end
91
85
 
92
86
  it 'must filter only 2 engagements' do
87
+ 3.times { Hubspot::EngagementNote.create!(contact.id, "foo") }
93
88
  engagements = Hubspot::Engagement.all(limit: 2)
94
89
  expect(engagements['engagements'].size).to eql 2
95
90
  end
96
-
97
- it 'it must offset the engagements' do
98
- single_list = Hubspot::Engagement.all(limit: 5)
99
- expect(single_list['engagements'].size).to eql 5
100
-
101
- second = Hubspot::Engagement.all(count: 1, offset: single_list['offset'])['engagements'].first
102
- expect(second.engagement['id']).to eql 4815722
103
- end
104
91
  end
105
92
 
106
93
  describe ".associate!" do
107
94
  cassette "engagement_associate"
108
95
 
109
96
  let(:engagement) { Hubspot::EngagementNote.create!(nil, 'note') }
110
- let(:contact) { Hubspot::Contact.create(email: "newcontact#{Time.now.to_i}@hsgem.com") }
97
+ let(:contact) { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
111
98
  subject { Hubspot::Engagement.associate!(engagement.id, 'contact', contact.id) }
112
99
 
113
100
  it 'associate an engagement to a resource' do
@@ -134,12 +121,6 @@ describe Hubspot::Engagement do
134
121
  end
135
122
 
136
123
  describe 'EngagementCall' do
137
- let(:example_engagement_hash) do
138
- VCR.use_cassette("engagement_call_example") do
139
- HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/4709059?hapikey=demo").parsed_response
140
- end
141
- end
142
-
143
124
  describe ".create!" do
144
125
  cassette "engagement_call_create"
145
126
  body = "Test call"
@@ -150,10 +131,10 @@ describe Hubspot::Engagement do
150
131
 
151
132
  describe ".find" do
152
133
  cassette "engagement_call_find"
153
- let(:engagement) { Hubspot::EngagementNote.new(example_engagement_hash) }
134
+ let(:engagement) { Hubspot::EngagementCall.create!(contact.id, "foo", 42) }
154
135
 
155
136
  it 'must find by the engagement id' do
156
- find_engagement = Hubspot::EngagementNote.find(engagement.id)
137
+ find_engagement = Hubspot::EngagementCall.find(engagement.id)
157
138
  find_engagement.id.should eql engagement.id
158
139
  find_engagement.body.should eql engagement.body
159
140
  end
@@ -1,7 +1,8 @@
1
1
  describe Hubspot::Event do
2
- let(:portal_id) { '62515' }
2
+ let(:portal_id) { ENV.fetch("HUBSPOT_PORTAL_ID") }
3
3
  let(:sent_portal_id) { portal_id }
4
- before { Hubspot.configure(hapikey: 'demo', portal_id: portal_id) }
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,38 +1,24 @@
1
- describe Hubspot do
2
-
1
+ describe Hubspot::File do
3
2
  let(:example_file_hash) do
4
- VCR.use_cassette("file_list", record: :none) do
5
- url = Hubspot::Connection.send(:generate_url, Hubspot::File::LIST_FILE_PATH)
6
- resp = HTTParty.get(url, format: :json)
7
- resp.parsed_response["objects"].first
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
8
12
  end
9
13
  end
10
14
 
11
- before do
12
- Hubspot.configure(hapikey: "demo")
13
- end
14
-
15
- describe Hubspot::File do
16
-
17
- describe ".find_by_id" do
18
- it "should fetch specific file" do
19
- VCR.use_cassette("file_find", record: :none) do
20
- file = Hubspot::File.find_by_id(example_file_hash["id"])
21
- file.id.should eq(example_file_hash["id"])
22
- end
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)
23
21
  end
24
22
  end
25
-
26
- describe '#destroy!' do
27
- it 'should remove from hubspot' do
28
- VCR.use_cassette("file_delete", record: :none) do
29
- file = Hubspot::File.find_by_id(example_file_hash["id"])
30
- res = file.destroy!
31
- expect(res["succeeded"]).to be true
32
- end
33
- end
34
- end
35
-
36
23
  end
37
-
38
24
  end
@@ -1,11 +1,27 @@
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
+ 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
6
7
  end
7
8
  end
8
9
 
10
+ let(:create_params) do
11
+ {
12
+ name: "Demo Form #{SecureRandom.hex}",
13
+ action: '',
14
+ method: 'POST',
15
+ cssClass: 'hs-form stacked',
16
+ redirect: '',
17
+ submitText: 'Sign Up',
18
+ followUpId: '',
19
+ leadNurturingCampaignId: '',
20
+ notifyRecipients: '',
21
+ embeddedCode: ''
22
+ }
23
+ end
24
+
9
25
  describe '#initialize' do
10
26
  subject { Hubspot::Form.new(example_form_hash) }
11
27
 
@@ -14,14 +30,11 @@ describe Hubspot::Form do
14
30
  its(:properties) { should be_a(Hash) }
15
31
  end
16
32
 
17
- before { Hubspot.configure(hapikey: 'demo', portal_id: '62515') }
18
-
19
33
  describe '.all' do
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)
@@ -30,7 +43,7 @@ describe Hubspot::Form do
30
43
 
31
44
  describe '.find' do
32
45
  cassette 'form_find'
33
- subject { Hubspot::Form.find(guid) }
46
+ subject { Hubspot::Form.find(Hubspot::Form.all.first.guid) }
34
47
 
35
48
  context 'when the form is found' do
36
49
  it { should be_an_instance_of Hubspot::Form }
@@ -39,31 +52,17 @@ describe Hubspot::Form do
39
52
 
40
53
  context 'when the form is not found' do
41
54
  it 'raises an error' do
42
- expect { Hubspot::Form.find(-1) }.to raise_error(Hubspot::RequestError)
55
+ expect { Hubspot::Form.find(-1) }.to raise_error(Hubspot::NotFoundError)
43
56
  end
44
57
  end
45
58
  end
46
59
 
47
60
  describe '.create' do
48
- subject { Hubspot::Form.create!(params) }
61
+ subject { Hubspot::Form.create!(create_params) }
49
62
 
50
63
  context 'with all required parameters' do
51
64
  cassette 'create_form'
52
65
 
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
66
  it { should be_an_instance_of Hubspot::Form }
68
67
  its(:guid) { should be_a(String) }
69
68
  end
@@ -117,11 +116,11 @@ describe Hubspot::Form do
117
116
  describe '#submit' do
118
117
  cassette 'form_submit_data'
119
118
 
120
- let(:form) { Hubspot::Form.find('561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
119
+ let(:form) { Hubspot::Form.all.first }
121
120
 
122
121
  context 'with a valid portal id' do
123
122
  before do
124
- Hubspot.configure(hapikey: 'demo', portal_id: '62515')
123
+ Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
125
124
  end
126
125
 
127
126
  it 'returns true if the form submission is successful' do
@@ -133,7 +132,7 @@ describe Hubspot::Form do
133
132
 
134
133
  context 'with an invalid portal id' do
135
134
  before do
136
- Hubspot.configure(hapikey: 'demo', portal_id: 'xxxx')
135
+ Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: "xxx")
137
136
  end
138
137
 
139
138
  it 'returns false in case of errors' do
@@ -144,13 +143,15 @@ describe Hubspot::Form do
144
143
  end
145
144
 
146
145
  context 'when initializing Hubspot::Form directly' do
147
- let(:form) { Hubspot::Form.new('guid' => '561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
146
+ let(:f) { Hubspot::Form.new('guid' => form.guid) }
148
147
 
149
- before { Hubspot.configure(hapikey: 'demo', portal_id: '62515') }
148
+ before do
149
+ Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
150
+ end
150
151
 
151
152
  it 'returns true if the form submission is successful' do
152
153
  params = {}
153
- result = form.submit(params)
154
+ result = f.submit(params)
154
155
  result.should be true
155
156
  end
156
157
  end
@@ -159,16 +160,16 @@ describe Hubspot::Form do
159
160
  describe '#update!' do
160
161
  cassette 'form_update'
161
162
 
162
- new_name = 'updated form name 1424709912'
163
+ new_name = "updated form name #{SecureRandom.hex}"
163
164
  redirect = 'http://hubspot.com'
164
165
 
165
- let(:form) { Hubspot::Form.find('561d9ce9-bb4c-45b4-8e32-21cdeaa3a7f0') }
166
+ let(:form) { Hubspot::Form.create!(create_params) }
166
167
  let(:params) { { name: new_name, redirect: redirect } }
167
168
  subject { form.update!(params) }
168
169
 
169
- it { should be_an_instance_of Hubspot::Form }
170
170
  it 'updates properties' do
171
- subject.properties['name'].should be == new_name
171
+ should be_an_instance_of Hubspot::Form
172
+ subject.properties['name'].should start_with('updated form name ')
172
173
  subject.properties['redirect'].should be == redirect
173
174
  end
174
175
  end
@@ -176,8 +177,7 @@ describe Hubspot::Form do
176
177
  describe '#destroy!' do
177
178
  cassette 'form_destroy'
178
179
 
179
- # NOTE: form previous created via the create! method
180
- let(:form) { Hubspot::Form.find('beb92950-ca65-4daf-87ae-a42c054e429f') }
180
+ let(:form) { Hubspot::Form.create!(create_params) }
181
181
  subject { form.destroy! }
182
182
  it { should be true }
183
183
 
@@ -0,0 +1,81 @@
1
+ RSpec.describe Hubspot::Meeting do
2
+
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
10
+ let(:hs_meeting_title) { 'hs_meeting_title' }
11
+ let(:hs_meeting_body) { 'hs_meeting_body' }
12
+ let(:hs_meeting_start_time) { DateTime.strptime('2022-05-03T10:00:00+01:00', '%Y-%m-%dT%H:%M:%S%z') }
13
+ let(:hs_meeting_end_time) { DateTime.strptime('2022-05-03T10:15:00+01:00', '%Y-%m-%dT%H:%M:%S%z') }
14
+
15
+ describe '.create' do
16
+ context 'with properties' do
17
+
18
+ subject do
19
+ described_class.create!(hubspot_owner_id,
20
+ hs_meeting_title,
21
+ hs_meeting_body,
22
+ hs_meeting_start_time,
23
+ hs_meeting_end_time)
24
+ end
25
+
26
+ it 'creates a new meeting with valid properties' do
27
+ VCR.use_cassette 'meeting' do
28
+ expect(subject[:id]).not_to be_nil
29
+ expect(DateTime.parse(subject[:properties][:hs_meeting_start_time])).to eq(hs_meeting_start_time)
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'with an invalid hs_meeting_start_time' do
35
+ subject { described_class.create!(hubspot_owner_id,
36
+ hs_meeting_title,
37
+ hs_meeting_body,
38
+ 'invalid',
39
+ hs_meeting_end_time) }
40
+
41
+ it 'raises an error' do
42
+ VCR.use_cassette 'meeting_error' do
43
+ expect { subject }.to raise_error(Hubspot::RequestError)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#destroy!' do
50
+ let(:meeting) do
51
+ Hubspot::Meeting.create!(hubspot_owner_id,
52
+ hs_meeting_title,
53
+ hs_meeting_body,
54
+ hs_meeting_start_time,
55
+ hs_meeting_end_time)
56
+ end
57
+
58
+ it "should be destroyed" do
59
+ VCR.use_cassette 'meeting_destroy' do
60
+ expect(Hubspot::Meeting.destroy!(meeting[:id])).to be_truthy
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#associate!' do
66
+ let(:contact) { create :contact }
67
+ let(:meeting) do
68
+ Hubspot::Meeting.create!(hubspot_owner_id,
69
+ hs_meeting_title,
70
+ hs_meeting_body,
71
+ hs_meeting_start_time,
72
+ hs_meeting_end_time)
73
+ end
74
+
75
+ it "should be success" do
76
+ VCR.use_cassette 'meeting_associate' do
77
+ expect(Hubspot::Meeting.associate!(meeting[:id], contact.id)).to be_truthy
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,12 +1,11 @@
1
1
  describe Hubspot::Owner do
2
2
  let(:example_owners) do
3
3
  VCR.use_cassette('owner_example') do
4
- HTTParty.get('https://api.hubapi.com/owners/v2/owners?hapikey=demo&portalId=62515').parsed_response
4
+ headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
5
+ HTTParty.get('https://api.hubapi.com/owners/v2/owners', headers: headers).parsed_response
5
6
  end
6
7
  end
7
8
 
8
- before { Hubspot.configure(hapikey: 'demo') }
9
-
10
9
  describe '.all' do
11
10
  cassette 'owner_all'
12
11
 
@@ -51,4 +51,44 @@ RSpec.describe Hubspot::Resource do
51
51
  end
52
52
  end
53
53
  end
54
- end
54
+
55
+ describe '#[]' do
56
+ context 'using new' do
57
+ let(:resource) { described_class.new(properties) }
58
+ let(:properties) { { id: 1, firstname: 'John', lastname: 'Wayne' } }
59
+
60
+ it { expect(resource[:firstname]).to eq 'John' }
61
+ it { expect(resource['lastname']).to eq 'Wayne' }
62
+ it { expect(resource[:middlename]).to be nil }
63
+ end
64
+
65
+ context 'using from_result' do
66
+ let(:resource) { described_class.from_result({ properties: properties }) }
67
+ let(:properties) { { id: { 'value' => 1 }, firstname: { 'value' => 'John' }, lastname: { 'value' => 'Wayne' } } }
68
+
69
+ it { expect(resource[:firstname]).to eq 'John' }
70
+ it { expect(resource['lastname']).to eq 'Wayne' }
71
+ it { expect(resource[:middlename]).to be nil }
72
+ end
73
+ end
74
+
75
+ describe '#adding_accessors' do
76
+ describe 'getters' do
77
+ context 'using new' do
78
+ let(:resource) { described_class.new(properties) }
79
+ let(:properties) { { id: 1, firstname: 'John', lastname: 'Wayne' } }
80
+
81
+ it { expect(resource.firstname).to eq 'John' }
82
+ it { expect(resource.lastname).to eq 'Wayne' }
83
+ end
84
+
85
+ context 'using from_result' do
86
+ let(:resource) { described_class.from_result({ properties: properties }) }
87
+ let(:properties) { { id: { 'value' => 1 }, firstname: { 'value' => 'John' }, lastname: { 'value' => 'Wayne' } } }
88
+
89
+ it { expect(resource.firstname).to eq 'John' }
90
+ it { expect(resource.lastname).to eq 'Wayne' }
91
+ end
92
+ end
93
+ end
94
+ end