hubspot-api-ruby 0.8.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/hubspot/deal.rb CHANGED
@@ -12,8 +12,6 @@ module Hubspot
12
12
  DEAL_PATH = "/deals/v1/deal/:deal_id"
13
13
  RECENT_UPDATED_PATH = "/deals/v1/deal/recent/modified"
14
14
  UPDATE_DEAL_PATH = '/deals/v1/deal/:deal_id'
15
- ASSOCIATE_DEAL_PATH = '/deals/v1/deal/:deal_id/associations/:OBJECTTYPE?id=:objectId'
16
- ASSOCIATED_DEAL_PATH = "/deals/v1/deal/associated/:objectType/:objectId"
17
15
 
18
16
  attr_reader :properties
19
17
  attr_reader :portal_id
@@ -61,25 +59,53 @@ module Hubspot
61
59
  response.success?
62
60
  end
63
61
 
64
- # Associate a deal with a contact or company
65
- # {http://developers.hubspot.com/docs/methods/deals/associate_deal}
66
- # Usage
67
- # Hubspot::Deal.associate!(45146940, [], [52])
68
- def associate!(deal_id, company_ids=[], vids=[])
69
- objecttype = company_ids.any? ? 'COMPANY' : 'CONTACT'
70
- object_ids = (company_ids.any? ? company_ids : vids).join('&id=')
71
- Hubspot::Connection.put_json(ASSOCIATE_DEAL_PATH, params: { deal_id: deal_id, OBJECTTYPE: objecttype, objectId: object_ids}, body: {})
72
- end
73
-
74
- # Didssociate a deal with a contact or company
75
- # {https://developers.hubspot.com/docs/methods/deals/delete_association}
76
- # Usage
77
- # Hubspot::Deal.dissociate!(45146940, [], [52])
78
- def dissociate!(deal_id, company_ids=[], vids=[])
79
- objecttype = company_ids.any? ? 'COMPANY' : 'CONTACT'
80
- object_ids = (company_ids.any? ? company_ids : vids).join('&id=')
81
- Hubspot::Connection.delete_json(ASSOCIATE_DEAL_PATH, { deal_id: deal_id, OBJECTTYPE: objecttype, objectId: object_ids })
82
- end
62
+ # Associate a deal with a contact or company
63
+ # {http://developers.hubspot.com/docs/methods/deals/associate_deal}
64
+ # Usage
65
+ # Hubspot::Deal.associate!(45146940, [32], [52])
66
+ def associate!(deal_id, company_ids=[], vids=[])
67
+ company_associations = associations = company_ids.map do |id|
68
+ { from_id: deal_id, to_id: id }
69
+ end
70
+
71
+ contact_associations = vids.map do |id|
72
+ { from_id: deal_id, to_id: id}
73
+ end
74
+
75
+ results = []
76
+ if company_associations.any?
77
+ results << HubSpot::Association.batch_create("Deal", "Company", company_associations)
78
+ end
79
+ if contact_associations.any?
80
+ results << HubSpot::Association.batch_create("Deal", "Contact", contact_associations)
81
+ end
82
+
83
+ results.all?
84
+ end
85
+
86
+ # Didssociate a deal with a contact or company
87
+ # {https://developers.hubspot.com/docs/methods/deals/delete_association}
88
+ # Usage
89
+ # Hubspot::Deal.dissociate!(45146940, [32], [52])
90
+ def dissociate!(deal_id, company_ids=[], vids=[])
91
+ company_associations = company_ids.map do |id|
92
+ { from_id: deal_id, to_id: id }
93
+ end
94
+
95
+ contact_associations = vids.map do |id|
96
+ { from_id: deal_id, to_id: id }
97
+ end
98
+
99
+ results = []
100
+ if company_associations.any?
101
+ results << HubSpot::Association.batch_delete("Deal", "Company", company_associations)
102
+ end
103
+ if contact_associations.any?
104
+ results << HubSpot::Association.batch_delete("Deal", "Contact", contact_associations)
105
+ end
106
+
107
+ results.all?
108
+ end
83
109
 
84
110
  def find(deal_id)
85
111
  response = Hubspot::Connection.get_json(DEAL_PATH, { deal_id: deal_id })
@@ -125,20 +151,15 @@ module Hubspot
125
151
  end
126
152
 
127
153
  # Find all deals associated to a contact or company
128
- # {http://developers.hubspot.com/docs/methods/deals/get-associated-deals}
129
154
  # @param object [Hubspot::Contact || Hubspot::Company] a contact or company
130
155
  # @return [Array] Array of Hubspot::Deal records
131
156
  def find_by_association(object)
132
- path = ASSOCIATED_DEAL_PATH
133
- objectType = case object
134
- when Hubspot::Company then :company
135
- when Hubspot::Contact then :contact
136
- else raise(Hubspot::InvalidParams, "Instance type not supported")
137
- end
138
-
139
- params = { objectType: objectType, objectId: object.id }
140
- response = Hubspot::Connection.get_json(path, params)
141
- response["results"].map { |deal_id| find(deal_id) }
157
+ to_object_type = case object
158
+ when Hubspot::Company then "Company"
159
+ when Hubspot::Contact then "Contact"
160
+ else raise(Hubspot::InvalidParams, 'Instance type not supported')
161
+ end
162
+ Hubspot::Association.all(to_object_type, object.id, "Deal")
142
163
  end
143
164
  end
144
165
 
@@ -21,7 +21,6 @@ module Hubspot
21
21
  attr_reader :metadata
22
22
 
23
23
  def initialize(response_hash)
24
-
25
24
  @engagement = response_hash["engagement"]
26
25
  @associations = response_hash["associations"]
27
26
  @attachments = response_hash["attachments"]
@@ -10,6 +10,8 @@ module Hubspot
10
10
  end
11
11
  end
12
12
 
13
+ class NotFoundError < RequestError; end
14
+
13
15
  class ConfigurationError < StandardError; end
14
16
  class MissingInterpolation < StandardError; end
15
17
  class ContactExistsError < RequestError; end
data/lib/hubspot/file.rb CHANGED
@@ -10,7 +10,7 @@ module Hubspot
10
10
  #
11
11
  class File
12
12
  GET_FILE_PATH = "/filemanager/api/v2/files/:file_id"
13
- DELETE_FILE_PATH = "/filemanager/api/v2/files/:file_id/full-delete"
13
+ DELETE_FILE_PATH = "/filemanager/api/v2/files/:file_id/full-delete"
14
14
  LIST_FILE_PATH = "/filemanager/api/v2/files"
15
15
 
16
16
  attr_reader :id
@@ -24,7 +24,7 @@ module Hubspot
24
24
  class << self
25
25
  def find_by_id(file_id)
26
26
  response = Hubspot::Connection.get_json(GET_FILE_PATH, { file_id: file_id })
27
- new(response)
27
+ new(response)
28
28
  end
29
29
  end
30
30
 
@@ -0,0 +1,44 @@
1
+ require 'hubspot/utils'
2
+
3
+ module Hubspot
4
+ class Meeting
5
+ #
6
+ # HubSpot Meeting API
7
+ #
8
+ # {https://developers.hubspot.com/docs/api/crm/meetings}
9
+ #
10
+ CREATE_MEETING_PATH = '/crm/v3/objects/meetings'
11
+ MEETING_PATH = '/crm/v3/objects/meetings/:meeting_id'
12
+ ASSOCIATE_MEETING_PATH = '/crm/v3/objects/meetings/:meeting_id/associations/Contact/:contact_id/meeting_event_to_contact'
13
+
14
+ class << self
15
+ def create!(owner_id, meeting_title, meeting_body, start_date_time, end_date_time)
16
+ body = {
17
+ properties: {
18
+ hs_timestamp: DateTime.now.strftime('%Q'),
19
+ hubspot_owner_id: owner_id,
20
+ hs_meeting_title: meeting_title,
21
+ hs_meeting_body: meeting_body,
22
+ hs_meeting_start_time: start_date_time.is_a?(DateTime) ? start_date_time.strftime('%Q') : start_date_time,
23
+ hs_meeting_end_time: end_date_time.is_a?(DateTime) ? end_date_time.strftime('%Q') : end_date_time,
24
+ hs_meeting_outcome: 'SCHEDULED'
25
+ }
26
+ }
27
+ response = Hubspot::Connection.post_json(CREATE_MEETING_PATH, params: {}, body: body)
28
+ HashWithIndifferentAccess.new(response)
29
+ end
30
+
31
+ def destroy!(meeting_id)
32
+ Hubspot::Connection.delete_json(MEETING_PATH, {meeting_id: meeting_id})
33
+ end
34
+
35
+ def associate!(meeting_id, contact_id)
36
+ Hubspot::Connection.put_json(ASSOCIATE_MEETING_PATH,
37
+ params: {
38
+ meeting_id: meeting_id,
39
+ contact_id: contact_id
40
+ })
41
+ end
42
+ end
43
+ end
44
+ end
@@ -97,7 +97,7 @@ module Hubspot
97
97
 
98
98
  def valid_group_params(params)
99
99
  return {} if params.blank?
100
- result = params.slice(*PROPERTY_SPECS[:group_field_names])
100
+ result = params.with_indifferent_access.slice(*PROPERTY_SPECS[:group_field_names])
101
101
  result['properties'] = valid_property_params(result['properties']) unless result['properties'].blank?
102
102
  result
103
103
  end
@@ -2,9 +2,5 @@ require 'hubspot-api-ruby'
2
2
  require 'rails'
3
3
  module Hubspot
4
4
  class Railtie < Rails::Railtie
5
- rake_tasks do
6
- spec = Gem::Specification.find_by_name('hubspot-api-ruby')
7
- load "#{spec.gem_dir}/lib/tasks/hubspot.rake"
8
- end
9
5
  end
10
6
  end
@@ -98,7 +98,7 @@ module Hubspot
98
98
  end
99
99
 
100
100
  def [](name)
101
- @changes[name] || @properties[name]
101
+ @changes[name] || @properties.dig(name, 'value')
102
102
  end
103
103
 
104
104
  def reload
@@ -238,7 +238,7 @@ module Hubspot
238
238
  singleton_class.instance_eval do
239
239
  keys.each do |k|
240
240
  # Define a getter
241
- define_method(k) { @changes[k.to_sym] || @properties.dig(k, "value") }
241
+ define_method(k) { @changes[k.to_sym] || @properties.dig(k, 'value') }
242
242
 
243
243
  # Define a setter
244
244
  define_method("#{k}=") do |v|
@@ -257,7 +257,7 @@ module Hubspot
257
257
  # Call the new setter
258
258
  return send(method_name, arguments[0])
259
259
  elsif @properties.key?(method_name)
260
- return @properties[method_name]
260
+ return @properties[method_name]['value']
261
261
  else
262
262
  super
263
263
  end
@@ -267,4 +267,4 @@ module Hubspot
267
267
  (@properties && @properties.key?(method_name)) || super
268
268
  end
269
269
  end
270
- end
270
+ end
data/lib/hubspot/utils.rb CHANGED
@@ -20,31 +20,6 @@ module Hubspot
20
20
  hash.map { |k, v| { key_name => k.to_s, "value" => v } }
21
21
  end
22
22
 
23
- def dump_properties(klass, hapikey=ENV['HUBSPOT_API_KEY'], filter={})
24
- Hubspot::Deprecator.build.deprecation_warning("Hubspot::Utils.dump_properties")
25
-
26
- with_hapikey(hapikey) do
27
- { 'groups' => klass.groups({}, filter),
28
- 'properties' => klass.all({}, filter).select { |p| !p['hubspotDefined'] }
29
- }
30
- end
31
- end
32
-
33
- def restore_properties(klass, hapikey=ENV['HUPSPOT_API_KEY'], properties={}, dry_run=false)
34
- Hubspot::Deprecator.build.deprecation_warning("Hubspot::Utils.restore_properties")
35
-
36
- existing_properties = dump_properties(klass, hapikey)
37
- skip, new_groups, new_props, update_props = compare_property_lists(klass, properties, existing_properties)
38
- puts '', 'Dry Run - Changes will not be applied' if dry_run
39
- puts '','Skipping'
40
- skip.each { |h| puts "#{h[:reason]} - #{h[:prop]['groupName']}:#{h[:prop]['name']}" }
41
- with_hapikey(hapikey) do
42
- create_groups(klass, new_groups, dry_run)
43
- create_properties(klass, new_props, dry_run)
44
- update_properties(klass, update_props, dry_run)
45
- end
46
- end
47
-
48
23
  def create_groups(klass, groups, dry_run=false)
49
24
  puts '','Creating new groups'
50
25
  groups.each do |g|
@@ -112,11 +87,6 @@ module Hubspot
112
87
  [skip, new_groups.to_a, new_props, update_props]
113
88
  end
114
89
 
115
- def with_hapikey(hapikey)
116
- Hubspot.configure(hapikey: hapikey)
117
- yield if block_given?
118
- end
119
-
120
90
  private
121
91
 
122
92
  def find_by_name(name, set)
@@ -14,18 +14,21 @@ require 'hubspot/contact'
14
14
  require 'hubspot/contact_properties'
15
15
  require 'hubspot/contact_list'
16
16
  require 'hubspot/event'
17
+ require 'hubspot/custom_event'
17
18
  require 'hubspot/form'
18
19
  require 'hubspot/blog'
19
20
  require 'hubspot/topic'
20
21
  require 'hubspot/deal'
21
22
  require 'hubspot/deal_pipeline'
22
23
  require 'hubspot/deal_properties'
24
+ require 'hubspot/association'
23
25
  require 'hubspot/deprecator'
24
26
  require 'hubspot/owner'
25
27
  require 'hubspot/engagement'
26
28
  require 'hubspot/subscription'
27
29
  require 'hubspot/oauth'
28
30
  require 'hubspot/file'
31
+ require 'hubspot/meeting'
29
32
 
30
33
  module Hubspot
31
34
  def self.configure(config={})
@@ -0,0 +1,165 @@
1
+ RSpec.describe Hubspot::Association do
2
+ let(:portal_id) { 62515 }
3
+ let(:company) { create :company }
4
+ let(:contact) { create :contact }
5
+
6
+ describe '.create' do
7
+ context 'with a valid ID' do
8
+ cassette
9
+ subject { described_class.create("Company", company.id, "Contact", contact.id) }
10
+
11
+ it 'associates the resources' do
12
+ expect(subject).to be true
13
+ expect(company.contact_ids.resources).to eq [contact.id]
14
+ end
15
+ end
16
+
17
+ context 'with an invalid ID' do
18
+ cassette
19
+ subject { described_class.create("Company", 1234, "Contact", 1234) }
20
+
21
+ it 'returns false' do
22
+ expect(subject).to be false
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '.batch_create' do
28
+ let(:deal) { Hubspot::Deal.create!(portal_id, [], [], {}) }
29
+ let(:contact2) { create :contact }
30
+
31
+ subject { described_class.batch_create(*associations) }
32
+
33
+ context 'with a valid request' do
34
+ cassette
35
+ let(:associations) do
36
+ [
37
+ "Deal",
38
+ "Contact",
39
+ [
40
+ { from_id: deal.deal_id, to_id: contact.id},
41
+ { from_id: deal.deal_id, to_id: contact2.id}
42
+ ]
43
+ ]
44
+ end
45
+
46
+ it 'associates the resources' do
47
+ expect(subject).to be true
48
+ find_deal = Hubspot::Deal.find(deal.deal_id)
49
+ expect(find_deal.vids).to eq [contact.id, contact2.id]
50
+ end
51
+ end
52
+
53
+ context 'with an invalid ID' do
54
+ cassette
55
+ let(:associations) do
56
+ [
57
+ "Deal",
58
+ "Contact",
59
+ [
60
+ { from_id: deal.deal_id, to_id: 1234 }
61
+ ]
62
+ ]
63
+ end
64
+
65
+ it 'returns false' do
66
+ expect(subject).to eq(false)
67
+ find_deal = Hubspot::Deal.find(deal.deal_id)
68
+ expect(find_deal.vids).to eq []
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '.delete' do
74
+ subject { described_class.delete("Company", company.id, "Contact", contact_id_to_dissociate) }
75
+ before { described_class.create("Company", company.id, "Contact", contact.id) }
76
+
77
+ context 'with a valid ID' do
78
+ cassette
79
+ let(:contact_id_to_dissociate) { contact.id }
80
+
81
+ it 'dissociates the resources' do
82
+ expect(subject).to be true
83
+ expect(company.contact_ids.resources).to eq []
84
+ end
85
+ end
86
+
87
+ context 'with an invalid ID' do
88
+ cassette
89
+ let(:contact_id_to_dissociate) { 1234 }
90
+
91
+ it 'does not raise an error' do
92
+ expect(subject).to be true
93
+ expect(company.contact_ids.resources).to eq [contact.id]
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '.batch_delete' do
99
+ let(:company2) { create(:company) }
100
+ let(:deal) { Hubspot::Deal.create!(portal_id, [company.id, company2.id], [], {}) }
101
+
102
+ subject { described_class.batch_delete("Deal", "Company", associations) }
103
+
104
+ context 'with a valid request' do
105
+ cassette
106
+ let(:associations) do
107
+ [
108
+ { from_id: deal.deal_id, to_id: company.id },
109
+ { from_id: deal.deal_id, to_id: company2.id }
110
+ ]
111
+ end
112
+
113
+ it 'dissociates the resources' do
114
+ expect(subject).to be true
115
+ find_deal = Hubspot::Deal.find(deal.deal_id)
116
+ expect(find_deal.company_ids).to eq []
117
+ end
118
+ end
119
+
120
+ context 'with an invalid ID' do
121
+ cassette
122
+ let(:associations) do
123
+ [
124
+ { from_id: deal.deal_id, to_id: 1234 },
125
+ { from_id: deal.deal_id, to_id: company.id }
126
+ ]
127
+ end
128
+
129
+ it 'does not raise an error, removes the valid associations' do
130
+ expect(subject).to be true
131
+ find_deal = Hubspot::Deal.find(deal.deal_id)
132
+ expect(find_deal.company_ids).to eq [company2.id]
133
+ end
134
+ end
135
+ end
136
+
137
+ describe '.all' do
138
+ subject { described_class.all(resource_type, resource_id, to_object_type) }
139
+
140
+ context 'with valid params' do
141
+ cassette
142
+
143
+ let(:resource_type) { "Deal" }
144
+ let(:resource_id) { deal.deal_id }
145
+ let(:to_object_type) { "Contact" }
146
+ let(:deal) { Hubspot::Deal.create!(portal_id, [], contact_ids, {}) }
147
+ let(:contact_ids) { [contact.id, second_contact.id] }
148
+ let(:second_contact) { create :contact }
149
+
150
+ it 'finds the resources' do
151
+ expect(subject.map(&:id)).to contain_exactly(*contact_ids)
152
+ end
153
+ end
154
+
155
+ context 'with unsupported object_type' do
156
+ let(:resource_type) { "Contact" }
157
+ let(:resource_id) { 1234 }
158
+ let(:to_object_type) { "Foo" }
159
+
160
+ it 'raises an error' do
161
+ expect { subject }.to raise_error(Hubspot::InvalidParams, 'Object type not supported')
162
+ end
163
+ end
164
+ end
165
+ end
@@ -1,14 +1,12 @@
1
1
  require 'timecop'
2
2
 
3
3
  describe Hubspot do
4
- before do
5
- Hubspot.configure(hapikey: "demo")
6
- Timecop.freeze(Time.utc(2012, 'Oct', 10))
7
- end
4
+ before { Timecop.freeze(Time.utc(2012, 'Oct', 10)) }
8
5
 
9
- after do
10
- Timecop.return
11
- end
6
+ after { Timecop.return }
7
+
8
+ let(:last_blog_id) { Hubspot::Blog.list.last['id'] }
9
+ let(:last_blog_post_id) { Hubspot::Blog.list.last.posts.first['id'] }
12
10
 
13
11
  describe Hubspot::Blog do
14
12
  describe ".list" do
@@ -16,7 +14,6 @@ describe Hubspot do
16
14
  VCR.use_cassette("blog_list") do
17
15
  result = Hubspot::Blog.list
18
16
 
19
- assert_requested :get, hubspot_api_url("/content/api/v2/blogs?hapikey=demo")
20
17
  expect(result).to be_kind_of(Array)
21
18
  expect(result.first).to be_a(Hubspot::Blog)
22
19
  end
@@ -26,10 +23,8 @@ describe Hubspot do
26
23
  describe ".find_by_id" do
27
24
  it "retrieves a blog by id" do
28
25
  VCR.use_cassette("blog_list") do
29
- id = 351076997
30
- result = Hubspot::Blog.find_by_id(id)
26
+ result = Hubspot::Blog.find_by_id(last_blog_id)
31
27
 
32
- assert_requested :get, hubspot_api_url("/content/api/v2/blogs/#{id}?hapikey=demo")
33
28
  expect(result).to be_a(Hubspot::Blog)
34
29
  end
35
30
  end
@@ -59,26 +54,23 @@ describe Hubspot do
59
54
  describe "#posts" do
60
55
  it "returns published blog posts created in the last 2 months" do
61
56
  VCR.use_cassette("blog_posts/all_blog_posts") do
62
- blog_id = 123
57
+ blog_id = last_blog_id
63
58
  created_gt = timestamp_in_milliseconds(Time.now - 2.months)
64
59
  blog = Hubspot::Blog.new({ "id" => blog_id })
65
60
 
66
61
  result = blog.posts
67
62
 
68
- assert_requested :get, hubspot_api_url("/content/api/v2/blog-posts?content_group_id=#{blog_id}&created__gt=#{created_gt}&hapikey=demo&order_by=-created&state=PUBLISHED")
69
63
  expect(result).to be_kind_of(Array)
70
64
  end
71
65
  end
72
66
 
73
67
  it "includes given parameters in the request" do
74
68
  VCR.use_cassette("blog_posts/filter_blog_posts") do
75
- blog_id = 123
76
69
  created_gt = timestamp_in_milliseconds(Time.now - 2.months)
77
- blog = Hubspot::Blog.new({ "id" => 123 })
70
+ blog = Hubspot::Blog.new({ "id" => last_blog_id })
78
71
 
79
72
  result = blog.posts({ state: "DRAFT" })
80
73
 
81
- assert_requested :get, hubspot_api_url("/content/api/v2/blog-posts?content_group_id=#{blog_id}&created__gt=#{created_gt}&hapikey=demo&order_by=-created&state=DRAFT")
82
74
  expect(result).to be_kind_of(Array)
83
75
  end
84
76
  end
@@ -106,11 +98,8 @@ describe Hubspot do
106
98
  describe ".find_by_blog_post_id" do
107
99
  it "retrieves a blog post by id" do
108
100
  VCR.use_cassette "blog_posts" do
109
- blog_post_id = 422192866
110
-
111
- result = Hubspot::BlogPost.find_by_blog_post_id(blog_post_id)
101
+ result = Hubspot::BlogPost.find_by_blog_post_id(last_blog_post_id)
112
102
 
113
- assert_requested :get, hubspot_api_url("/content/api/v2/blog-posts/#{blog_post_id}?hapikey=demo")
114
103
  expect(result).to be_a(Hubspot::BlogPost)
115
104
  end
116
105
  end
@@ -119,7 +108,7 @@ describe Hubspot do
119
108
  describe "#topics" do
120
109
  it "returns the list of topics" do
121
110
  VCR.use_cassette "blog_posts" do
122
- blog_post = Hubspot::BlogPost.find_by_blog_post_id(422192866)
111
+ blog_post = Hubspot::BlogPost.find_by_blog_post_id(last_blog_post_id)
123
112
 
124
113
  topics = blog_post.topics
125
114
 
@@ -14,8 +14,6 @@ RSpec.describe Hubspot::CompanyProperties do
14
14
  end
15
15
  end
16
16
 
17
- before { Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY", "demo")) }
18
-
19
17
  describe ".all" do
20
18
  it "should return all properties" do
21
19
  VCR.use_cassette "company_properties/all_properties" do
@@ -229,7 +227,7 @@ RSpec.describe Hubspot::CompanyProperties do
229
227
  VCR.use_cassette("company_properties/delete_non_property") do
230
228
  expect {
231
229
  Hubspot::CompanyProperties.delete!("non-existent")
232
- }.to raise_error(Hubspot::RequestError)
230
+ }.to raise_error(Hubspot::NotFoundError)
233
231
  end
234
232
  end
235
233
  end
@@ -240,17 +238,16 @@ RSpec.describe Hubspot::CompanyProperties do
240
238
  describe ".groups" do
241
239
  it "returns all groups" do
242
240
  VCR.use_cassette("company_properties/all_groups") do
243
- group_name = "group_awesome"
244
- Hubspot::CompanyProperties.create_group!(name: group_name)
241
+ group = Hubspot::CompanyProperties.create_group!(name: "group_#{SecureRandom.hex}")
245
242
 
246
243
  response = Hubspot::CompanyProperties.groups
247
244
 
248
245
  assert_hubspot_api_request(:get, "/properties/v1/companies/groups")
249
246
 
250
247
  group_names = response.map { |group| group["name"] }
251
- expect(group_names).to include(group_name)
248
+ expect(group_names).to include(group['name'])
252
249
 
253
- Hubspot::CompanyProperties.delete_group!(group_name)
250
+ Hubspot::CompanyProperties.delete_group!(group['name'])
254
251
  end
255
252
  end
256
253
 
@@ -358,10 +355,10 @@ RSpec.describe Hubspot::CompanyProperties do
358
355
 
359
356
  let(:sub_params) { params.select { |k, _| k != 'displayName' } }
360
357
 
361
- it 'should return the valid parameters' do
362
- params['name'] = 'ff_group235'
358
+ it 'should return the valid parameters' do |example|
359
+ params['name'] = "ff_group_#{SecureRandom.hex}"
363
360
  response = Hubspot::CompanyProperties.create_group!(sub_params)
364
- expect(Hubspot::CompanyProperties.same?(response, sub_params)).to be true
361
+ expect(Hubspot::CompanyProperties.same?(response.except("name"), sub_params.except("name"))).to be true
365
362
  end
366
363
  end
367
364
  end
@@ -402,7 +399,7 @@ RSpec.describe Hubspot::CompanyProperties do
402
399
  cassette 'company_properties/delete_non_group'
403
400
 
404
401
  it 'should raise an error' do
405
- expect { Hubspot::CompanyProperties.delete_group!(name) }.to raise_error(Hubspot::RequestError)
402
+ expect { Hubspot::CompanyProperties.delete_group!(name) }.to raise_error(Hubspot::NotFoundError)
406
403
  end
407
404
  end
408
405
  end