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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Guardfile +2 -0
- data/Rakefile +1 -0
- data/hubspot-api-ruby.gemspec +3 -1
- data/lib/hubspot/association.rb +2 -0
- data/lib/hubspot/blog.rb +2 -0
- data/lib/hubspot/collection.rb +3 -1
- data/lib/hubspot/company.rb +2 -0
- data/lib/hubspot/company_properties.rb +2 -0
- data/lib/hubspot/config.rb +2 -0
- data/lib/hubspot/connection.rb +24 -20
- data/lib/hubspot/contact.rb +4 -2
- data/lib/hubspot/contact_list.rb +2 -0
- data/lib/hubspot/contact_properties.rb +2 -0
- data/lib/hubspot/conversation_thread.rb +2 -0
- data/lib/hubspot/custom_event.rb +2 -0
- data/lib/hubspot/deal.rb +2 -0
- data/lib/hubspot/deal_pipeline.rb +2 -0
- data/lib/hubspot/deal_properties.rb +2 -0
- data/lib/hubspot/deprecator.rb +2 -0
- data/lib/hubspot/engagement.rb +2 -0
- data/lib/hubspot/event.rb +2 -0
- data/lib/hubspot/exceptions.rb +2 -0
- data/lib/hubspot/file.rb +2 -0
- data/lib/hubspot/form.rb +2 -0
- data/lib/hubspot/meeting.rb +2 -0
- data/lib/hubspot/oauth.rb +2 -0
- data/lib/hubspot/owner.rb +2 -0
- data/lib/hubspot/paged_collection.rb +2 -0
- data/lib/hubspot/properties.rb +2 -0
- data/lib/hubspot/railtie.rb +2 -0
- data/lib/hubspot/resource.rb +6 -0
- data/lib/hubspot/subscription.rb +2 -0
- data/lib/hubspot/task.rb +2 -0
- data/lib/hubspot/ticket.rb +2 -0
- data/lib/hubspot/ticket_properties.rb +2 -0
- data/lib/hubspot/topic.rb +2 -0
- data/lib/hubspot/utils.rb +2 -0
- data/lib/hubspot-api-ruby.rb +2 -0
- data/spec/factories/companies.rb +1 -0
- data/spec/factories/contacts.rb +2 -0
- data/spec/lib/hubspot/association_spec.rb +2 -0
- data/spec/lib/hubspot/blog_spec.rb +2 -0
- data/spec/lib/hubspot/company_properties_spec.rb +2 -0
- data/spec/lib/hubspot/company_spec.rb +2 -0
- data/spec/lib/hubspot/config_spec.rb +2 -0
- data/spec/lib/hubspot/connection_spec.rb +108 -95
- data/spec/lib/hubspot/contact_list_spec.rb +2 -0
- data/spec/lib/hubspot/contact_properties_spec.rb +2 -0
- data/spec/lib/hubspot/contact_spec.rb +2 -0
- data/spec/lib/hubspot/conversation_thread_spec.rb +2 -0
- data/spec/lib/hubspot/custom_event_spec.rb +2 -0
- data/spec/lib/hubspot/deal_pipeline_spec.rb +2 -0
- data/spec/lib/hubspot/deal_properties_spec.rb +3 -1
- data/spec/lib/hubspot/deal_spec.rb +2 -0
- data/spec/lib/hubspot/deprecator_spec.rb +2 -0
- data/spec/lib/hubspot/engagement_spec.rb +2 -0
- data/spec/lib/hubspot/event_spec.rb +2 -0
- data/spec/lib/hubspot/file_spec.rb +2 -0
- data/spec/lib/hubspot/form_spec.rb +2 -0
- data/spec/lib/hubspot/meeting_spec.rb +2 -0
- data/spec/lib/hubspot/owner_spec.rb +2 -0
- data/spec/lib/hubspot/properties_spec.rb +2 -0
- data/spec/lib/hubspot/resource_spec.rb +13 -0
- data/spec/lib/hubspot/task_spec.rb +2 -0
- data/spec/lib/hubspot/ticket_properties_spec.rb +2 -0
- data/spec/lib/hubspot/ticket_spec.rb +2 -0
- data/spec/lib/hubspot/utils_spec.rb +2 -0
- data/spec/lib/hubspot-ruby_spec.rb +2 -0
- data/spec/shared_examples/saveable_resource.rb +3 -1
- data/spec/shared_examples/updateable_resource.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/cassette_helper.rb +2 -0
- data/spec/support/hubspot_api_helpers.rb +2 -0
- data/spec/support/vcr.rb +2 -0
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 750ee1add6d5d2cb47595d7a474c958c8dbdd0b2d8e985b36e2b677a97c2731f
|
|
4
|
+
data.tar.gz: b4a8afca4e80b2e4dd19369cbe89db48fdfbfbce0bd5af41173ea3293fa6a4ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cce6c8e5062b4bf18fc52a6f34755d43cbd97161de45b78cd4c5143420dcce262cb81173472774cbd46ca3e344353c7c29490ffded3eb2e0febb49d7ad1ddf65
|
|
7
|
+
data.tar.gz: ddc2f26e0e3df993bfd00ee9ed11bfbc4c5fe5741c274879ae74d50ea0cc9244803468eac339da4d57db4840408a102ec03dc6d44b8d0cd3b67f1c54567fd057
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/Rakefile
CHANGED
data/hubspot-api-ruby.gemspec
CHANGED
data/lib/hubspot/association.rb
CHANGED
data/lib/hubspot/blog.rb
CHANGED
data/lib/hubspot/collection.rb
CHANGED
data/lib/hubspot/company.rb
CHANGED
data/lib/hubspot/config.rb
CHANGED
data/lib/hubspot/connection.rb
CHANGED
|
@@ -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: {
|
|
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[
|
|
89
|
+
params['hapikey'] = Hubspot::Config.hapikey unless options[:hapikey] == false
|
|
87
90
|
|
|
88
|
-
if
|
|
91
|
+
if /:portal_id/.match?(path)
|
|
89
92
|
Hubspot::Config.ensure! :portal_id
|
|
90
|
-
params[
|
|
93
|
+
params['portal_id'] = Hubspot::Config.portal_id
|
|
91
94
|
end
|
|
92
95
|
|
|
93
|
-
params.each do |
|
|
94
|
-
if path.match(":#{
|
|
95
|
-
path.gsub
|
|
96
|
-
params.delete(
|
|
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(
|
|
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?('?') ? '&' :
|
|
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
|
|
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 =
|
|
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:
|
|
153
|
+
post(url, body: opts[:body].to_json, headers:)
|
|
150
154
|
end
|
|
151
155
|
end
|
|
152
156
|
end
|
data/lib/hubspot/contact.rb
CHANGED
|
@@ -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?]
|
data/lib/hubspot/contact_list.rb
CHANGED
data/lib/hubspot/custom_event.rb
CHANGED
data/lib/hubspot/deal.rb
CHANGED
data/lib/hubspot/deprecator.rb
CHANGED
data/lib/hubspot/engagement.rb
CHANGED
data/lib/hubspot/event.rb
CHANGED
data/lib/hubspot/exceptions.rb
CHANGED
data/lib/hubspot/file.rb
CHANGED
data/lib/hubspot/form.rb
CHANGED
data/lib/hubspot/meeting.rb
CHANGED
data/lib/hubspot/oauth.rb
CHANGED
data/lib/hubspot/owner.rb
CHANGED
data/lib/hubspot/properties.rb
CHANGED
data/lib/hubspot/railtie.rb
CHANGED
data/lib/hubspot/resource.rb
CHANGED
|
@@ -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
|
|
data/lib/hubspot/subscription.rb
CHANGED
data/lib/hubspot/task.rb
CHANGED
data/lib/hubspot/ticket.rb
CHANGED
data/lib/hubspot/topic.rb
CHANGED
data/lib/hubspot/utils.rb
CHANGED
data/lib/hubspot-api-ruby.rb
CHANGED
data/spec/factories/companies.rb
CHANGED
data/spec/factories/contacts.rb
CHANGED
|
@@ -1,67 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
describe Hubspot::Connection do
|
|
2
|
-
describe
|
|
3
|
-
it
|
|
4
|
-
path =
|
|
5
|
-
body = { key:
|
|
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,
|
|
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({
|
|
12
|
+
expect(result).to eq({ 'key' => 'value' })
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
describe
|
|
15
|
-
it
|
|
16
|
-
path =
|
|
17
|
-
body = { id: 1, name:
|
|
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,
|
|
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:
|
|
22
|
-
expect(result).to eq({
|
|
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
|
|
27
|
-
it
|
|
28
|
-
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,
|
|
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
|
|
38
|
-
it
|
|
39
|
-
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,
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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({
|
|
56
|
+
expect(response).to eq({ 'vid' => 123 })
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
it
|
|
58
|
-
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,
|
|
64
|
-
body: JSON.generate(
|
|
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
|
|
76
|
-
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,
|
|
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
|
-
|
|
85
|
+
end.to raise_error(Hubspot::RequestError)
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
|
|
87
|
-
describe
|
|
88
|
-
it
|
|
89
|
-
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,
|
|
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
|
-
|
|
100
|
+
'https://api.hubapi.com/some/path',
|
|
99
101
|
{
|
|
100
|
-
body:
|
|
101
|
-
headers: {
|
|
102
|
+
body: '{}',
|
|
103
|
+
headers: { 'Content-Type' => 'application/json' }
|
|
102
104
|
}
|
|
103
105
|
)
|
|
104
|
-
expect(response).to eq({
|
|
106
|
+
expect(response).to eq({ 'vid' => 123 })
|
|
105
107
|
end
|
|
106
108
|
|
|
107
|
-
it
|
|
108
|
-
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,
|
|
114
|
-
|
|
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
|
|
126
|
-
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,
|
|
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
|
-
|
|
135
|
+
end.to raise_error(Hubspot::RequestError)
|
|
134
136
|
end
|
|
135
137
|
end
|
|
136
138
|
|
|
137
139
|
context 'private methods' do
|
|
138
|
-
describe
|
|
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 }.
|
|
148
|
+
expect { subject }.not_to(change { params })
|
|
146
149
|
end
|
|
147
150
|
|
|
148
|
-
context
|
|
149
|
-
let(:path) {
|
|
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(
|
|
156
|
+
Hubspot.configure(access_token: ENV.fetch('HUBSPOT_ACCESS_TOKEN'), portal_id: ENV.fetch('HUBSPOT_PORTAL_ID'))
|
|
154
157
|
end
|
|
155
158
|
|
|
156
|
-
it {
|
|
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
|
-
|
|
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
|
|
170
|
+
context 'with interpolations but no params' do
|
|
167
171
|
let(:params) { {} }
|
|
168
172
|
|
|
169
|
-
it
|
|
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
|
|
175
|
-
let(:params) { { email:
|
|
176
|
-
|
|
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
|
|
180
|
-
let(:path) {
|
|
181
|
-
let(:params) { { email:
|
|
182
|
-
|
|
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
|
|
186
|
-
let(:params) { { email:
|
|
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
|
-
|
|
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:
|
|
192
|
-
|
|
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
|
|
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:
|
|
199
|
-
|
|
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
|
|
203
|
-
let(:path) {
|
|
204
|
-
let(:params) { { batch_email: %w
|
|
205
|
-
|
|
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
|
|
210
|
-
let(:options) { { base_url:
|
|
211
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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::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,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.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
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/vcr.rb
CHANGED
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.
|
|
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:
|
|
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:
|
|
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: []
|