hubspot-ruby 0.1.8 → 0.2.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/Gemfile +2 -22
- data/Gemfile.lock +14 -11
- data/LICENSE.txt +0 -2
- data/README.md +8 -6
- data/RELEASING.md +4 -5
- data/Rakefile +2 -17
- data/hubspot-ruby.gemspec +20 -157
- data/lib/hubspot-ruby.rb +10 -0
- data/lib/hubspot/blog.rb +1 -2
- data/lib/hubspot/company.rb +149 -0
- data/lib/hubspot/company_properties.rb +59 -0
- data/lib/hubspot/config.rb +10 -4
- data/lib/hubspot/connection.rb +12 -4
- data/lib/hubspot/contact.rb +52 -31
- data/lib/hubspot/contact_list.rb +16 -16
- data/lib/hubspot/contact_properties.rb +53 -6
- data/lib/hubspot/deal.rb +2 -2
- data/lib/hubspot/deal_pipeline.rb +43 -0
- data/lib/hubspot/deal_properties.rb +59 -0
- data/lib/hubspot/engagement.rb +133 -0
- data/lib/hubspot/exceptions.rb +1 -1
- data/lib/hubspot/form.rb +20 -20
- data/lib/hubspot/owner.rb +49 -0
- data/lib/hubspot/properties.rb +119 -0
- data/lib/hubspot/railtie.rb +10 -0
- data/lib/hubspot/topic.rb +2 -2
- data/lib/hubspot/utils.rb +106 -3
- data/spec/lib/hubspot/blog_spec.rb +2 -0
- data/spec/lib/hubspot/company_properties_spec.rb +239 -0
- data/spec/lib/hubspot/company_spec.rb +190 -0
- data/spec/lib/hubspot/config_spec.rb +1 -1
- data/spec/lib/hubspot/connection_spec.rb +33 -27
- data/spec/lib/hubspot/contact_list_spec.rb +61 -61
- data/spec/lib/hubspot/contact_properties_spec.rb +234 -3
- data/spec/lib/hubspot/contact_spec.rb +140 -71
- data/spec/lib/hubspot/deal_properties_spec.rb +254 -0
- data/spec/lib/hubspot/engagement_spec.rb +87 -0
- data/spec/lib/hubspot/form_spec.rb +72 -60
- data/spec/lib/hubspot/owner_spec.rb +56 -0
- data/spec/lib/hubspot/properties_spec.rb +45 -0
- data/spec/lib/hubspot/topic_spec.rb +0 -1
- data/spec/lib/hubspot/utils_spec.rb +113 -15
- data/spec/lib/tasks/properties_spec.rb +90 -0
- data/spec/live/companies_integration_spec.rb +23 -0
- data/spec/live/companies_properties_integration_spec.rb +120 -0
- data/spec/live/contacts_integration_spec.rb +1 -1
- data/spec/live/contacts_properties_integration_spec.rb +120 -0
- data/spec/live/deal_properties_integration_spec.rb +123 -0
- data/spec/live/deals_integration_spec.rb +1 -1
- data/spec/support/cassette_helper.rb +1 -1
- data/spec/support/tests_helper.rb +3 -3
- metadata +39 -78
- data/.document +0 -5
- data/lib/hubspot/version.rb +0 -9
- data/spec/fixtures/vcr_cassettes/add_contacts_to_lists.yml +0 -281
- data/spec/fixtures/vcr_cassettes/blog_list.yml +0 -180
- data/spec/fixtures/vcr_cassettes/blog_posts.yml +0 -107
- data/spec/fixtures/vcr_cassettes/blog_posts_list.yml +0 -6463
- data/spec/fixtures/vcr_cassettes/contact_create.yml +0 -64
- data/spec/fixtures/vcr_cassettes/contact_create_existing_email.yml +0 -62
- data/spec/fixtures/vcr_cassettes/contact_create_invalid_email.yml +0 -63
- data/spec/fixtures/vcr_cassettes/contact_create_with_params.yml +0 -64
- data/spec/fixtures/vcr_cassettes/contact_destroy.yml +0 -131
- data/spec/fixtures/vcr_cassettes/contact_example.yml +0 -32
- data/spec/fixtures/vcr_cassettes/contact_find_by_email.yml +0 -59
- data/spec/fixtures/vcr_cassettes/contact_find_by_email_batch_mode.yml +0 -509
- data/spec/fixtures/vcr_cassettes/contact_find_by_id.yml +0 -59
- data/spec/fixtures/vcr_cassettes/contact_find_by_id_batch_mode.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_find_by_utk.yml +0 -83
- data/spec/fixtures/vcr_cassettes/contact_find_by_utk_batch_mode.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_list_batch_find.yml +0 -65
- data/spec/fixtures/vcr_cassettes/contact_list_destroy.yml +0 -63
- data/spec/fixtures/vcr_cassettes/contact_list_example.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_list_find.yml +0 -96
- data/spec/fixtures/vcr_cassettes/contact_list_refresh.yml +0 -33
- data/spec/fixtures/vcr_cassettes/contact_list_update.yml +0 -36
- data/spec/fixtures/vcr_cassettes/contact_update.yml +0 -66
- data/spec/fixtures/vcr_cassettes/contacts_among_list.yml +0 -189
- data/spec/fixtures/vcr_cassettes/create_form.yml +0 -39
- data/spec/fixtures/vcr_cassettes/create_list.yml +0 -36
- data/spec/fixtures/vcr_cassettes/create_list_with_filters.yml +0 -36
- data/spec/fixtures/vcr_cassettes/deal_create.yml +0 -61
- data/spec/fixtures/vcr_cassettes/deal_example.yml +0 -166
- data/spec/fixtures/vcr_cassettes/deal_find.yml +0 -115
- data/spec/fixtures/vcr_cassettes/destroy_deal.yml +0 -221
- data/spec/fixtures/vcr_cassettes/fail_to_create_form.yml +0 -35
- data/spec/fixtures/vcr_cassettes/fail_to_create_list.yml +0 -35
- data/spec/fixtures/vcr_cassettes/field_among_form.yml +0 -34
- data/spec/fixtures/vcr_cassettes/fields_among_form.yml +0 -35
- data/spec/fixtures/vcr_cassettes/find_all_contacts.yml +0 -297
- data/spec/fixtures/vcr_cassettes/find_all_dynamic_lists.yml +0 -104
- data/spec/fixtures/vcr_cassettes/find_all_forms.yml +0 -15378
- data/spec/fixtures/vcr_cassettes/find_all_lists.yml +0 -138
- data/spec/fixtures/vcr_cassettes/find_all_recent_contacts.yml +0 -33
- data/spec/fixtures/vcr_cassettes/find_all_recent_updated_deals.yml +0 -130
- data/spec/fixtures/vcr_cassettes/find_all_stastic_lists.yml +0 -21876
- data/spec/fixtures/vcr_cassettes/form_destroy.yml +0 -64
- data/spec/fixtures/vcr_cassettes/form_example.yml +0 -39
- data/spec/fixtures/vcr_cassettes/form_find.yml +0 -69
- data/spec/fixtures/vcr_cassettes/form_post.yml +0 -31
- data/spec/fixtures/vcr_cassettes/form_submit_data.yml +0 -130
- data/spec/fixtures/vcr_cassettes/form_update.yml +0 -77
- data/spec/fixtures/vcr_cassettes/one_month_blog_posts_filter_state.yml +0 -19127
- data/spec/fixtures/vcr_cassettes/one_month_blog_posts_list.yml +0 -34963
- data/spec/fixtures/vcr_cassettes/remove_contacts_from_lists.yml +0 -315
- data/spec/fixtures/vcr_cassettes/topic_list.yml +0 -48
- data/spec/fixtures/vcr_cassettes/topics_list.yml +0 -86
|
@@ -1,42 +1,48 @@
|
|
|
1
1
|
describe Hubspot::Connection do
|
|
2
2
|
before(:each) do
|
|
3
|
-
@url
|
|
4
|
-
@
|
|
3
|
+
@url = 'http://localhost:3000'
|
|
4
|
+
@http_response = mock('http_response')
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
describe '.get_json' do
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
describe '.get_json' do
|
|
8
|
+
it 'delegates url format to Hubspot::Utils, call HTTParty get and returns response' do
|
|
9
|
+
@http_response.success? { true }
|
|
10
|
+
@http_response.parsed_response { {} }
|
|
11
|
+
@http_response.code { 200 }
|
|
12
|
+
@http_response.body { 'mocked response' }
|
|
13
|
+
|
|
14
|
+
mock(Hubspot::Connection).generate_url(@url, {}) { @url }
|
|
15
|
+
mock(Hubspot::Connection).get(@url, format: :json) { @http_response }
|
|
14
16
|
Hubspot::Connection.get_json(@url, {})
|
|
15
|
-
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
describe '.post_json' do
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
describe '.post_json' do
|
|
21
|
+
it 'delegates url format to Hubspot::Utils, call HTTParty post and returns response' do
|
|
22
|
+
@http_response.success? { true }
|
|
23
|
+
@http_response.parsed_response { {} }
|
|
24
|
+
@http_response.code { 200 }
|
|
25
|
+
@http_response.body { 'mocked response' }
|
|
26
|
+
|
|
27
|
+
mock(Hubspot::Connection).generate_url(@url, {}) { @url }
|
|
28
|
+
mock(Hubspot::Connection).post(@url, body: "{}", headers: {"Content-Type"=>"application/json"}, format: :json) { @http_response }
|
|
25
29
|
Hubspot::Connection.post_json(@url, params: {}, body: {})
|
|
26
|
-
|
|
30
|
+
end
|
|
27
31
|
end
|
|
28
32
|
|
|
29
|
-
describe '.delete_json' do
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
describe '.delete_json' do
|
|
34
|
+
it 'delegates url format to Hubspot::Utils, call HTTParty delete and returns response' do
|
|
35
|
+
@http_response.success? { true }
|
|
36
|
+
@http_response.code { 200 }
|
|
37
|
+
@http_response.body { 'mocked response' }
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
mock(Hubspot::Connection).generate_url(@url, {}) { @url }
|
|
40
|
+
mock(Hubspot::Connection).delete(@url, format: :json) { @http_response }
|
|
35
41
|
Hubspot::Connection.delete_json(@url, {})
|
|
36
|
-
|
|
42
|
+
end
|
|
37
43
|
end
|
|
38
44
|
|
|
39
|
-
context 'private methods' do
|
|
45
|
+
context 'private methods' do
|
|
40
46
|
describe ".generate_url" do
|
|
41
47
|
let(:path){ "/test/:email/profile" }
|
|
42
48
|
let(:params){{email: "test"}}
|
|
@@ -102,11 +108,11 @@ describe Hubspot::Connection do
|
|
|
102
108
|
it{ should == "https://cool.com/test/test/profile"}
|
|
103
109
|
end
|
|
104
110
|
|
|
105
|
-
context "passing Array as parameters for batch mode, key is prefixed with batch_" do
|
|
111
|
+
context "passing Array as parameters for batch mode, key is prefixed with batch_" do
|
|
106
112
|
let(:path) { Hubspot::ContactList::LIST_BATCH_PATH }
|
|
107
113
|
let(:params) { { batch_list_id: [1,2,3] } }
|
|
108
114
|
it{ should == "https://api.hubapi.com/contacts/v1/lists/batch?listId=1&listId=2&listId=3&hapikey=demo" }
|
|
109
115
|
end
|
|
110
116
|
end
|
|
111
117
|
end
|
|
112
|
-
end
|
|
118
|
+
end
|
|
@@ -13,17 +13,17 @@ describe Hubspot::ContactList do
|
|
|
13
13
|
HTTParty.get("https://api.hubapi.com/contacts/v1/contact/email/testingapis@hubspot.com/profile?hapikey=demo").parsed_response
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
describe '#initialize' do
|
|
18
18
|
subject { Hubspot::ContactList.new(example_contact_list_hash) }
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
it { should be_an_instance_of Hubspot::ContactList }
|
|
21
21
|
its(:id) { should be_an(Integer) }
|
|
22
22
|
its(:portal_id) { should be_a(Integer) }
|
|
23
23
|
its(:name) { should_not be_empty }
|
|
24
|
-
its(:dynamic) { should be true }
|
|
24
|
+
its(:dynamic) { should be true }
|
|
25
25
|
its(:properties) { should be_a(Hash) }
|
|
26
|
-
end
|
|
26
|
+
end
|
|
27
27
|
|
|
28
28
|
before { Hubspot.configure(hapikey: "demo") }
|
|
29
29
|
|
|
@@ -40,18 +40,18 @@ describe Hubspot::ContactList do
|
|
|
40
40
|
|
|
41
41
|
it 'add default properties to the contacts returned' do
|
|
42
42
|
contact = list.contacts.first
|
|
43
|
-
expect(contact.email).to_not be_empty
|
|
43
|
+
expect(contact.email).to_not be_empty
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
expect_count_and_offset do |params|
|
|
47
|
-
Hubspot::ContactList.find(1).contacts(params)
|
|
46
|
+
expect_count_and_offset do |params|
|
|
47
|
+
Hubspot::ContactList.find(1).contacts(params)
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
describe '.create' do
|
|
52
52
|
subject{ Hubspot::ContactList.create!({ name: name }) }
|
|
53
|
-
|
|
54
|
-
context 'with all required parameters' do
|
|
53
|
+
|
|
54
|
+
context 'with all required parameters' do
|
|
55
55
|
cassette 'create_list'
|
|
56
56
|
|
|
57
57
|
let(:name) { 'testing list' }
|
|
@@ -63,7 +63,7 @@ describe Hubspot::ContactList do
|
|
|
63
63
|
context 'adding filters parameters' do
|
|
64
64
|
cassette 'create_list_with_filters'
|
|
65
65
|
|
|
66
|
-
it 'returns a ContactList object with filters set' do
|
|
66
|
+
it 'returns a ContactList object with filters set' do
|
|
67
67
|
name = 'list with filters'
|
|
68
68
|
filters_param = [[{ operator: "EQ", value: "@hubspot", property: "twitterhandle", type: "string"}]]
|
|
69
69
|
list_with_filters = Hubspot::ContactList.create!({ name: name, filters: filters_param })
|
|
@@ -76,7 +76,7 @@ describe Hubspot::ContactList do
|
|
|
76
76
|
context 'without all required parameters' do
|
|
77
77
|
cassette 'fail_to_create_list'
|
|
78
78
|
|
|
79
|
-
it 'raises an error' do
|
|
79
|
+
it 'raises an error' do
|
|
80
80
|
expect { Hubspot::ContactList.create!({ name: nil }) }.to raise_error(Hubspot::RequestError)
|
|
81
81
|
end
|
|
82
82
|
end
|
|
@@ -87,35 +87,35 @@ describe Hubspot::ContactList do
|
|
|
87
87
|
cassette 'find_all_lists'
|
|
88
88
|
|
|
89
89
|
it 'returns by defaut 20 contact lists' do
|
|
90
|
-
lists = Hubspot::ContactList.all
|
|
91
|
-
expect(lists.count).to eql 20
|
|
90
|
+
lists = Hubspot::ContactList.all
|
|
91
|
+
expect(lists.count).to eql 20
|
|
92
92
|
|
|
93
93
|
list = lists.first
|
|
94
|
-
expect(list).to be_a(Hubspot::ContactList)
|
|
94
|
+
expect(list).to be_a(Hubspot::ContactList)
|
|
95
95
|
expect(list.id).to be_an(Integer)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
expect_count_and_offset { |params| Hubspot::ContactList.all(params) }
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
context 'static lists' do
|
|
101
|
+
context 'static lists' do
|
|
102
102
|
cassette 'find_all_stastic_lists'
|
|
103
103
|
|
|
104
104
|
it 'returns by defaut all the static contact lists' do
|
|
105
|
-
lists = Hubspot::ContactList.all(static: true)
|
|
106
|
-
expect(lists.count).to be > 20
|
|
105
|
+
lists = Hubspot::ContactList.all(static: true)
|
|
106
|
+
expect(lists.count).to be > 20
|
|
107
107
|
|
|
108
108
|
list = lists.first
|
|
109
|
-
expect(list).to be_a(Hubspot::ContactList)
|
|
109
|
+
expect(list).to be_a(Hubspot::ContactList)
|
|
110
110
|
expect(list.dynamic).to be false
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
context 'dynamic lists' do
|
|
115
115
|
cassette 'find_all_dynamic_lists'
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
it 'returns by defaut all the static contact lists' do
|
|
118
|
-
lists = Hubspot::ContactList.all(dynamic: true)
|
|
118
|
+
lists = Hubspot::ContactList.all(dynamic: true)
|
|
119
119
|
expect(lists.count).to be > 20
|
|
120
120
|
|
|
121
121
|
list = lists.first
|
|
@@ -124,7 +124,7 @@ describe Hubspot::ContactList do
|
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
describe '.find' do
|
|
129
129
|
context 'given an id' do
|
|
130
130
|
cassette "contact_list_find"
|
|
@@ -140,14 +140,14 @@ describe Hubspot::ContactList do
|
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
context 'Wrong parameter type given' do
|
|
143
|
-
it 'raises an error' do
|
|
143
|
+
it 'raises an error' do
|
|
144
144
|
expect { Hubspot::ContactList.find(static_list) }.to raise_error(Hubspot::InvalidParams)
|
|
145
|
-
end
|
|
145
|
+
end
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
context 'when the contact list is not found' do
|
|
149
|
-
it 'raises an error' do
|
|
150
|
-
expect { Hubspot::ContactList.find(-1) }.to raise_error(Hubspot::RequestError)
|
|
149
|
+
it 'raises an error' do
|
|
150
|
+
expect { Hubspot::ContactList.find(-1) }.to raise_error(Hubspot::RequestError)
|
|
151
151
|
end
|
|
152
152
|
end
|
|
153
153
|
end
|
|
@@ -156,65 +156,65 @@ describe Hubspot::ContactList do
|
|
|
156
156
|
cassette "contact_list_batch_find"
|
|
157
157
|
|
|
158
158
|
it 'find lists of contacts' do
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
lists = Hubspot::ContactList.find([2,3,4])
|
|
160
|
+
list = lists.first
|
|
161
|
+
expect(list).to be_a(Hubspot::ContactList)
|
|
162
|
+
expect(list.id).to be == 2
|
|
163
|
+
expect(lists.second.id).to be == 3
|
|
164
|
+
expect(lists.last.id).to be == 4
|
|
165
165
|
end
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
-
describe '#add' do
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
contact = Hubspot::Contact.all(count: 1).first
|
|
169
|
+
describe '#add' do
|
|
170
|
+
cassette "add_contacts_to_lists"
|
|
171
|
+
|
|
172
|
+
context 'static list' do
|
|
173
|
+
it 'returns true if contacts have been added to the list' do
|
|
174
|
+
contact = Hubspot::Contact.all(count: 1).first
|
|
175
175
|
mock(Hubspot::Connection).post_json("/contacts/v1/lists/:list_id/add", {:params=>{:list_id=>4}, :body=>{:vids=>[contact.vid]}}) { { 'updated' => [contact.vid] } }
|
|
176
|
-
|
|
177
|
-
expect(static_list.add(contact)).to be true
|
|
178
|
-
end
|
|
179
176
|
|
|
180
|
-
|
|
177
|
+
expect(static_list.add(contact)).to be true
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'returns false if the contact already exists in the list' do
|
|
181
181
|
contact = static_list.contacts(count: 1).first
|
|
182
182
|
expect(static_list.add(contact)).to be false
|
|
183
183
|
end
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
context 'dynamic list' do
|
|
187
|
-
it 'raises error if try to add a contact to a dynamic list' do
|
|
188
|
-
contact = Hubspot::Contact.new(example_contact_hash)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
context 'dynamic list' do
|
|
187
|
+
it 'raises error if try to add a contact to a dynamic list' do
|
|
188
|
+
contact = Hubspot::Contact.new(example_contact_hash)
|
|
189
189
|
expect { dynamic_list.add(contact) }.to raise_error(Hubspot::RequestError)
|
|
190
190
|
end
|
|
191
191
|
end
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
describe '#remove' do
|
|
195
|
-
|
|
195
|
+
cassette "remove_contacts_from_lists"
|
|
196
196
|
|
|
197
197
|
context 'static list' do
|
|
198
|
-
it 'returns true if removes all contacts in batch mode' do
|
|
199
|
-
|
|
198
|
+
it 'returns true if removes all contacts in batch mode' do
|
|
199
|
+
contacts = static_list.contacts(count: 2)
|
|
200
200
|
expect(static_list.remove([contacts.first, contacts.last])).to be true
|
|
201
201
|
end
|
|
202
202
|
|
|
203
|
-
it 'returns false if the contact cannot be removed' do
|
|
204
|
-
contact_not_present_in_list = Hubspot::Contact.new(example_contact_hash)
|
|
203
|
+
it 'returns false if the contact cannot be removed' do
|
|
204
|
+
contact_not_present_in_list = Hubspot::Contact.new(example_contact_hash)
|
|
205
205
|
expect(static_list.remove(contact_not_present_in_list)).to be false
|
|
206
206
|
end
|
|
207
|
-
end
|
|
207
|
+
end
|
|
208
208
|
|
|
209
|
-
context 'dynamic list' do
|
|
210
|
-
it 'raises error if try to remove a contact from a dynamic list' do
|
|
211
|
-
|
|
212
|
-
expect { dynamic_list.remove(contact) }.to raise_error(Hubspot::RequestError)
|
|
209
|
+
context 'dynamic list' do
|
|
210
|
+
it 'raises error if try to remove a contact from a dynamic list' do
|
|
211
|
+
contact = dynamic_list.contacts(recent: true, count: 1).first
|
|
212
|
+
expect { dynamic_list.remove(contact) }.to raise_error(Hubspot::RequestError)
|
|
213
213
|
end
|
|
214
214
|
end
|
|
215
215
|
end
|
|
216
216
|
|
|
217
|
-
describe '#update!' do
|
|
217
|
+
describe '#update!' do
|
|
218
218
|
cassette "contact_list_update"
|
|
219
219
|
|
|
220
220
|
let(:contact_list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
|
@@ -225,13 +225,13 @@ describe Hubspot::ContactList do
|
|
|
225
225
|
its(:name){ should == "update list name" }
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
-
describe '#destroy!' do
|
|
228
|
+
describe '#destroy!' do
|
|
229
229
|
cassette "contact_list_destroy"
|
|
230
230
|
|
|
231
231
|
let(:contact_list) { Hubspot::ContactList.create!({ name: "newcontactlist_#{Time.now.to_i}"}) }
|
|
232
232
|
subject{ contact_list.destroy! }
|
|
233
233
|
it { should be_true }
|
|
234
|
-
|
|
234
|
+
|
|
235
235
|
it "should be destroyed" do
|
|
236
236
|
subject
|
|
237
237
|
contact_list.destroyed?.should be_true
|
|
@@ -239,11 +239,11 @@ describe Hubspot::ContactList do
|
|
|
239
239
|
end
|
|
240
240
|
|
|
241
241
|
describe '#refresh' do
|
|
242
|
-
cassette "contact_list_refresh"
|
|
242
|
+
cassette "contact_list_refresh"
|
|
243
243
|
|
|
244
244
|
let(:contact_list) { Hubspot::ContactList.new(example_contact_list_hash) }
|
|
245
245
|
subject { contact_list.refresh }
|
|
246
246
|
|
|
247
247
|
it { should be true }
|
|
248
248
|
end
|
|
249
|
-
end
|
|
249
|
+
end
|
|
@@ -1,8 +1,239 @@
|
|
|
1
1
|
describe Hubspot::ContactProperties do
|
|
2
2
|
describe '.add_default_parameters' do
|
|
3
3
|
subject { Hubspot::ContactProperties.add_default_parameters({}) }
|
|
4
|
-
context
|
|
5
|
-
its([:property]){ should ==
|
|
4
|
+
context 'default parameters' do
|
|
5
|
+
its([:property]) { should == 'email' }
|
|
6
6
|
end
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
let(:example_groups) do
|
|
10
|
+
VCR.use_cassette('groups_example', record: :once) do
|
|
11
|
+
HTTParty.get('https://api.hubapi.com/contacts/v2/groups?hapikey=demo').parsed_response
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:example_properties) do
|
|
16
|
+
VCR.use_cassette('properties_example', record: :once) do
|
|
17
|
+
HTTParty.get('https://api.hubapi.com/contacts/v2/properties?hapikey=demo').parsed_response
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
before { Hubspot.configure(hapikey: 'demo') }
|
|
22
|
+
|
|
23
|
+
describe 'Properties' do
|
|
24
|
+
describe '.all' do
|
|
25
|
+
context 'with no filter' do
|
|
26
|
+
cassette 'all_properties'
|
|
27
|
+
|
|
28
|
+
it 'should return all properties' do
|
|
29
|
+
expect(Hubspot::ContactProperties.all).to eql(example_properties)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
let(:groups) { %w(calltrackinginfo emailinformation) }
|
|
34
|
+
|
|
35
|
+
context 'with included groups' do
|
|
36
|
+
cassette 'properties_in_groups'
|
|
37
|
+
|
|
38
|
+
it 'should return properties for the specified group[s]' do
|
|
39
|
+
response = Hubspot::ContactProperties.all({}, { include: groups })
|
|
40
|
+
response.each { |p| expect(groups.include?(p['groupName'])).to be_true }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with excluded groups' do
|
|
45
|
+
cassette 'properties_not_in_groups'
|
|
46
|
+
|
|
47
|
+
it 'should return properties for the non-specified group[s]' do
|
|
48
|
+
response = Hubspot::ContactProperties.all({}, { exclude: groups })
|
|
49
|
+
response.each { |p| expect(groups.include?(p['groupName'])).to be_false }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
let(:params) { {
|
|
55
|
+
'name' => 'my_new_property',
|
|
56
|
+
'label' => 'This is my new property',
|
|
57
|
+
'description' => 'What kind of x would you like?',
|
|
58
|
+
'groupName' => 'contactinformation',
|
|
59
|
+
'type' => 'string',
|
|
60
|
+
'fieldType' => 'text',
|
|
61
|
+
'hidden' => false,
|
|
62
|
+
'options' => [],
|
|
63
|
+
'deleted' => false,
|
|
64
|
+
'displayOrder' => 0,
|
|
65
|
+
'formField' => true,
|
|
66
|
+
'readOnlyValue' => false,
|
|
67
|
+
'readOnlyDefinition' => false,
|
|
68
|
+
'mutableDefinitionNotDeletable' => false,
|
|
69
|
+
'calculated' => false,
|
|
70
|
+
'externalOptions' => false,
|
|
71
|
+
'displayMode' => 'current_value'
|
|
72
|
+
} }
|
|
73
|
+
let(:valid_params) { params.select { |k, _| Hubspot::ContactProperties::PROPERTY_SPECS[:field_names].include?(k) } }
|
|
74
|
+
|
|
75
|
+
describe '.create!' do
|
|
76
|
+
context 'with no valid parameters' do
|
|
77
|
+
cassette 'fail_to_create_property'
|
|
78
|
+
|
|
79
|
+
it 'should return nil' do
|
|
80
|
+
expect(Hubspot::ContactProperties.create!({})).to be(nil)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context 'with all valid parameters' do
|
|
85
|
+
cassette 'create_property'
|
|
86
|
+
|
|
87
|
+
it 'should return the valid parameters' do
|
|
88
|
+
response = Hubspot::ContactProperties.create!(params)
|
|
89
|
+
valid_params.each { |k, v| expect(response[k]).to eq(v) }
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe '.update!' do
|
|
95
|
+
context 'with no valid parameters' do
|
|
96
|
+
|
|
97
|
+
it 'should return nil ' do
|
|
98
|
+
expect(Hubspot::ContactProperties.update!(params['name'], {})).to be(nil)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context 'with mixed parameters' do
|
|
103
|
+
cassette 'update_property'
|
|
104
|
+
|
|
105
|
+
it 'should return the valid parameters' do
|
|
106
|
+
params['description'] = 'What is their favorite flavor?'
|
|
107
|
+
valid_params['description'] = params['description']
|
|
108
|
+
|
|
109
|
+
response = Hubspot::ContactProperties.update!(params['name'], params)
|
|
110
|
+
valid_params.each { |k, v| expect(response[k]).to eq(v) }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe '.delete!' do
|
|
116
|
+
let(:name) { params['name'] }
|
|
117
|
+
|
|
118
|
+
context 'with existing property' do
|
|
119
|
+
cassette 'delete_property'
|
|
120
|
+
|
|
121
|
+
it 'should return nil' do
|
|
122
|
+
expect(Hubspot::ContactProperties.delete!(name)).to eq(nil)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context 'with non-existent property' do
|
|
127
|
+
cassette 'delete_non_property'
|
|
128
|
+
|
|
129
|
+
it 'should raise an error' do
|
|
130
|
+
expect { Hubspot::ContactProperties.delete!(name) }.to raise_error(Hubspot::RequestError)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe 'Groups' do
|
|
137
|
+
describe '.groups' do
|
|
138
|
+
context 'with no filter' do
|
|
139
|
+
cassette 'all_groups'
|
|
140
|
+
|
|
141
|
+
it 'should return all groups' do
|
|
142
|
+
expect(Hubspot::ContactProperties.groups).to eql(example_groups)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
let(:groups) { %w(calltrackinginfo emailinformation) }
|
|
147
|
+
|
|
148
|
+
context 'with included groups' do
|
|
149
|
+
cassette 'groups_included'
|
|
150
|
+
|
|
151
|
+
it 'should return the specified groups' do
|
|
152
|
+
response = Hubspot::ContactProperties.groups({}, { include: groups })
|
|
153
|
+
response.each { |p| expect(groups.include?(p['name'])).to be_true }
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
context 'with excluded groups' do
|
|
158
|
+
cassette 'groups_not_excluded'
|
|
159
|
+
|
|
160
|
+
it 'should return groups that were not excluded' do
|
|
161
|
+
response = Hubspot::ContactProperties.groups({}, { exclude: groups })
|
|
162
|
+
response.each { |p| expect(groups.include?(p['name'])).to be_false }
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
let(:params) { { 'name' => 'ff_group1', 'displayName' => 'Test Group One', 'displayOrder' => 100, 'badParam' => 99 } }
|
|
168
|
+
|
|
169
|
+
describe '.create_group!' do
|
|
170
|
+
context 'with no valid parameters' do
|
|
171
|
+
it 'should return nil' do
|
|
172
|
+
expect(Hubspot::ContactProperties.create_group!({})).to be(nil)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
context 'with mixed parameters' do
|
|
177
|
+
cassette 'create_group'
|
|
178
|
+
|
|
179
|
+
it 'should return the valid parameters' do
|
|
180
|
+
response = Hubspot::ContactProperties.create_group!(params)
|
|
181
|
+
expect(Hubspot::ContactProperties.same?(response, params)).to be_true
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
context 'with some valid parameters' do
|
|
186
|
+
cassette 'create_group_some_params'
|
|
187
|
+
|
|
188
|
+
let(:sub_params) { params.select { |k, _| k != 'displayName' } }
|
|
189
|
+
|
|
190
|
+
it 'should return the valid parameters' do
|
|
191
|
+
params['name'] = 'ff_group234'
|
|
192
|
+
response = Hubspot::ContactProperties.create_group!(sub_params)
|
|
193
|
+
expect(Hubspot::ContactProperties.same?(response, sub_params)).to be_true
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
describe '.update_group!' do
|
|
199
|
+
context 'with no valid parameters' do
|
|
200
|
+
|
|
201
|
+
it 'should return nil ' do
|
|
202
|
+
expect(Hubspot::ContactProperties.update_group!(params['name'], {})).to be(nil)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
context 'with mixed parameters' do
|
|
207
|
+
cassette 'update_group'
|
|
208
|
+
|
|
209
|
+
it 'should return the valid parameters' do
|
|
210
|
+
params['displayName'] = 'Test Group OneA'
|
|
211
|
+
|
|
212
|
+
response = Hubspot::ContactProperties.update_group!(params['name'], params)
|
|
213
|
+
expect(Hubspot::ContactProperties.same?(response, params)).to be_true
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
describe '.delete_group!' do
|
|
220
|
+
let(:name) { params['name'] }
|
|
221
|
+
|
|
222
|
+
context 'with existing group' do
|
|
223
|
+
cassette 'delete_group'
|
|
224
|
+
|
|
225
|
+
it 'should return nil' do
|
|
226
|
+
expect(Hubspot::ContactProperties.delete_group!(name)).to eq(nil)
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
context 'with non-existent group' do
|
|
231
|
+
cassette 'delete_non_group'
|
|
232
|
+
|
|
233
|
+
it 'should raise an error' do
|
|
234
|
+
expect { Hubspot::ContactProperties.delete_group!(name) }.to raise_error(Hubspot::RequestError)
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|