hubspot-api-ruby 0.8.1 → 0.9.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/README.md +17 -9
- data/hubspot-api-ruby.gemspec +3 -4
- data/lib/hubspot/association.rb +79 -53
- data/lib/hubspot/company.rb +2 -2
- data/lib/hubspot/config.rb +10 -9
- data/lib/hubspot/connection.rb +20 -14
- data/lib/hubspot/contact.rb +5 -1
- data/lib/hubspot/contact_list.rb +0 -7
- data/lib/hubspot/custom_event.rb +25 -0
- data/lib/hubspot/deal.rb +34 -14
- data/lib/hubspot/exceptions.rb +2 -0
- data/lib/hubspot/meeting.rb +44 -0
- data/lib/hubspot/properties.rb +1 -1
- data/lib/hubspot-api-ruby.rb +2 -0
- data/spec/lib/hubspot/association_spec.rb +37 -32
- data/spec/lib/hubspot/blog_spec.rb +8 -14
- data/spec/lib/hubspot/company_properties_spec.rb +8 -11
- data/spec/lib/hubspot/company_spec.rb +5 -6
- data/spec/lib/hubspot/contact_list_spec.rb +76 -53
- data/spec/lib/hubspot/contact_properties_spec.rb +5 -34
- data/spec/lib/hubspot/contact_spec.rb +1 -3
- data/spec/lib/hubspot/custom_event_spec.rb +27 -0
- data/spec/lib/hubspot/deal_pipeline_spec.rb +4 -15
- data/spec/lib/hubspot/deal_properties_spec.rb +11 -58
- data/spec/lib/hubspot/deal_spec.rb +11 -53
- data/spec/lib/hubspot/engagement_spec.rb +20 -31
- data/spec/lib/hubspot/file_spec.rb +5 -30
- data/spec/lib/hubspot/form_spec.rb +36 -33
- data/spec/lib/hubspot/meeting_spec.rb +75 -0
- data/spec/spec_helper.rb +13 -4
- data/spec/support/vcr.rb +3 -6
- metadata +12 -24
- data/spec/lib/hubspot/topic_spec.rb +0 -23
- data/spec/support/tests_helper.rb +0 -17
@@ -14,29 +14,8 @@ describe Hubspot::ContactProperties do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:example_groups) do
|
18
|
-
VCR.use_cassette('contact_properties/groups_example') do
|
19
|
-
HTTParty.get('https://api.hubapi.com/contacts/v2/groups?hapikey=demo').parsed_response
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:example_properties) do
|
24
|
-
VCR.use_cassette('contact_properties/properties_example') do
|
25
|
-
HTTParty.get('https://api.hubapi.com/contacts/v2/properties?hapikey=demo').parsed_response
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
before { Hubspot.configure(hapikey: 'demo') }
|
30
|
-
|
31
17
|
describe 'Properties' do
|
32
18
|
describe '.all' do
|
33
|
-
context 'with no filter' do
|
34
|
-
cassette 'contact_properties/all_properties'
|
35
|
-
|
36
|
-
it 'should return all properties' do
|
37
|
-
expect(Hubspot::ContactProperties.all).to eql(example_properties)
|
38
|
-
end
|
39
|
-
end
|
40
19
|
|
41
20
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
42
21
|
|
@@ -133,7 +112,7 @@ describe Hubspot::ContactProperties do
|
|
133
112
|
cassette 'contact_properties/delete_non_property'
|
134
113
|
|
135
114
|
it 'should raise an error' do
|
136
|
-
expect { Hubspot::ContactProperties.delete!(name) }.to raise_error(Hubspot::
|
115
|
+
expect { Hubspot::ContactProperties.delete!(name) }.to raise_error(Hubspot::NotFoundError)
|
137
116
|
end
|
138
117
|
end
|
139
118
|
end
|
@@ -141,14 +120,6 @@ describe Hubspot::ContactProperties do
|
|
141
120
|
|
142
121
|
describe 'Groups' do
|
143
122
|
describe '.groups' do
|
144
|
-
context 'with no filter' do
|
145
|
-
cassette 'contact_properties/all_groups'
|
146
|
-
|
147
|
-
it 'should return all groups' do
|
148
|
-
expect(Hubspot::ContactProperties.groups).to eql(example_groups)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
123
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
153
124
|
|
154
125
|
context 'with included groups' do
|
@@ -193,10 +164,10 @@ describe Hubspot::ContactProperties do
|
|
193
164
|
|
194
165
|
let(:sub_params) { params.select { |k, _| k != 'displayName' } }
|
195
166
|
|
196
|
-
it 'should return the valid parameters' do
|
197
|
-
params['name'] =
|
167
|
+
it 'should return the valid parameters' do |example|
|
168
|
+
params['name'] = "ff_group_#{SecureRandom.hex}"
|
198
169
|
response = Hubspot::ContactProperties.create_group!(sub_params)
|
199
|
-
expect(Hubspot::ContactProperties.same?(response, sub_params)).to be true
|
170
|
+
expect(Hubspot::ContactProperties.same?(response.except("name"), sub_params.except("name"))).to be true
|
200
171
|
end
|
201
172
|
end
|
202
173
|
end
|
@@ -237,7 +208,7 @@ describe Hubspot::ContactProperties do
|
|
237
208
|
cassette 'contact_properties/delete_non_group'
|
238
209
|
|
239
210
|
it 'should raise an error' do
|
240
|
-
expect { Hubspot::ContactProperties.delete_group!(name) }.to raise_error(Hubspot::
|
211
|
+
expect { Hubspot::ContactProperties.delete_group!(name) }.to raise_error(Hubspot::NotFoundError)
|
241
212
|
end
|
242
213
|
end
|
243
214
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
RSpec.describe Hubspot::Contact do
|
2
2
|
|
3
|
-
before{ Hubspot.configure(hapikey: 'demo') }
|
4
|
-
|
5
3
|
it_behaves_like "a saveable resource", :contact do
|
6
4
|
def set_property(contact)
|
7
5
|
contact.firstname = "foobar"
|
@@ -35,7 +33,7 @@ RSpec.describe Hubspot::Contact do
|
|
35
33
|
it 'raises an error' do
|
36
34
|
expect {
|
37
35
|
subject
|
38
|
-
}.to raise_error(Hubspot::
|
36
|
+
}.to raise_error(Hubspot::NotFoundError, /contact does not exist/)
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
RSpec.describe Hubspot::CustomEvent do
|
2
|
+
let(:portal_id) { '62515' }
|
3
|
+
let(:sent_portal_id) { portal_id }
|
4
|
+
before { Hubspot.configure(hapikey: 'demo', custom_event_prefix: 'foobar') }
|
5
|
+
|
6
|
+
describe '.trigger' do
|
7
|
+
let(:event_name) { 'my_awesome_event' }
|
8
|
+
let(:email) { 'testingapis@hubspot.com' }
|
9
|
+
let(:properties) { { prop_foo: 'bar' } }
|
10
|
+
let(:options) { {} }
|
11
|
+
let(:base_url) { 'https://api.hubapi.com' }
|
12
|
+
let(:url) { "#{base_url}/events/v3/send?hapikey=demo" }
|
13
|
+
|
14
|
+
subject { described_class.trigger(event_name, email, properties, options) }
|
15
|
+
|
16
|
+
before { stub_request(:post, url).to_return(status: 204, body: JSON.generate({})) }
|
17
|
+
|
18
|
+
it('sends a request to trigger the event') { is_expected.to be true }
|
19
|
+
|
20
|
+
context 'with headers' do
|
21
|
+
let(:headers) { { 'User-Agent' => 'something' } }
|
22
|
+
let(:options) { { headers: headers } }
|
23
|
+
|
24
|
+
it('sends headers') { is_expected.to be true }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
RSpec.describe Hubspot::DealPipeline do
|
2
|
-
before do
|
3
|
-
Hubspot.configure hapikey: 'demo'
|
4
|
-
end
|
5
2
|
|
6
3
|
describe ".find" do
|
7
4
|
it "retrieves a record by id" do
|
8
5
|
VCR.use_cassette("find_deal_pipeline") do
|
9
|
-
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
6
|
+
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
10
7
|
id = deal_pipeline.pipeline_id
|
11
8
|
|
12
9
|
result = Hubspot::DealPipeline.find(deal_pipeline.pipeline_id)
|
13
10
|
|
14
|
-
assert_requested :get, hubspot_api_url("/deals/v1/pipelines/#{id}")
|
15
11
|
expect(result).to be_a(Hubspot::DealPipeline)
|
16
12
|
|
17
13
|
deal_pipeline.destroy!
|
@@ -22,11 +18,10 @@ RSpec.describe Hubspot::DealPipeline do
|
|
22
18
|
describe ".all" do
|
23
19
|
it "returns a list" do
|
24
20
|
VCR.use_cassette("all_deal_pipelines") do
|
25
|
-
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
21
|
+
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
26
22
|
|
27
23
|
results = Hubspot::DealPipeline.all
|
28
24
|
|
29
|
-
assert_requested :get, hubspot_api_url("/deals/v1/pipelines")
|
30
25
|
expect(results).to be_kind_of(Array)
|
31
26
|
expect(results.first).to be_a(Hubspot::DealPipeline)
|
32
27
|
|
@@ -38,9 +33,8 @@ RSpec.describe Hubspot::DealPipeline do
|
|
38
33
|
describe ".create!" do
|
39
34
|
it "creates a new record" do
|
40
35
|
VCR.use_cassette("create_deal_pipeline") do
|
41
|
-
result = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
36
|
+
result = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
42
37
|
|
43
|
-
assert_requested :post, hubspot_api_url("/deals/v1/pipelines")
|
44
38
|
expect(result).to be_a(Hubspot::DealPipeline)
|
45
39
|
|
46
40
|
result.destroy!
|
@@ -51,12 +45,11 @@ RSpec.describe Hubspot::DealPipeline do
|
|
51
45
|
describe "#destroy!" do
|
52
46
|
it "deletes the record" do
|
53
47
|
VCR.use_cassette("delete_deal_pipeline") do
|
54
|
-
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline")
|
48
|
+
deal_pipeline = Hubspot::DealPipeline.create!(label: "New Pipeline #{SecureRandom.hex}")
|
55
49
|
id = deal_pipeline.pipeline_id
|
56
50
|
|
57
51
|
result = deal_pipeline.destroy!
|
58
52
|
|
59
|
-
assert_requested :delete, hubspot_api_url("/deals/v1/pipelines/#{id}")
|
60
53
|
expect(result).to be_a(HTTParty::Response)
|
61
54
|
end
|
62
55
|
end
|
@@ -78,8 +71,4 @@ RSpec.describe Hubspot::DealPipeline do
|
|
78
71
|
expect(result).to eq(data["stages"][0])
|
79
72
|
end
|
80
73
|
end
|
81
|
-
|
82
|
-
def hubspot_api_url(path)
|
83
|
-
URI.join(Hubspot::Config.base_url, path, "?hapikey=demo")
|
84
|
-
end
|
85
74
|
end
|
@@ -14,30 +14,9 @@ describe Hubspot::DealProperties do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:example_groups) do
|
18
|
-
VCR.use_cassette('deal_groups_example') do
|
19
|
-
HTTParty.get('https://api.hubapi.com/deals/v1/groups?hapikey=demo').parsed_response
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:example_properties) do
|
24
|
-
VCR.use_cassette('deal_properties_example') do
|
25
|
-
HTTParty.get('https://api.hubapi.com/deals/v1/properties?hapikey=demo').parsed_response
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
before { Hubspot.configure(hapikey: 'demo') }
|
30
17
|
|
31
18
|
describe 'Properties' do
|
32
19
|
describe '.all' do
|
33
|
-
context 'with no filter' do
|
34
|
-
cassette 'deal_all_properties'
|
35
|
-
|
36
|
-
it 'should return all properties' do
|
37
|
-
expect(Hubspot::DealProperties.all).to eql(example_properties)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
20
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
42
21
|
|
43
22
|
context 'with included groups' do
|
@@ -60,31 +39,13 @@ describe Hubspot::DealProperties do
|
|
60
39
|
end
|
61
40
|
|
62
41
|
let(:params) { {
|
63
|
-
'name' =>
|
42
|
+
'name' => "my_new_property_#{SecureRandom.hex}",
|
64
43
|
'label' => 'This is my new property',
|
65
44
|
'description' => 'How much money do you have?',
|
66
45
|
'groupName' => 'dealinformation',
|
67
46
|
'type' => 'string',
|
68
47
|
'fieldType' => 'text',
|
69
48
|
'hidden' => false,
|
70
|
-
'options' => [{
|
71
|
-
'description' => '',
|
72
|
-
'value' => 'Over $50K',
|
73
|
-
'readOnly' => false,
|
74
|
-
'label' => 'Over $50K',
|
75
|
-
'displayOrder' => 0,
|
76
|
-
'hidden' => false,
|
77
|
-
'doubleData' => 0.0
|
78
|
-
},
|
79
|
-
{
|
80
|
-
'description' => '',
|
81
|
-
'value' => 'Under $50K',
|
82
|
-
'readOnly' => false,
|
83
|
-
'label' => 'Under $50K',
|
84
|
-
'displayOrder' => 1,
|
85
|
-
'hidden' => false,
|
86
|
-
'doubleData' => 0.0
|
87
|
-
}],
|
88
49
|
'deleted' => false,
|
89
50
|
'displayOrder' => 0,
|
90
51
|
'formField' => true,
|
@@ -110,7 +71,7 @@ describe Hubspot::DealProperties do
|
|
110
71
|
|
111
72
|
it 'should return the valid parameters' do
|
112
73
|
response = Hubspot::DealProperties.create!(params)
|
113
|
-
expect(Hubspot::DealProperties.same?(params, response)).to be true
|
74
|
+
expect(Hubspot::DealProperties.same?(params.except("name"), response.compact.except("name", "options"))).to be true
|
114
75
|
end
|
115
76
|
end
|
116
77
|
end
|
@@ -127,22 +88,22 @@ describe Hubspot::DealProperties do
|
|
127
88
|
cassette 'deal_update_property'
|
128
89
|
|
129
90
|
it 'should return the valid parameters' do
|
91
|
+
properties = Hubspot::DealProperties.create!(params)
|
130
92
|
params['description'] = 'What is their favorite flavor?'
|
131
93
|
|
132
|
-
response = Hubspot::DealProperties.update!(
|
133
|
-
expect(Hubspot::DealProperties.same?(response, params)).to be true
|
94
|
+
response = Hubspot::DealProperties.update!(properties['name'], params)
|
95
|
+
expect(Hubspot::DealProperties.same?(response.compact.except("name"), params.except("name"))).to be true
|
134
96
|
end
|
135
97
|
end
|
136
98
|
end
|
137
99
|
|
138
100
|
describe '.delete!' do
|
139
|
-
let(:name) { params['name'] }
|
140
|
-
|
141
101
|
context 'with existing property' do
|
142
102
|
cassette 'deal_delete_property'
|
143
103
|
|
144
104
|
it 'should return nil' do
|
145
|
-
|
105
|
+
properties = Hubspot::DealProperties.create!(params)
|
106
|
+
expect(Hubspot::DealProperties.delete!(properties["name"])).to eq(nil)
|
146
107
|
end
|
147
108
|
end
|
148
109
|
|
@@ -150,7 +111,7 @@ describe Hubspot::DealProperties do
|
|
150
111
|
cassette 'deal_delete_non_property'
|
151
112
|
|
152
113
|
it 'should raise an error' do
|
153
|
-
expect { Hubspot::DealProperties.delete!(
|
114
|
+
expect { Hubspot::DealProperties.delete!("i_do_not_exist") }.to raise_error(Hubspot::NotFoundError)
|
154
115
|
end
|
155
116
|
end
|
156
117
|
end
|
@@ -158,14 +119,6 @@ describe Hubspot::DealProperties do
|
|
158
119
|
|
159
120
|
describe 'Groups' do
|
160
121
|
describe '.groups' do
|
161
|
-
context 'with no filter' do
|
162
|
-
cassette 'deal_all_groups'
|
163
|
-
|
164
|
-
it 'should return all groups' do
|
165
|
-
expect(Hubspot::DealProperties.groups).to eql(example_groups)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
122
|
let(:groups) { %w(calltrackinginfo emailinformation) }
|
170
123
|
|
171
124
|
context 'with included groups' do
|
@@ -211,9 +164,9 @@ describe Hubspot::DealProperties do
|
|
211
164
|
let(:sub_params) { params.select { |k, _| k != 'displayName' } }
|
212
165
|
|
213
166
|
it 'should return the valid parameters' do
|
214
|
-
params['name'] =
|
167
|
+
params['name'] = "ff_group_#{SecureRandom.hex}"
|
215
168
|
response = Hubspot::DealProperties.create_group!(sub_params)
|
216
|
-
expect(Hubspot::DealProperties.same?(response, sub_params)).to be true
|
169
|
+
expect(Hubspot::DealProperties.same?(response.except("name"), sub_params.except("name"))).to be true
|
217
170
|
end
|
218
171
|
end
|
219
172
|
end
|
@@ -254,7 +207,7 @@ describe Hubspot::DealProperties do
|
|
254
207
|
cassette 'deal_delete_non_group'
|
255
208
|
|
256
209
|
it 'should raise an error' do
|
257
|
-
expect { Hubspot::DealProperties.delete_group!(name) }.to raise_error(Hubspot::
|
210
|
+
expect { Hubspot::DealProperties.delete_group!(name) }.to raise_error(Hubspot::NotFoundError)
|
258
211
|
end
|
259
212
|
end
|
260
213
|
end
|
@@ -1,25 +1,12 @@
|
|
1
1
|
describe Hubspot::Deal do
|
2
|
-
let(:portal_id) {
|
3
|
-
let(:
|
4
|
-
let(:
|
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], {}) }
|
@@ -107,13 +94,10 @@ describe Hubspot::Deal do
|
|
107
94
|
end
|
108
95
|
end
|
109
96
|
end
|
110
|
-
|
111
|
-
|
97
|
+
|
112
98
|
describe '.associate' do
|
113
99
|
cassette
|
114
100
|
let(:deal) { Hubspot::Deal.create!(portal_id, [], [], {}) }
|
115
|
-
let(:company) { create :company }
|
116
|
-
let(:contact) { create :contact }
|
117
101
|
let(:contact_id) { contact.id }
|
118
102
|
|
119
103
|
subject { Hubspot::Deal.associate!(deal.deal_id, [company.id], [contact_id]) }
|
@@ -128,10 +112,10 @@ describe Hubspot::Deal do
|
|
128
112
|
context 'when an id is invalid' do
|
129
113
|
let(:contact_id) { 1234 }
|
130
114
|
|
131
|
-
it '
|
132
|
-
expect
|
115
|
+
it 'returns false and changes valid associations' do
|
116
|
+
expect(subject).to eq(false)
|
133
117
|
find_deal = Hubspot::Deal.find(deal.deal_id)
|
134
|
-
find_deal.company_ids.should eql []
|
118
|
+
find_deal.company_ids.should eql [company.id]
|
135
119
|
find_deal.vids.should eql []
|
136
120
|
end
|
137
121
|
end
|
@@ -149,7 +133,6 @@ describe Hubspot::Deal do
|
|
149
133
|
|
150
134
|
describe '.find_by_company' do
|
151
135
|
cassette
|
152
|
-
let(:company) { create :company }
|
153
136
|
let!(:deal) { Hubspot::Deal.create!(portal_id, [company.id], [], { amount: amount }) }
|
154
137
|
|
155
138
|
it 'returns company deals' do
|
@@ -161,7 +144,6 @@ describe Hubspot::Deal do
|
|
161
144
|
|
162
145
|
describe '.find_by_contact' do
|
163
146
|
cassette
|
164
|
-
let(:contact) { create :contact }
|
165
147
|
let!(:deal) { Hubspot::Deal.create!(portal_id, [], [contact.id], { amount: amount }) }
|
166
148
|
|
167
149
|
it 'returns contact deals' do
|
@@ -175,52 +157,28 @@ describe Hubspot::Deal do
|
|
175
157
|
cassette 'find_all_recent_updated_deals'
|
176
158
|
|
177
159
|
it 'must get the recents updated deals' do
|
160
|
+
deal
|
178
161
|
deals = Hubspot::Deal.recent
|
179
162
|
|
180
163
|
first = deals.first
|
181
|
-
last = deals.last
|
182
164
|
|
183
165
|
expect(first).to be_a Hubspot::Deal
|
184
|
-
expect(first.properties['amount']).to eql '0'
|
185
|
-
expect(first.properties['dealname']).to eql '1420787916-gou2rzdgjzx2@u2rzdgjzx2.com'
|
186
|
-
expect(first.properties['dealstage']).to eql 'closedwon'
|
187
|
-
|
188
|
-
expect(last).to be_a Hubspot::Deal
|
189
|
-
expect(last.properties['amount']).to eql '250'
|
190
|
-
expect(last.properties['dealname']).to eql '1420511993-U9862RD9XR@U9862RD9XR.com'
|
191
|
-
expect(last.properties['dealstage']).to eql 'closedwon'
|
192
166
|
end
|
193
167
|
|
194
168
|
it 'must filter only 2 deals' do
|
169
|
+
3.times { Hubspot::Deal.create!(portal_id, [company_id], [vid], { amount: amount}) }
|
195
170
|
deals = Hubspot::Deal.recent(count: 2)
|
196
171
|
expect(deals.size).to eql 2
|
197
172
|
end
|
198
173
|
|
199
|
-
it 'it must offset the deals' do
|
200
|
-
deal = Hubspot::Deal.recent(count: 1, offset: 1).first
|
201
|
-
expect(deal.properties['dealname']).to eql '1420704406-goy6v83a97nr@y6v83a97nr.com' # the third deal
|
202
|
-
end
|
203
174
|
end
|
204
175
|
|
205
176
|
describe "#destroy!" do
|
206
177
|
it "should remove from hubspot" do
|
207
178
|
VCR.use_cassette("destroy_deal") do
|
208
179
|
result = deal.destroy!
|
209
|
-
|
210
|
-
assert_requested :delete, hubspot_api_url("/deals/v1/deal/#{deal.deal_id}?hapikey=demo")
|
211
|
-
|
212
180
|
expect(result).to be true
|
213
181
|
end
|
214
182
|
end
|
215
183
|
end
|
216
|
-
|
217
|
-
describe '#[]' do
|
218
|
-
subject{ Hubspot::Deal.new(example_deal_hash) }
|
219
|
-
|
220
|
-
it 'should get a property' do
|
221
|
-
subject.properties.each do |property, value|
|
222
|
-
expect(subject[property]).to eql value
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
184
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
describe Hubspot::Engagement do
|
2
|
+
|
3
|
+
let(:contact) { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
|
4
|
+
let(:engagement) { Hubspot::EngagementNote.create!(contact.id, "foo") }
|
2
5
|
let(:example_engagement_hash) do
|
3
6
|
VCR.use_cassette("engagement_example") do
|
4
|
-
HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/
|
7
|
+
HTTParty.get("https://api.hubapi.com/engagements/v1/engagements/3981023?hapikey=demo").parsed_response
|
5
8
|
end
|
6
9
|
end
|
7
10
|
let(:example_associated_engagement_hash) do
|
@@ -11,12 +14,11 @@ describe Hubspot::Engagement do
|
|
11
14
|
end
|
12
15
|
|
13
16
|
# http://developers.hubspot.com/docs/methods/contacts/get_contact
|
14
|
-
before{ Hubspot.configure(hapikey: "demo") }
|
15
17
|
|
16
18
|
describe "#initialize" do
|
17
19
|
subject{ Hubspot::Engagement.new(example_engagement_hash) }
|
18
20
|
it { should be_an_instance_of Hubspot::Engagement }
|
19
|
-
its (:id) { should ==
|
21
|
+
its (:id) { should == 3981023 }
|
20
22
|
end
|
21
23
|
|
22
24
|
describe 'EngagementNote' do
|
@@ -30,7 +32,6 @@ describe Hubspot::Engagement do
|
|
30
32
|
|
31
33
|
describe ".find" do
|
32
34
|
cassette "engagement_find"
|
33
|
-
let(:engagement) {Hubspot::EngagementNote.new(example_engagement_hash)}
|
34
35
|
|
35
36
|
it 'must find by the engagement id' do
|
36
37
|
find_engagement = Hubspot::EngagementNote.find(engagement.id)
|
@@ -41,10 +42,18 @@ describe Hubspot::Engagement do
|
|
41
42
|
|
42
43
|
describe ".find_by_company" do
|
43
44
|
cassette "engagement_find_by_country"
|
44
|
-
|
45
|
+
|
46
|
+
let(:company) { Hubspot::Company.create(name: SecureRandom.hex) }
|
47
|
+
before do
|
48
|
+
engagement.class.associate!(
|
49
|
+
engagement.id,
|
50
|
+
"Company",
|
51
|
+
company.id
|
52
|
+
)
|
53
|
+
end
|
45
54
|
|
46
55
|
it 'must find by company id' do
|
47
|
-
find_engagements = Hubspot::EngagementNote.find_by_company(
|
56
|
+
find_engagements = Hubspot::EngagementNote.find_by_company(company.id)
|
48
57
|
find_engagements.should_not be_nil
|
49
58
|
find_engagements.any?{|engagement| engagement.id == engagement.id and engagement.body == engagement.body}.should be true
|
50
59
|
end
|
@@ -52,7 +61,6 @@ describe Hubspot::Engagement do
|
|
52
61
|
|
53
62
|
describe ".find_by_contact" do
|
54
63
|
cassette "engagement_find_by_contact"
|
55
|
-
let(:engagement) {Hubspot::EngagementNote.new(example_associated_engagement_hash)}
|
56
64
|
|
57
65
|
it 'must find by contact id' do
|
58
66
|
find_engagements = Hubspot::EngagementNote.find_by_contact(engagement.associations["contactIds"].first)
|
@@ -75,39 +83,26 @@ describe Hubspot::Engagement do
|
|
75
83
|
cassette "find_all_engagements"
|
76
84
|
|
77
85
|
it 'must get the engagements list' do
|
86
|
+
engagement
|
78
87
|
engagements = Hubspot::Engagement.all
|
79
88
|
|
80
|
-
expect(engagements['engagements'].size).to eql 100 # default page size
|
81
|
-
|
82
89
|
first = engagements['engagements'].first
|
83
|
-
last = engagements['engagements'].last
|
84
90
|
|
85
91
|
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
92
|
end
|
91
93
|
|
92
94
|
it 'must filter only 2 engagements' do
|
95
|
+
3.times { Hubspot::EngagementNote.create!(contact.id, "foo") }
|
93
96
|
engagements = Hubspot::Engagement.all(limit: 2)
|
94
97
|
expect(engagements['engagements'].size).to eql 2
|
95
98
|
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
99
|
end
|
105
100
|
|
106
101
|
describe ".associate!" do
|
107
102
|
cassette "engagement_associate"
|
108
103
|
|
109
104
|
let(:engagement) { Hubspot::EngagementNote.create!(nil, 'note') }
|
110
|
-
let(:contact) { Hubspot::Contact.create(
|
105
|
+
let(:contact) { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
|
111
106
|
subject { Hubspot::Engagement.associate!(engagement.id, 'contact', contact.id) }
|
112
107
|
|
113
108
|
it 'associate an engagement to a resource' do
|
@@ -134,12 +129,6 @@ describe Hubspot::Engagement do
|
|
134
129
|
end
|
135
130
|
|
136
131
|
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
132
|
describe ".create!" do
|
144
133
|
cassette "engagement_call_create"
|
145
134
|
body = "Test call"
|
@@ -150,10 +139,10 @@ describe Hubspot::Engagement do
|
|
150
139
|
|
151
140
|
describe ".find" do
|
152
141
|
cassette "engagement_call_find"
|
153
|
-
let(:engagement) { Hubspot::
|
142
|
+
let(:engagement) { Hubspot::EngagementCall.create!(contact.id, "foo", 42) }
|
154
143
|
|
155
144
|
it 'must find by the engagement id' do
|
156
|
-
find_engagement = Hubspot::
|
145
|
+
find_engagement = Hubspot::EngagementCall.find(engagement.id)
|
157
146
|
find_engagement.id.should eql engagement.id
|
158
147
|
find_engagement.body.should eql engagement.body
|
159
148
|
end
|
@@ -1,38 +1,13 @@
|
|
1
1
|
describe Hubspot do
|
2
|
-
|
3
|
-
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
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
before do
|
12
|
-
Hubspot.configure(hapikey: "demo")
|
13
|
-
end
|
14
|
-
|
15
2
|
describe Hubspot::File do
|
16
|
-
|
3
|
+
before { Hubspot.configure(hapikey: "demo") }
|
17
4
|
describe ".find_by_id" do
|
18
5
|
it "should fetch specific file" do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
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
|
6
|
+
VCR.use_cassette("file_find") do
|
7
|
+
file = Hubspot::File.find_by_id(5323360053)
|
8
|
+
file.id.should eq(5323360053)
|
9
|
+
end
|
33
10
|
end
|
34
11
|
end
|
35
|
-
|
36
12
|
end
|
37
|
-
|
38
13
|
end
|