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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -22
  3. data/Gemfile.lock +14 -11
  4. data/LICENSE.txt +0 -2
  5. data/README.md +8 -6
  6. data/RELEASING.md +4 -5
  7. data/Rakefile +2 -17
  8. data/hubspot-ruby.gemspec +20 -157
  9. data/lib/hubspot-ruby.rb +10 -0
  10. data/lib/hubspot/blog.rb +1 -2
  11. data/lib/hubspot/company.rb +149 -0
  12. data/lib/hubspot/company_properties.rb +59 -0
  13. data/lib/hubspot/config.rb +10 -4
  14. data/lib/hubspot/connection.rb +12 -4
  15. data/lib/hubspot/contact.rb +52 -31
  16. data/lib/hubspot/contact_list.rb +16 -16
  17. data/lib/hubspot/contact_properties.rb +53 -6
  18. data/lib/hubspot/deal.rb +2 -2
  19. data/lib/hubspot/deal_pipeline.rb +43 -0
  20. data/lib/hubspot/deal_properties.rb +59 -0
  21. data/lib/hubspot/engagement.rb +133 -0
  22. data/lib/hubspot/exceptions.rb +1 -1
  23. data/lib/hubspot/form.rb +20 -20
  24. data/lib/hubspot/owner.rb +49 -0
  25. data/lib/hubspot/properties.rb +119 -0
  26. data/lib/hubspot/railtie.rb +10 -0
  27. data/lib/hubspot/topic.rb +2 -2
  28. data/lib/hubspot/utils.rb +106 -3
  29. data/spec/lib/hubspot/blog_spec.rb +2 -0
  30. data/spec/lib/hubspot/company_properties_spec.rb +239 -0
  31. data/spec/lib/hubspot/company_spec.rb +190 -0
  32. data/spec/lib/hubspot/config_spec.rb +1 -1
  33. data/spec/lib/hubspot/connection_spec.rb +33 -27
  34. data/spec/lib/hubspot/contact_list_spec.rb +61 -61
  35. data/spec/lib/hubspot/contact_properties_spec.rb +234 -3
  36. data/spec/lib/hubspot/contact_spec.rb +140 -71
  37. data/spec/lib/hubspot/deal_properties_spec.rb +254 -0
  38. data/spec/lib/hubspot/engagement_spec.rb +87 -0
  39. data/spec/lib/hubspot/form_spec.rb +72 -60
  40. data/spec/lib/hubspot/owner_spec.rb +56 -0
  41. data/spec/lib/hubspot/properties_spec.rb +45 -0
  42. data/spec/lib/hubspot/topic_spec.rb +0 -1
  43. data/spec/lib/hubspot/utils_spec.rb +113 -15
  44. data/spec/lib/tasks/properties_spec.rb +90 -0
  45. data/spec/live/companies_integration_spec.rb +23 -0
  46. data/spec/live/companies_properties_integration_spec.rb +120 -0
  47. data/spec/live/contacts_integration_spec.rb +1 -1
  48. data/spec/live/contacts_properties_integration_spec.rb +120 -0
  49. data/spec/live/deal_properties_integration_spec.rb +123 -0
  50. data/spec/live/deals_integration_spec.rb +1 -1
  51. data/spec/support/cassette_helper.rb +1 -1
  52. data/spec/support/tests_helper.rb +3 -3
  53. metadata +39 -78
  54. data/.document +0 -5
  55. data/lib/hubspot/version.rb +0 -9
  56. data/spec/fixtures/vcr_cassettes/add_contacts_to_lists.yml +0 -281
  57. data/spec/fixtures/vcr_cassettes/blog_list.yml +0 -180
  58. data/spec/fixtures/vcr_cassettes/blog_posts.yml +0 -107
  59. data/spec/fixtures/vcr_cassettes/blog_posts_list.yml +0 -6463
  60. data/spec/fixtures/vcr_cassettes/contact_create.yml +0 -64
  61. data/spec/fixtures/vcr_cassettes/contact_create_existing_email.yml +0 -62
  62. data/spec/fixtures/vcr_cassettes/contact_create_invalid_email.yml +0 -63
  63. data/spec/fixtures/vcr_cassettes/contact_create_with_params.yml +0 -64
  64. data/spec/fixtures/vcr_cassettes/contact_destroy.yml +0 -131
  65. data/spec/fixtures/vcr_cassettes/contact_example.yml +0 -32
  66. data/spec/fixtures/vcr_cassettes/contact_find_by_email.yml +0 -59
  67. data/spec/fixtures/vcr_cassettes/contact_find_by_email_batch_mode.yml +0 -509
  68. data/spec/fixtures/vcr_cassettes/contact_find_by_id.yml +0 -59
  69. data/spec/fixtures/vcr_cassettes/contact_find_by_id_batch_mode.yml +0 -33
  70. data/spec/fixtures/vcr_cassettes/contact_find_by_utk.yml +0 -83
  71. data/spec/fixtures/vcr_cassettes/contact_find_by_utk_batch_mode.yml +0 -33
  72. data/spec/fixtures/vcr_cassettes/contact_list_batch_find.yml +0 -65
  73. data/spec/fixtures/vcr_cassettes/contact_list_destroy.yml +0 -63
  74. data/spec/fixtures/vcr_cassettes/contact_list_example.yml +0 -33
  75. data/spec/fixtures/vcr_cassettes/contact_list_find.yml +0 -96
  76. data/spec/fixtures/vcr_cassettes/contact_list_refresh.yml +0 -33
  77. data/spec/fixtures/vcr_cassettes/contact_list_update.yml +0 -36
  78. data/spec/fixtures/vcr_cassettes/contact_update.yml +0 -66
  79. data/spec/fixtures/vcr_cassettes/contacts_among_list.yml +0 -189
  80. data/spec/fixtures/vcr_cassettes/create_form.yml +0 -39
  81. data/spec/fixtures/vcr_cassettes/create_list.yml +0 -36
  82. data/spec/fixtures/vcr_cassettes/create_list_with_filters.yml +0 -36
  83. data/spec/fixtures/vcr_cassettes/deal_create.yml +0 -61
  84. data/spec/fixtures/vcr_cassettes/deal_example.yml +0 -166
  85. data/spec/fixtures/vcr_cassettes/deal_find.yml +0 -115
  86. data/spec/fixtures/vcr_cassettes/destroy_deal.yml +0 -221
  87. data/spec/fixtures/vcr_cassettes/fail_to_create_form.yml +0 -35
  88. data/spec/fixtures/vcr_cassettes/fail_to_create_list.yml +0 -35
  89. data/spec/fixtures/vcr_cassettes/field_among_form.yml +0 -34
  90. data/spec/fixtures/vcr_cassettes/fields_among_form.yml +0 -35
  91. data/spec/fixtures/vcr_cassettes/find_all_contacts.yml +0 -297
  92. data/spec/fixtures/vcr_cassettes/find_all_dynamic_lists.yml +0 -104
  93. data/spec/fixtures/vcr_cassettes/find_all_forms.yml +0 -15378
  94. data/spec/fixtures/vcr_cassettes/find_all_lists.yml +0 -138
  95. data/spec/fixtures/vcr_cassettes/find_all_recent_contacts.yml +0 -33
  96. data/spec/fixtures/vcr_cassettes/find_all_recent_updated_deals.yml +0 -130
  97. data/spec/fixtures/vcr_cassettes/find_all_stastic_lists.yml +0 -21876
  98. data/spec/fixtures/vcr_cassettes/form_destroy.yml +0 -64
  99. data/spec/fixtures/vcr_cassettes/form_example.yml +0 -39
  100. data/spec/fixtures/vcr_cassettes/form_find.yml +0 -69
  101. data/spec/fixtures/vcr_cassettes/form_post.yml +0 -31
  102. data/spec/fixtures/vcr_cassettes/form_submit_data.yml +0 -130
  103. data/spec/fixtures/vcr_cassettes/form_update.yml +0 -77
  104. data/spec/fixtures/vcr_cassettes/one_month_blog_posts_filter_state.yml +0 -19127
  105. data/spec/fixtures/vcr_cassettes/one_month_blog_posts_list.yml +0 -34963
  106. data/spec/fixtures/vcr_cassettes/remove_contacts_from_lists.yml +0 -315
  107. data/spec/fixtures/vcr_cassettes/topic_list.yml +0 -48
  108. data/spec/fixtures/vcr_cassettes/topics_list.yml +0 -86
@@ -50,4 +50,4 @@ describe Hubspot::Config do
50
50
  end
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -1,42 +1,48 @@
1
1
  describe Hubspot::Connection do
2
2
  before(:each) do
3
- @url = 'http://localhost:3000'
4
- @http_reponse = mock('http_response')
3
+ @url = 'http://localhost:3000'
4
+ @http_response = mock('http_response')
5
5
  end
6
6
 
7
- describe '.get_json' do
8
- it 'delegates url format to Hubspot::Utils, call HTTParty get and returns response' do
9
- @http_reponse.success? { true }
10
- @http_reponse.parsed_response { {} }
11
-
12
- mock(Hubspot::Connection).generate_url(@url, {}) { @url }
13
- mock(Hubspot::Connection).get(@url, format: :json) { @http_reponse }
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
- end
17
+ end
16
18
  end
17
19
 
18
- describe '.post_json' do
19
- it 'delegates url format to Hubspot::Utils, call HTTParty post and returns response' do
20
- @http_reponse.success? { true }
21
- @http_reponse.parsed_response { {} }
22
-
23
- mock(Hubspot::Connection).generate_url(@url, {}) { @url }
24
- mock(Hubspot::Connection).post(@url, body: "{}", headers: {"Content-Type"=>"application/json"}, format: :json) { @http_reponse }
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
- end
30
+ end
27
31
  end
28
32
 
29
- describe '.delete_json' do
30
- it 'delegates url format to Hubspot::Utils, call HTTParty delete and returns response' do
31
- @http_reponse.success? { true }
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
- mock(Hubspot::Connection).generate_url(@url, {}) { @url }
34
- mock(Hubspot::Connection).delete(@url, format: :json) { @http_reponse }
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
- end
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
- 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
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
- 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
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
- it 'returns false if the contact already exists in the list' do
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
- 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)
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
- cassette "remove_contacts_from_lists"
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
- contacts = static_list.contacts(count: 2)
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
- contact = dynamic_list.contacts(recent: true, count: 1).first
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 "default parameters" do
5
- its([:property]){ should == "email" }
4
+ context 'default parameters' do
5
+ its([:property]) { should == 'email' }
6
6
  end
7
7
  end
8
- end
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