hubspot-api-ruby 0.23.0 → 0.23.1

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Guardfile +2 -0
  4. data/Rakefile +1 -0
  5. data/hubspot-api-ruby.gemspec +3 -1
  6. data/lib/hubspot/association.rb +2 -0
  7. data/lib/hubspot/blog.rb +2 -0
  8. data/lib/hubspot/collection.rb +3 -1
  9. data/lib/hubspot/company.rb +2 -0
  10. data/lib/hubspot/company_properties.rb +2 -0
  11. data/lib/hubspot/config.rb +2 -0
  12. data/lib/hubspot/connection.rb +24 -20
  13. data/lib/hubspot/contact.rb +4 -2
  14. data/lib/hubspot/contact_list.rb +2 -0
  15. data/lib/hubspot/contact_properties.rb +2 -0
  16. data/lib/hubspot/conversation_thread.rb +2 -0
  17. data/lib/hubspot/custom_event.rb +2 -0
  18. data/lib/hubspot/deal.rb +2 -0
  19. data/lib/hubspot/deal_pipeline.rb +2 -0
  20. data/lib/hubspot/deal_properties.rb +2 -0
  21. data/lib/hubspot/deprecator.rb +2 -0
  22. data/lib/hubspot/engagement.rb +2 -0
  23. data/lib/hubspot/event.rb +2 -0
  24. data/lib/hubspot/exceptions.rb +2 -0
  25. data/lib/hubspot/file.rb +2 -0
  26. data/lib/hubspot/form.rb +2 -0
  27. data/lib/hubspot/meeting.rb +2 -0
  28. data/lib/hubspot/oauth.rb +2 -0
  29. data/lib/hubspot/owner.rb +2 -0
  30. data/lib/hubspot/paged_collection.rb +2 -0
  31. data/lib/hubspot/properties.rb +2 -0
  32. data/lib/hubspot/railtie.rb +2 -0
  33. data/lib/hubspot/resource.rb +6 -0
  34. data/lib/hubspot/subscription.rb +2 -0
  35. data/lib/hubspot/task.rb +2 -0
  36. data/lib/hubspot/ticket.rb +2 -0
  37. data/lib/hubspot/ticket_properties.rb +2 -0
  38. data/lib/hubspot/topic.rb +2 -0
  39. data/lib/hubspot/utils.rb +2 -0
  40. data/lib/hubspot-api-ruby.rb +2 -0
  41. data/spec/factories/companies.rb +1 -0
  42. data/spec/factories/contacts.rb +2 -0
  43. data/spec/lib/hubspot/association_spec.rb +2 -0
  44. data/spec/lib/hubspot/blog_spec.rb +2 -0
  45. data/spec/lib/hubspot/company_properties_spec.rb +2 -0
  46. data/spec/lib/hubspot/company_spec.rb +2 -0
  47. data/spec/lib/hubspot/config_spec.rb +2 -0
  48. data/spec/lib/hubspot/connection_spec.rb +108 -95
  49. data/spec/lib/hubspot/contact_list_spec.rb +2 -0
  50. data/spec/lib/hubspot/contact_properties_spec.rb +2 -0
  51. data/spec/lib/hubspot/contact_spec.rb +2 -0
  52. data/spec/lib/hubspot/conversation_thread_spec.rb +2 -0
  53. data/spec/lib/hubspot/custom_event_spec.rb +2 -0
  54. data/spec/lib/hubspot/deal_pipeline_spec.rb +2 -0
  55. data/spec/lib/hubspot/deal_properties_spec.rb +3 -1
  56. data/spec/lib/hubspot/deal_spec.rb +2 -0
  57. data/spec/lib/hubspot/deprecator_spec.rb +2 -0
  58. data/spec/lib/hubspot/engagement_spec.rb +2 -0
  59. data/spec/lib/hubspot/event_spec.rb +2 -0
  60. data/spec/lib/hubspot/file_spec.rb +2 -0
  61. data/spec/lib/hubspot/form_spec.rb +2 -0
  62. data/spec/lib/hubspot/meeting_spec.rb +2 -0
  63. data/spec/lib/hubspot/owner_spec.rb +2 -0
  64. data/spec/lib/hubspot/properties_spec.rb +2 -0
  65. data/spec/lib/hubspot/resource_spec.rb +13 -0
  66. data/spec/lib/hubspot/task_spec.rb +2 -0
  67. data/spec/lib/hubspot/ticket_properties_spec.rb +2 -0
  68. data/spec/lib/hubspot/ticket_spec.rb +2 -0
  69. data/spec/lib/hubspot/utils_spec.rb +2 -0
  70. data/spec/lib/hubspot-ruby_spec.rb +2 -0
  71. data/spec/shared_examples/saveable_resource.rb +3 -1
  72. data/spec/shared_examples/updateable_resource.rb +2 -0
  73. data/spec/spec_helper.rb +2 -0
  74. data/spec/support/cassette_helper.rb +2 -0
  75. data/spec/support/hubspot_api_helpers.rb +2 -0
  76. data/spec/support/vcr.rb +2 -0
  77. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd6ac9387338bceb92ea57c9e34788833c6ea45511ea72cbb33befcf62585265
4
- data.tar.gz: 90c55d2a97d519183045e25e194439ff2ac99525fe10400171b8ffa7c1ddd527
3
+ metadata.gz: 750ee1add6d5d2cb47595d7a474c958c8dbdd0b2d8e985b36e2b677a97c2731f
4
+ data.tar.gz: b4a8afca4e80b2e4dd19369cbe89db48fdfbfbce0bd5af41173ea3293fa6a4ed
5
5
  SHA512:
6
- metadata.gz: cc28f6c773ae9fd46b6ef2e63e9e64cd4f3aed94c1fc8637f86b62d4c006c6352cfeb8faeac3b2b3dcb1b9c0bfb152cfc4d3817491ad7b32937fd30e83eb4e6e
7
- data.tar.gz: 1e3ae54b2544206dc5328629b0b5885af3706e9c534ad1db4b287915aa8fc263c64f32ae8fb9e93af6d54a8f123b3e60da7f33fddbfe06c58ac667367aa5b9c4
6
+ metadata.gz: cce6c8e5062b4bf18fc52a6f34755d43cbd97161de45b78cd4c5143420dcce262cb81173472774cbd46ca3e344353c7c29490ffded3eb2e0febb49d7ad1ddf65
7
+ data.tar.gz: ddc2f26e0e3df993bfd00ee9ed11bfbc4c5fe5741c274879ae74d50ea0cc9244803468eac339da4d57db4840408a102ec03dc6d44b8d0cd3b67f1c54567fd057
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
  # Add dependencies to hubspot-api-ruby.gemspec
3
5
  gemspec
data/Guardfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # A sample Guardfile
2
4
  # More info at https://github.com/guard/guard#readme
3
5
 
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rubygems'
4
5
  require 'bundler'
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = "hubspot-api-ruby"
3
- s.version = "0.23.0"
5
+ s.version = "0.23.1"
4
6
  s.require_paths = ["lib"]
5
7
  s.authors = ["Jonathan"]
6
8
  s.email = ["jonathan@hoggo.com"]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hubspot::Association
2
4
  OBJECT_TARGET_TO_CLASS = {
3
5
  "Contact" => Hubspot::Contact,
data/lib/hubspot/blog.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  #
3
5
  # HubSpot Contacts API
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hubspot::Collection
2
4
  def initialize(opts = {}, &block)
3
5
  @options = opts
@@ -38,4 +40,4 @@ protected
38
40
  def method_missing(method, *args, &block)
39
41
  @resources.public_send(method, *args, &block)
40
42
  end
41
- end
43
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hubspot::Company < Hubspot::Resource
2
4
  self.id_field = "companyId"
3
5
  self.property_name_field = "name"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class CompanyProperties < Properties
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logger'
2
4
  require 'hubspot/connection'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class Connection
3
5
  include HTTParty
@@ -39,10 +41,10 @@ module Hubspot
39
41
  verb,
40
42
  url,
41
43
  body: options[:body].to_json,
42
- headers: { "Content-Type" => "application/json" },
44
+ headers: { 'Content-Type' => 'application/json' },
43
45
  format: :json,
44
46
  read_timeout: read_timeout(options),
45
- open_timeout: open_timeout(options),
47
+ open_timeout: open_timeout(options)
46
48
  )
47
49
 
48
50
  log_request_and_response(url, response, options[:body])
@@ -63,10 +65,11 @@ module Hubspot
63
65
  return response if response.success?
64
66
 
65
67
  raise(Hubspot::NotFoundError.new(response)) if response.not_found?
68
+
66
69
  raise(Hubspot::RequestError.new(response))
67
70
  end
68
71
 
69
- def log_request_and_response(uri, response, body=nil)
72
+ def log_request_and_response(uri, response, body = nil)
70
73
  Hubspot::Config.logger.info(<<~MSG)
71
74
  Hubspot: #{uri}.
72
75
  Body: #{body}.
@@ -74,7 +77,7 @@ module Hubspot
74
77
  MSG
75
78
  end
76
79
 
77
- def generate_url(path, params={}, options={})
80
+ def generate_url(path, params = {}, options = {})
78
81
  if Hubspot::Config.access_token.present?
79
82
  options[:hapikey] = false
80
83
  else
@@ -83,26 +86,26 @@ module Hubspot
83
86
  path = path.clone
84
87
  params = params.clone
85
88
  base_url = options[:base_url] || Hubspot::Config.base_url
86
- params["hapikey"] = Hubspot::Config.hapikey unless options[:hapikey] == false
89
+ params['hapikey'] = Hubspot::Config.hapikey unless options[:hapikey] == false
87
90
 
88
- if path =~ /:portal_id/
91
+ if /:portal_id/.match?(path)
89
92
  Hubspot::Config.ensure! :portal_id
90
- params["portal_id"] = Hubspot::Config.portal_id if path =~ /:portal_id/
93
+ params['portal_id'] = Hubspot::Config.portal_id
91
94
  end
92
95
 
93
- params.each do |k,v|
94
- if path.match(":#{k}")
95
- path.gsub!(":#{k}", CGI.escape(v.to_s))
96
- params.delete(k)
96
+ params.each do |key, value|
97
+ if path.match(":#{key}")
98
+ path = path.gsub(":#{key}", CGI.escape(value.to_s))
99
+ params.delete(key)
97
100
  end
98
101
  end
99
- raise(Hubspot::MissingInterpolation.new("Interpolation not resolved")) if path =~ /:/
102
+ raise(Hubspot::MissingInterpolation.new('Interpolation not resolved')) if /:/.match?(path)
100
103
 
101
- query = params.map do |k,v|
102
- v.is_a?(Array) ? v.map { |value| param_string(k,value) } : param_string(k,v)
103
- end.join("&")
104
+ query = params.map do |k, v|
105
+ v.is_a?(Array) ? v.map { |value| param_string(k, value) } : param_string(k, v)
106
+ end.join('&')
104
107
 
105
- path += path.include?('?') ? '&' : "?" if query.present?
108
+ path += path.include?('?') ? '&' : '?' if query.present?
106
109
  base_url + path + query
107
110
  end
108
111
 
@@ -111,13 +114,14 @@ module Hubspot
111
114
  value.is_a?(Time) ? (value.to_i * 1000) : CGI.escape(value.to_s)
112
115
  end
113
116
 
114
- def param_string(key,value)
117
+ def param_string(key, value)
115
118
  case key
116
119
  when /range/
117
- raise "Value must be a range" unless value.is_a?(Range)
120
+ raise 'Value must be a range' unless value.is_a?(Range)
121
+
118
122
  "#{key}=#{converted_value(value.begin)}&#{key}=#{converted_value(value.end)}"
119
123
  when /^batch_(.*)$/
120
- key = $1.gsub(/(_.)/) { |w| w.last.upcase }
124
+ key = ::Regexp.last_match(1).gsub(/(_.)/) { |w| w.last.upcase }
121
125
  "#{key}=#{converted_value(value)}"
122
126
  else
123
127
  "#{key}=#{converted_value(value)}"
@@ -146,7 +150,7 @@ module Hubspot
146
150
  def self.trigger(path, opts)
147
151
  url = generate_url(path, opts[:params], { hapikey: true })
148
152
  headers = (opts[:headers] || {}).merge('content-type': 'application/json')
149
- post(url, body: opts[:body].to_json, headers: headers)
153
+ post(url, body: opts[:body].to_json, headers:)
150
154
  end
151
155
  end
152
156
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hubspot::Contact < Hubspot::Resource
2
4
  self.id_field = 'vid'
3
5
  self.update_method = 'post'
@@ -21,8 +23,8 @@ class Hubspot::Contact < Hubspot::Resource
21
23
  request_options[:after] = after if after.present?
22
24
  response = Hubspot::Connection.get_json(ALL_PATH, request_options)
23
25
 
24
- contacts = response['results'].map do |result|
25
- from_result result, id_field: Hubspot::Resource.id_field
26
+ contacts = response['results'].map do |result|
27
+ from_result result, id_field: Hubspot::Resource.id_field
26
28
  end
27
29
  after = response.dig('paging', 'next', 'after')
28
30
  [contacts, after, after.present?]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  #
3
5
  # HubSpot Contact lists API
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class ContactProperties < Properties
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
data/lib/hubspot/deal.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class DealProperties < Properties
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class Deprecator
3
5
  def self.build(version: "1.0")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
data/lib/hubspot/event.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class RequestError < StandardError
3
5
  attr_accessor :response
data/lib/hubspot/file.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
  require 'base64'
3
5
  require 'pp'
data/lib/hubspot/form.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  #
3
5
  # HubSpot Form API
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
data/lib/hubspot/oauth.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'httparty'
2
4
 
3
5
  module Hubspot
data/lib/hubspot/owner.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  #
3
5
  # HubSpot Owners API
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hubspot::PagedCollection < Hubspot::Collection
2
4
  attr_accessor :offset, :limit
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class Properties
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot-api-ruby'
2
4
  require 'rails'
3
5
  module Hubspot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class Resource
3
5
  class_attribute :id_field, instance_writer: false
@@ -93,6 +95,10 @@ module Hubspot
93
95
  @changes[name] || @properties.dig(name, 'value')
94
96
  end
95
97
 
98
+ def []=(name, value)
99
+ @changes[name] = value unless @changes[name] == value
100
+ end
101
+
96
102
  def reload
97
103
  raise(Hubspot::InvalidParams.new("Resource must have an ID")) if @id.nil?
98
104
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class Subscription
3
5
  SUBSCRIPTIONS_PATH = '/email/public/v1/subscriptions'
data/lib/hubspot/task.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'hubspot/utils'
2
4
 
3
5
  module Hubspot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class TicketProperties < Properties
3
5
  CREATE_PROPERTY_PATH = '/crm/v3/properties/ticket'
data/lib/hubspot/topic.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  #
3
5
  # HubSpot Topics API
data/lib/hubspot/utils.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  class Utils
3
5
  class << self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support'
2
4
  require 'active_support/core_ext'
3
5
  require 'httparty'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  FactoryBot.define do
3
4
  factory :company, class: Hubspot::Company do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :contact, class: 'Hubspot::Contact' do
3
5
  to_create { |instance| instance.save }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::Association do
2
4
  let(:portal_id) { 62515 }
3
5
  let(:company) { create :company }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'timecop'
2
4
 
3
5
  describe Hubspot do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::CompanyProperties do
2
4
  describe '.add_default_parameters' do
3
5
  let(:opts) { {} }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::Company do
2
4
 
3
5
  it_behaves_like "a saveable resource", :company do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Config do
2
4
  describe ".configure" do
3
5
  it "sets the access token config" do
@@ -1,67 +1,69 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Connection do
2
- describe ".get_json" do
3
- it "returns the parsed response from the GET request" do
4
- path = "/some/path"
5
- body = { key: "value" }
4
+ describe '.get_json' do
5
+ it 'returns the parsed response from the GET request' do
6
+ path = '/some/path'
7
+ body = { key: 'value' }
6
8
 
7
- stub_request(:get, "https://api.hubapi.com/some/path").to_return(status: 200, body: JSON.generate(body))
9
+ stub_request(:get, 'https://api.hubapi.com/some/path').to_return(status: 200, body: JSON.generate(body))
8
10
 
9
11
  result = Hubspot::Connection.get_json(path, {})
10
- expect(result).to eq({ "key" => "value" })
12
+ expect(result).to eq({ 'key' => 'value' })
11
13
  end
12
14
  end
13
15
 
14
- describe ".post_json" do
15
- it "returns the parsed response from the POST request" do
16
- path = "/some/path"
17
- body = { id: 1, name: "ABC" }
16
+ describe '.post_json' do
17
+ it 'returns the parsed response from the POST request' do
18
+ path = '/some/path'
19
+ body = { id: 1, name: 'ABC' }
18
20
 
19
- stub_request(:post, "https://api.hubapi.com/some/path?name=ABC").to_return(status: 200, body: JSON.generate(body))
21
+ stub_request(:post, 'https://api.hubapi.com/some/path?name=ABC').to_return(status: 200, body: JSON.generate(body))
20
22
 
21
- result = Hubspot::Connection.post_json(path, params: { name: "ABC" })
22
- expect(result).to eq({ "id" => 1, "name" => "ABC" })
23
+ result = Hubspot::Connection.post_json(path, params: { name: 'ABC' })
24
+ expect(result).to eq({ 'id' => 1, 'name' => 'ABC' })
23
25
  end
24
26
  end
25
27
 
26
- describe ".delete_json" do
27
- it "returns the response from the DELETE request" do
28
- path = "/some/path"
28
+ describe '.delete_json' do
29
+ it 'returns the response from the DELETE request' do
30
+ path = '/some/path'
29
31
 
30
- stub_request(:delete, "https://api.hubapi.com/some/path").to_return(status: 204, body: JSON.generate({}))
32
+ stub_request(:delete, 'https://api.hubapi.com/some/path').to_return(status: 204, body: JSON.generate({}))
31
33
 
32
34
  result = Hubspot::Connection.delete_json(path, {})
33
35
  expect(result.code).to eq(204)
34
36
  end
35
37
  end
36
38
 
37
- describe ".put_json" do
38
- it "issues a PUT request and returns the parsed body" do
39
- path = "/some/path"
39
+ describe '.put_json' do
40
+ it 'issues a PUT request and returns the parsed body' do
41
+ path = '/some/path'
40
42
  update_options = { params: {}, body: {} }
41
43
 
42
- stub_request(:put, "https://api.hubapi.com/some/path").to_return(status: 200, body: JSON.generate(vid: 123))
44
+ stub_request(:put, 'https://api.hubapi.com/some/path').to_return(status: 200, body: JSON.generate(vid: 123))
43
45
 
44
46
  response = Hubspot::Connection.put_json(path, update_options)
45
47
 
46
48
  assert_requested(
47
49
  :put,
48
- "https://api.hubapi.com/some/path",
49
- {
50
- body: "{}",
51
- headers: { "Content-Type" => "application/json" },
52
- }
50
+ 'https://api.hubapi.com/some/path',
51
+ {
52
+ body: '{}',
53
+ headers: { 'Content-Type' => 'application/json' }
54
+ }
53
55
  )
54
- expect(response).to eq({ "vid" => 123 })
56
+ expect(response).to eq({ 'vid' => 123 })
55
57
  end
56
58
 
57
- it "logs information about the request and response" do
58
- path = "/some/path"
59
+ it 'logs information about the request and response' do
60
+ path = '/some/path'
59
61
  update_options = { params: {}, body: {} }
60
62
 
61
63
  logger = stub_logger
62
64
 
63
- stub_request(:put, "https://api.hubapi.com/some/path").to_return(status: 200,
64
- body: JSON.generate("response body"))
65
+ stub_request(:put, 'https://api.hubapi.com/some/path').to_return(status: 200,
66
+ body: JSON.generate('response body'))
65
67
 
66
68
  Hubspot::Connection.put_json(path, update_options)
67
69
 
@@ -72,46 +74,46 @@ describe Hubspot::Connection do
72
74
  MSG
73
75
  end
74
76
 
75
- it "raises when the request fails" do
76
- path = "/some/path"
77
+ it 'raises when the request fails' do
78
+ path = '/some/path'
77
79
  update_options = { params: {}, body: {} }
78
80
 
79
- stub_request(:put, "https://api.hubapi.com/some/path").to_return(status: 401)
81
+ stub_request(:put, 'https://api.hubapi.com/some/path').to_return(status: 401)
80
82
 
81
- expect {
83
+ expect do
82
84
  Hubspot::Connection.put_json(path, update_options)
83
- }.to raise_error(Hubspot::RequestError)
85
+ end.to raise_error(Hubspot::RequestError)
84
86
  end
85
87
  end
86
88
 
87
- describe ".patch_json" do
88
- it "issues a PATCH request and returns the parsed body" do
89
- path = "/some/path"
89
+ describe '.patch_json' do
90
+ it 'issues a PATCH request and returns the parsed body' do
91
+ path = '/some/path'
90
92
  update_options = { params: {}, body: {} }
91
93
 
92
- stub_request(:patch, "https://api.hubapi.com/some/path").to_return(status: 200, body: JSON.generate(vid: 123))
94
+ stub_request(:patch, 'https://api.hubapi.com/some/path').to_return(status: 200, body: JSON.generate(vid: 123))
93
95
 
94
96
  response = Hubspot::Connection.patch_json(path, update_options)
95
97
 
96
98
  assert_requested(
97
99
  :patch,
98
- "https://api.hubapi.com/some/path",
100
+ 'https://api.hubapi.com/some/path',
99
101
  {
100
- body: "{}",
101
- headers: { "Content-Type" => "application/json" },
102
+ body: '{}',
103
+ headers: { 'Content-Type' => 'application/json' }
102
104
  }
103
105
  )
104
- expect(response).to eq({ "vid" => 123 })
106
+ expect(response).to eq({ 'vid' => 123 })
105
107
  end
106
108
 
107
- it "logs information about the request and response" do
108
- path = "/some/path"
109
+ it 'logs information about the request and response' do
110
+ path = '/some/path'
109
111
  update_options = { params: {}, body: {} }
110
112
 
111
113
  logger = stub_logger
112
114
 
113
- stub_request(:patch, "https://api.hubapi.com/some/path").to_return(status: 200,
114
- body: JSON.generate("response body"))
115
+ stub_request(:patch, 'https://api.hubapi.com/some/path').to_return(status: 200,
116
+ body: JSON.generate('response body'))
115
117
 
116
118
  Hubspot::Connection.patch_json(path, update_options)
117
119
 
@@ -122,99 +124,109 @@ describe Hubspot::Connection do
122
124
  MSG
123
125
  end
124
126
 
125
- it "raises when the request fails" do
126
- path = "/some/path"
127
+ it 'raises when the request fails' do
128
+ path = '/some/path'
127
129
  update_options = { params: {}, body: {} }
128
130
 
129
- stub_request(:patch, "https://api.hubapi.com/some/path").to_return(status: 401)
131
+ stub_request(:patch, 'https://api.hubapi.com/some/path').to_return(status: 401)
130
132
 
131
- expect {
133
+ expect do
132
134
  Hubspot::Connection.patch_json(path, update_options)
133
- }.to raise_error(Hubspot::RequestError)
135
+ end.to raise_error(Hubspot::RequestError)
134
136
  end
135
137
  end
136
138
 
137
139
  context 'private methods' do
138
- describe ".generate_url" do
139
- let(:path) { "/test/:email/profile" }
140
- let(:params) { { email: "test" } }
141
- let(:options) { {} }
140
+ describe '.generate_url' do
142
141
  subject { Hubspot::Connection.send(:generate_url, path, params, options) }
143
142
 
143
+ let(:path) { '/test/:email/profile' }
144
+ let(:params) { { email: 'test' } }
145
+ let(:options) { {} }
146
+
144
147
  it "doesn't modify params" do
145
- expect { subject }.to_not change{params}
148
+ expect { subject }.not_to(change { params })
146
149
  end
147
150
 
148
- context "with a portal_id param" do
149
- let(:path) { "/test/:portal_id/profile" }
151
+ context 'with a portal_id param' do
152
+ let(:path) { '/test/:portal_id/profile' }
150
153
  let(:params) { {} }
151
154
 
152
155
  before do
153
- Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"))
156
+ Hubspot.configure(access_token: ENV.fetch('HUBSPOT_ACCESS_TOKEN'), portal_id: ENV.fetch('HUBSPOT_PORTAL_ID'))
154
157
  end
155
158
 
156
- it { should == "https://api.hubapi.com/test/#{ENV.fetch('HUBSPOT_PORTAL_ID')}/profile" }
159
+ it { is_expected.to eq("https://api.hubapi.com/test/#{ENV.fetch('HUBSPOT_PORTAL_ID')}/profile") }
157
160
  end
158
161
 
159
162
  context "when configure hasn't been called" do
160
163
  before { Hubspot::Config.reset! }
161
- it "raises a config exception" do
164
+
165
+ it 'raises a config exception' do
162
166
  expect { subject }.to raise_error Hubspot::ConfigurationError
163
167
  end
164
168
  end
165
169
 
166
- context "with interpolations but no params" do
170
+ context 'with interpolations but no params' do
167
171
  let(:params) { {} }
168
172
 
169
- it "raises an interpolation exception" do
170
- expect{ subject }.to raise_error Hubspot::MissingInterpolation
173
+ it 'raises an interpolation exception' do
174
+ expect { subject }.to raise_error Hubspot::MissingInterpolation
171
175
  end
172
176
  end
173
177
 
174
- context "with an interpolated param" do
175
- let(:params) { { email: "email@address.com" } }
176
- it { should == "https://api.hubapi.com/test/email%40address.com/profile" }
178
+ context 'with an interpolated param' do
179
+ let(:params) { { email: 'email@address.com' } }
180
+
181
+ it { is_expected.to eq('https://api.hubapi.com/test/email%40address.com/profile') }
177
182
  end
178
183
 
179
- context "with multiple interpolated params" do
180
- let(:path) { "/test/:email/:id/profile" }
181
- let(:params) { { email: "email@address.com", id: 1234 } }
182
- it { should == "https://api.hubapi.com/test/email%40address.com/1234/profile" }
184
+ context 'with multiple interpolated params' do
185
+ let(:path) { '/test/:email/:id/profile' }
186
+ let(:params) { { email: 'email@address.com', id: 1234 } }
187
+
188
+ it { is_expected.to eq('https://api.hubapi.com/test/email%40address.com/1234/profile') }
183
189
  end
184
190
 
185
- context "with query params" do
186
- let(:params) { { email: "email@address.com", id: 1234 } }
187
- it { should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234" }
191
+ context 'with query params' do
192
+ let(:params) { { email: 'email@address.com', id: 1234 } }
188
193
 
189
- context "containing a time" do
194
+ it { is_expected.to eq('https://api.hubapi.com/test/email%40address.com/profile?id=1234') }
195
+
196
+ context 'containing a time' do
190
197
  let(:start_time) { Time.now }
191
- let(:params) { { email: "email@address.com", id: 1234, start: start_time } }
192
- it { should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234&start=#{start_time.to_i * 1000}" }
198
+ let(:params) { { email: 'email@address.com', id: 1234, start: start_time } }
199
+
200
+ it { is_expected.to eq("https://api.hubapi.com/test/email%40address.com/profile?id=1234&start=#{start_time.to_i * 1000}") }
193
201
  end
194
202
 
195
- context "containing a range" do
203
+ context 'containing a range' do
196
204
  let(:start_time) { Time.now }
197
205
  let(:end_time) { Time.now + 1.year }
198
- let(:params) { { email: "email@address.com", id: 1234, created__range: start_time..end_time } }
199
- it { should == "https://api.hubapi.com/test/email%40address.com/profile?id=1234&created__range=#{start_time.to_i * 1000}&created__range=#{end_time.to_i * 1000}" }
206
+ let(:params) { { email: 'email@address.com', id: 1234, created__range: start_time..end_time } }
207
+
208
+ it { is_expected.to eq("https://api.hubapi.com/test/email%40address.com/profile?id=1234&created__range=#{start_time.to_i * 1000}&created__range=#{end_time.to_i * 1000}") }
200
209
  end
201
210
 
202
- context "containing an array of strings" do
203
- let(:path) { "/test/emails" }
204
- let(:params) { { batch_email: %w(email1@example.com email2@example.com) } }
205
- it { should == "https://api.hubapi.com/test/emails?email=email1%40example.com&email=email2%40example.com" }
211
+ context 'containing an array of strings' do
212
+ let(:path) { '/test/emails' }
213
+ let(:params) { { batch_email: %w[email1@example.com email2@example.com] } }
214
+
215
+ it { is_expected.to eq('https://api.hubapi.com/test/emails?email=email1%40example.com&email=email2%40example.com') }
206
216
  end
207
217
  end
208
218
 
209
- context "with options" do
210
- let(:options) { { base_url: "https://cool.com", access_token: false } }
211
- it { should == "https://cool.com/test/test/profile" }
219
+ context 'with options' do
220
+ let(:options) { { base_url: 'https://cool.com', access_token: false } }
221
+
222
+ it { is_expected.to eq('https://cool.com/test/test/profile') }
212
223
  end
213
224
 
214
- context "passing Array as parameters for batch mode, key is prefixed with batch_" do
225
+ context 'passing Array as parameters for batch mode, key is prefixed with batch_' do
215
226
  let(:path) { Hubspot::ContactList::LISTS_PATH }
216
- let(:params) { { batch_list_id: [1,2,3] } }
217
- it { should == "https://api.hubapi.com/crm/v3/lists?listId=1&listId=2&listId=3" }
227
+ let(:params) { { batch_list_id: [1, 2, 3] } }
228
+
229
+ it { is_expected.to eq('https://api.hubapi.com/crm/v3/lists?listId=1&listId=2&listId=3') }
218
230
  end
219
231
  end
220
232
  end
@@ -228,11 +240,12 @@ end
228
240
 
229
241
  describe Hubspot::EventConnection do
230
242
  describe '.trigger' do
243
+ subject { described_class.trigger(path, options) }
244
+
231
245
  let(:path) { '/path' }
232
246
  let(:options) { { params: {} } }
233
247
  let(:headers) { nil }
234
248
 
235
- subject { described_class.trigger(path, options) }
236
249
  before { allow(described_class).to receive(:get).and_return(true) }
237
250
 
238
251
  it 'calls get with a custom url' do
@@ -242,11 +255,11 @@ describe Hubspot::EventConnection do
242
255
 
243
256
  context 'with more options' do
244
257
  let(:headers) { { 'User-Agent' => 'something' } }
245
- let(:options) { { params: {}, headers: headers } }
258
+ let(:options) { { params: {}, headers: } }
246
259
 
247
260
  it 'supports headers' do
248
261
  subject
249
- expect(described_class).to have_received(:get).with('https://track.hubspot.com/path', body: nil, headers: headers)
262
+ expect(described_class).to have_received(:get).with('https://track.hubspot.com/path', body: nil, headers:)
250
263
  end
251
264
  end
252
265
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::ContactList do
2
4
  # uncomment if you need to create test data in your panel.
3
5
  # note that sandboxes have a limit of 10 dynamic lists
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::ContactProperties do
2
4
  describe '.add_default_parameters' do
3
5
  let(:opts) { {} }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::Contact do
2
4
  it_behaves_like 'a saveable resource', :contact do
3
5
  def set_property(contact)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::ConversationThread do
2
4
  describe 'find' do
3
5
  let(:thread_id) { 3_176_297_853 }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::CustomEvent do
2
4
  before do
3
5
  Hubspot.configure(access_token: ENV.fetch("HUBSPOT_ACCESS_TOKEN"), portal_id: ENV.fetch("HUBSPOT_PORTAL_ID"),
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::DealPipeline do
2
4
 
3
5
  describe ".find" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::DealProperties do
2
4
  describe '.add_default_parameters' do
3
5
  let(:opts) { {} }
@@ -37,7 +39,7 @@ describe Hubspot::DealProperties do
37
39
  end
38
40
  end
39
41
  end
40
-
42
+
41
43
  describe '.find' do
42
44
  context 'existing property' do
43
45
  cassette 'deal_properties/existing_property'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Deal do
2
4
  let(:portal_id) { ENV.fetch("HUBSPOT_PORTAL_ID").to_i }
3
5
  let(:company) { Hubspot::Company.create(name: SecureRandom.hex) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::Deprecator do
2
4
  describe ".build" do
3
5
  it "returns an instance of ActiveSupport::Deprecation" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Engagement do
2
4
  let(:contact) { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
3
5
  let(:engagement) { Hubspot::EngagementNote.create!(contact.id, "foo") }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Event do
2
4
  let(:portal_id) { ENV.fetch("HUBSPOT_PORTAL_ID") }
3
5
  let(:sent_portal_id) { portal_id }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::File do
2
4
  let(:example_file_hash) do
3
5
  VCR.use_cassette('file_example') do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Form do
2
4
  let(:example_form_hash) do
3
5
  VCR.use_cassette('form_example') do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::Meeting do
2
4
 
3
5
  let(:hubspot_owner_id) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Owner do
2
4
  let(:example_owners) do
3
5
  VCR.use_cassette('owner_example') do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hubspot
2
4
  describe Properties do
3
5
  let(:params) { { 'name' => 'amount_of_new_money_lined_up',
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  RSpec.describe Hubspot::Resource do
3
4
  describe '#new' do
@@ -72,6 +73,18 @@ RSpec.describe Hubspot::Resource do
72
73
  end
73
74
  end
74
75
 
76
+ describe '#[]=' do
77
+ let(:resource) { described_class.from_result({ properties: }) }
78
+ let(:properties) { { id: { 'value' => 1 }, firstname: { 'value' => 'John' }, lastname: { 'value' => 'Wayne' } } }
79
+
80
+ it 'stages a change to a property' do
81
+ resource[:firstname] = 'Jon'
82
+
83
+ expect(resource[:firstname]).to eq 'Jon'
84
+ expect(resource.changes).to include(firstname: 'Jon')
85
+ end
86
+ end
87
+
75
88
  describe '#adding_accessors' do
76
89
  describe 'getters' do
77
90
  context 'using new' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::Task do
2
4
  describe 'create!' do
3
5
  subject(:new_task) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::TicketProperties do
2
4
  describe '.create' do
3
5
  context 'with all valid parameters' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot::Ticket do
2
4
  describe 'create!' do
3
5
  subject(:new_ticket) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe Hubspot::Utils do
2
4
  API_HEADERS = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }.freeze
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Hubspot do
2
4
  describe ".configure" do
3
5
  it "delegates .configure to Hubspot::Config.configure" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_examples_for "a saveable resource" do |factory_name|
2
4
  describe '#save' do
3
5
  context 'with a new resource' do
@@ -42,4 +44,4 @@ RSpec.shared_examples_for "a saveable resource" do |factory_name|
42
44
  end
43
45
  end
44
46
  end
45
- end
47
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_examples_for "an updateable resource" do |factory_name|
2
4
  describe '.update' do
3
5
  context 'with an existing resource' do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
5
  RSPEC_ROOT = File.dirname(__FILE__)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CassetteHelper
2
4
  def self.extended(base)
3
5
  base.around do |spec|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HubspotApiHelpers
2
4
  def hubspot_api_url(path)
3
5
  URI.join(Hubspot::Config.base_url, path)
data/spec/support/vcr.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "vcr"
2
4
 
3
5
  def vcr_record_mode
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubspot-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-06-04 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: activesupport
@@ -352,6 +353,7 @@ licenses:
352
353
  - MIT
353
354
  metadata:
354
355
  changelog_uri: https://github.com/captaincontrat/hubspot-api-ruby/blob/master/History.md
356
+ post_install_message:
355
357
  rdoc_options: []
356
358
  require_paths:
357
359
  - lib
@@ -366,7 +368,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
366
368
  - !ruby/object:Gem::Version
367
369
  version: '0'
368
370
  requirements: []
369
- rubygems_version: 4.0.6
371
+ rubygems_version: 3.5.22
372
+ signing_key:
370
373
  specification_version: 4
371
374
  summary: hubspot-api-ruby is a wrapper for the HubSpot REST API
372
375
  test_files: []