hubspot-api-ruby 0.21.0 → 0.22.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/hubspot-api-ruby.gemspec +3 -2
- data/lib/hubspot/contact.rb +29 -27
- data/lib/hubspot/contact_list.rb +66 -67
- data/lib/hubspot/resource.rb +6 -3
- data/spec/factories/contacts.rb +5 -3
- data/spec/lib/hubspot/connection_spec.rb +2 -2
- data/spec/lib/hubspot/contact_list_spec.rb +118 -156
- data/spec/lib/hubspot/contact_spec.rb +95 -35
- metadata +18 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 660784a9172dc42af4abe066bad9f2a5297fe8d7b4fe3e6f9fed5617d583fcaa
|
|
4
|
+
data.tar.gz: 1d6d7072a0c0ce71b9dcdba3155572be2f9e5b12b6e3a3fd0bb002acad0836a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf383fe3b8dc2cad6e64774874b90163c28cce2c8007bf7dfc850169ae31eda46615416716b9f4299decaa49b5d4309e3d52f3f60498085e3fb073db9376806f
|
|
7
|
+
data.tar.gz: 3870a04cb0535f399f8e29b1aeb2d95b65aa58cdee7c00b36ec502589099445de94c7a70d88725f0c3d9b10a934ab6ec95587d352d2af4b05a5dcbe32932b9cd
|
data/hubspot-api-ruby.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "hubspot-api-ruby"
|
|
3
|
-
s.version = "0.
|
|
3
|
+
s.version = "0.22.1"
|
|
4
4
|
s.require_paths = ["lib"]
|
|
5
5
|
s.authors = ["Jonathan"]
|
|
6
6
|
s.email = ["jonathan@hoggo.com"]
|
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
"changelog_uri" => "https://github.com/captaincontrat/hubspot-api-ruby/blob/master/History.md"
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
s.required_ruby_version = ">= 3.
|
|
18
|
+
s.required_ruby_version = ">= 3.2"
|
|
19
19
|
|
|
20
20
|
# Add runtime dependencies here
|
|
21
21
|
s.add_runtime_dependency "activesupport", ">= 4.2.2"
|
|
@@ -37,4 +37,5 @@ Gem::Specification.new do |s|
|
|
|
37
37
|
s.add_development_dependency("byebug")
|
|
38
38
|
s.add_development_dependency("faker")
|
|
39
39
|
s.add_development_dependency("factory_bot")
|
|
40
|
+
s.add_development_dependency("irb")
|
|
40
41
|
end
|
data/lib/hubspot/contact.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
class Hubspot::Contact < Hubspot::Resource
|
|
2
|
-
self.id_field =
|
|
3
|
-
self.update_method =
|
|
2
|
+
self.id_field = 'vid'
|
|
3
|
+
self.update_method = 'post'
|
|
4
4
|
|
|
5
|
-
ALL_PATH = '/
|
|
5
|
+
ALL_PATH = '/crm/v3/objects/contacts'
|
|
6
6
|
CREATE_PATH = '/contacts/v1/contact'
|
|
7
7
|
CREATE_OR_UPDATE_PATH = '/contacts/v1/contact/createOrUpdate/email/:email'
|
|
8
8
|
DELETE_PATH = '/contacts/v1/contact/vid/:id'
|
|
@@ -16,14 +16,16 @@ class Hubspot::Contact < Hubspot::Resource
|
|
|
16
16
|
|
|
17
17
|
class << self
|
|
18
18
|
def all(opts = {})
|
|
19
|
-
Hubspot::PagedCollection.new(opts) do |options,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
19
|
+
Hubspot::PagedCollection.new(opts) do |options, after, limit|
|
|
20
|
+
request_options = options.merge(limit:)
|
|
21
|
+
request_options[:after] = after if after.present?
|
|
22
|
+
response = Hubspot::Connection.get_json(ALL_PATH, request_options)
|
|
24
23
|
|
|
25
|
-
contacts = response[
|
|
26
|
-
|
|
24
|
+
contacts = response['results'].map do |result|
|
|
25
|
+
from_result result, id_field: Hubspot::Resource.id_field
|
|
26
|
+
end
|
|
27
|
+
after = response.dig('paging', 'next', 'after')
|
|
28
|
+
[contacts, after, after.present?]
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
@@ -31,7 +33,7 @@ class Hubspot::Contact < Hubspot::Resource
|
|
|
31
33
|
response = Hubspot::Connection.get_json(FIND_PATH, id: vid)
|
|
32
34
|
from_result(response)
|
|
33
35
|
end
|
|
34
|
-
|
|
36
|
+
|
|
35
37
|
def find_by_email(email)
|
|
36
38
|
response = Hubspot::Connection.get_json(FIND_BY_EMAIL_PATH, email: email)
|
|
37
39
|
from_result(response)
|
|
@@ -41,17 +43,17 @@ class Hubspot::Contact < Hubspot::Resource
|
|
|
41
43
|
response = Hubspot::Connection.get_json(FIND_BY_USER_TOKEN_PATH, token: token)
|
|
42
44
|
from_result(response)
|
|
43
45
|
end
|
|
44
|
-
|
|
46
|
+
alias find_by_utk find_by_user_token
|
|
45
47
|
|
|
46
48
|
def create(email, properties = {})
|
|
47
|
-
super(properties.merge(
|
|
49
|
+
super(properties.merge('email' => email))
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
def create_or_update(email, properties = {})
|
|
51
53
|
request = {
|
|
52
|
-
properties: Hubspot::Utils.hash_to_properties(properties.stringify_keys, key_name:
|
|
54
|
+
properties: Hubspot::Utils.hash_to_properties(properties.stringify_keys, key_name: 'property')
|
|
53
55
|
}
|
|
54
|
-
response = Hubspot::Connection.post_json(CREATE_OR_UPDATE_PATH, params: {email: email}, body: request)
|
|
56
|
+
response = Hubspot::Connection.post_json(CREATE_OR_UPDATE_PATH, params: { email: email }, body: request)
|
|
55
57
|
from_result(response)
|
|
56
58
|
end
|
|
57
59
|
|
|
@@ -60,10 +62,10 @@ class Hubspot::Contact < Hubspot::Resource
|
|
|
60
62
|
response = Hubspot::Connection.get_json(
|
|
61
63
|
SEARCH_PATH,
|
|
62
64
|
options.merge(q: query, offset: offset, count: limit)
|
|
63
|
-
|
|
65
|
+
)
|
|
64
66
|
|
|
65
|
-
contacts = response[
|
|
66
|
-
[contacts, response[
|
|
67
|
+
contacts = response['contacts'].map { |result| from_result(result) }
|
|
68
|
+
[contacts, response['offset'], response['has-more']]
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
|
|
@@ -71,23 +73,23 @@ class Hubspot::Contact < Hubspot::Resource
|
|
|
71
73
|
Hubspot::Connection.post_json(
|
|
72
74
|
MERGE_PATH,
|
|
73
75
|
params: { id: primary.to_i, no_parse: true },
|
|
74
|
-
body: {
|
|
75
|
-
|
|
76
|
+
body: { 'vidToMerge' => secondary.to_i }
|
|
77
|
+
)
|
|
76
78
|
|
|
77
79
|
true
|
|
78
80
|
end
|
|
79
|
-
|
|
81
|
+
|
|
80
82
|
def batch_update(contacts, opts = {})
|
|
81
83
|
request = contacts.map do |contact|
|
|
82
84
|
# Use the specified options or update with the changes
|
|
83
85
|
changes = opts.empty? ? contact.changes : opts
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
87
|
+
next if changes.empty?
|
|
88
|
+
|
|
89
|
+
{
|
|
90
|
+
'vid' => contact.id,
|
|
91
|
+
'properties' => changes.map { |k, v| { 'property' => k, 'value' => v } }
|
|
92
|
+
}
|
|
91
93
|
end
|
|
92
94
|
|
|
93
95
|
# Remove any objects without changes and return if there is nothing to update
|
data/lib/hubspot/contact_list.rb
CHANGED
|
@@ -3,106 +3,105 @@ module Hubspot
|
|
|
3
3
|
# HubSpot Contact lists API
|
|
4
4
|
#
|
|
5
5
|
class ContactList
|
|
6
|
-
LISTS_PATH
|
|
7
|
-
LIST_PATH
|
|
8
|
-
|
|
9
|
-
CONTACTS_PATH
|
|
10
|
-
RECENT_CONTACTS_PATH
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
LISTS_PATH = '/crm/v3/lists'
|
|
7
|
+
LIST_PATH = '/crm/v3/lists/:list_id'
|
|
8
|
+
SEARCH_PATH = LISTS_PATH + '/search'
|
|
9
|
+
CONTACTS_PATH = LIST_PATH + '/memberships'
|
|
10
|
+
RECENT_CONTACTS_PATH = LIST_PATH + '/memberships/join-order'
|
|
11
|
+
ADD_CONTACTS_PATH = LIST_PATH + '/memberships/add'
|
|
12
|
+
REMOVE_CONTACTS_PATH = LIST_PATH + '/memberships/remove'
|
|
13
|
+
UPDATE_NAME_PATH = LIST_PATH + '/update-list-name'
|
|
14
|
+
CONTACT_OBJECT_TYPE_ID = '0-1'
|
|
15
|
+
MANUAL_PROCESSING_TYPE = 'MANUAL'
|
|
13
16
|
|
|
14
17
|
class << self
|
|
15
|
-
# {
|
|
16
|
-
def create!(opts={})
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
# {https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/guide#create-a-list}
|
|
19
|
+
def create!(opts = {})
|
|
20
|
+
object_type_id = opts.delete(:object_type_id) { CONTACT_OBJECT_TYPE_ID }
|
|
21
|
+
processing_type = opts.delete(:processing_type) { MANUAL_PROCESSING_TYPE }
|
|
22
|
+
body = opts.merge(objectTypeId: object_type_id, processingType: processing_type)
|
|
19
23
|
|
|
20
|
-
response = Hubspot::Connection.post_json(LISTS_PATH, params: {}, body:
|
|
24
|
+
response = Hubspot::Connection.post_json(LISTS_PATH, params: {}, body:)
|
|
21
25
|
new(response)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
|
-
# {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
# {https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/guide#retrieve-by-searching-list-details}
|
|
29
|
+
def all(opts = {})
|
|
30
|
+
body = opts.delete(:body) || { query: '' }
|
|
31
|
+
|
|
32
|
+
Hubspot::PagedCollection.new(opts) do |options, after, limit|
|
|
33
|
+
response = Hubspot::Connection.post_json(
|
|
34
|
+
SEARCH_PATH,
|
|
35
|
+
options.merge('limit' => limit, 'offset' => after, 'offset_param' => 'after', params: {}, body:)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
lists = response['lists'].map { |list| new(list) }
|
|
39
|
+
after = response.dig('paging', 'next', 'after')
|
|
40
|
+
[lists, after, after.present?]
|
|
41
|
+
end
|
|
35
42
|
end
|
|
36
43
|
|
|
37
|
-
# {
|
|
38
|
-
# {
|
|
44
|
+
# {https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/get-list-listId}
|
|
45
|
+
# {https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/get-lists#parameter-list-ids}
|
|
39
46
|
def find(ids)
|
|
40
47
|
batch_mode, path, params = case ids
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
when Integer then [false, LIST_PATH, { list_id: ids }]
|
|
49
|
+
when String then [false, LIST_PATH, { list_id: ids.to_i }]
|
|
50
|
+
when Array then [true, LISTS_PATH, { listIds: ids.map(&:to_i) }]
|
|
51
|
+
else raise Hubspot::InvalidParams, 'expecting Integer or Array of Integers parameter'
|
|
52
|
+
end
|
|
46
53
|
|
|
47
54
|
response = Hubspot::Connection.get_json(path, params)
|
|
48
55
|
batch_mode ? response['lists'].map { |l| new(l) } : new(response)
|
|
49
56
|
end
|
|
50
57
|
end
|
|
51
58
|
|
|
52
|
-
attr_reader :id
|
|
53
|
-
attr_reader :portal_id
|
|
54
|
-
attr_reader :name
|
|
55
|
-
attr_reader :dynamic
|
|
56
|
-
attr_reader :properties
|
|
59
|
+
attr_reader :id, :legacy_list_id, :name, :processing_type, :properties
|
|
57
60
|
|
|
58
61
|
def initialize(hash)
|
|
59
|
-
|
|
62
|
+
send(:assign_properties, hash.key?('list') ? hash['list'] : hash)
|
|
60
63
|
end
|
|
61
64
|
|
|
62
|
-
# {
|
|
63
|
-
def
|
|
64
|
-
response = Hubspot::Connection.
|
|
65
|
-
|
|
65
|
+
# {https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/update-list-name}
|
|
66
|
+
def update_name!(new_name)
|
|
67
|
+
response = Hubspot::Connection.put_json(UPDATE_NAME_PATH, params: { list_id: id, listName: new_name }, body: {})
|
|
68
|
+
send(:assign_properties, response['updatedList'])
|
|
66
69
|
self
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
# {http://developers.hubspot.com/docs/methods/lists/delete_list}
|
|
70
73
|
def destroy!
|
|
71
|
-
response = Hubspot::Connection.delete_json(LIST_PATH, { list_id:
|
|
74
|
+
response = Hubspot::Connection.delete_json(LIST_PATH, { list_id: id })
|
|
72
75
|
@destroyed = (response.code == 204)
|
|
73
76
|
end
|
|
74
77
|
|
|
75
|
-
# {
|
|
76
|
-
def
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
@contacts = response['contacts'].map! { |c| Hubspot::Contact.from_result(c) }
|
|
88
|
-
paged ? response : @contacts
|
|
89
|
-
else
|
|
90
|
-
@contacts
|
|
78
|
+
# {https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/memberships/get-memberships-by-id}
|
|
79
|
+
def contact_ids(opts = {})
|
|
80
|
+
path = opts.delete(:recent) ? RECENT_CONTACTS_PATH : CONTACTS_PATH
|
|
81
|
+
opts[:list_id] = id
|
|
82
|
+
Hubspot::PagedCollection.new(opts) do |options, after, limit|
|
|
83
|
+
response = Hubspot::Connection.get_json(
|
|
84
|
+
path, options.merge('limit' => limit, 'offset' => after, 'offset_param' => 'after')
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
contact_ids = response['results'].pluck('recordId')
|
|
88
|
+
after = response.dig('paging', 'next', 'after')
|
|
89
|
+
[contact_ids, after, after.present?]
|
|
91
90
|
end
|
|
92
91
|
end
|
|
93
92
|
|
|
94
93
|
# {http://developers.hubspot.com/docs/methods/lists/add_contact_to_list}
|
|
95
|
-
def add(
|
|
96
|
-
contact_ids = [
|
|
97
|
-
response = Hubspot::Connection.
|
|
98
|
-
response['
|
|
94
|
+
def add(contact_ids)
|
|
95
|
+
contact_ids = [contact_ids].flatten.uniq.compact
|
|
96
|
+
response = Hubspot::Connection.put_json(ADD_CONTACTS_PATH, params: { list_id: id }, body: contact_ids)
|
|
97
|
+
response['recordsIdsAdded']&.sort == contact_ids.sort.map(&:to_s)
|
|
99
98
|
end
|
|
100
99
|
|
|
101
100
|
# {http://developers.hubspot.com/docs/methods/lists/remove_contact_from_list}
|
|
102
|
-
def remove(
|
|
103
|
-
contact_ids = [
|
|
104
|
-
response = Hubspot::Connection.
|
|
105
|
-
response['
|
|
101
|
+
def remove(contact_ids)
|
|
102
|
+
contact_ids = [contact_ids].flatten.uniq.compact
|
|
103
|
+
response = Hubspot::Connection.put_json(REMOVE_CONTACTS_PATH, params: { list_id: id }, body: contact_ids)
|
|
104
|
+
response['recordIdsRemoved']&.sort == contact_ids.sort.map(&:to_s)
|
|
106
105
|
end
|
|
107
106
|
|
|
108
107
|
def destroyed?
|
|
@@ -113,9 +112,9 @@ module Hubspot
|
|
|
113
112
|
|
|
114
113
|
def assign_properties(hash)
|
|
115
114
|
@id = hash['listId']
|
|
116
|
-
@
|
|
115
|
+
@legacy_list_id = hash['legacyListId']
|
|
117
116
|
@name = hash['name']
|
|
118
|
-
@
|
|
117
|
+
@processing_type = hash['processingType']
|
|
119
118
|
@properties = hash
|
|
120
119
|
end
|
|
121
120
|
end
|
data/lib/hubspot/resource.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Hubspot
|
|
|
9
9
|
self.update_method = "put"
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
|
-
def from_result(result)
|
|
12
|
+
def from_result(result, id_field: self.id_field)
|
|
13
13
|
resource = new(result[id_field])
|
|
14
14
|
resource.send(:initialize_from, result.with_indifferent_access)
|
|
15
15
|
resource
|
|
@@ -55,9 +55,12 @@ module Hubspot
|
|
|
55
55
|
@changes = HashWithIndifferentAccess.new
|
|
56
56
|
@properties = HashWithIndifferentAccess.new
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
case id_or_properties
|
|
59
|
+
when Integer, NilClass
|
|
59
60
|
@id = id_or_properties
|
|
60
|
-
|
|
61
|
+
when String
|
|
62
|
+
@id = Integer id_or_properties
|
|
63
|
+
when Hash
|
|
61
64
|
@id = id_or_properties.delete(id_field) || id_or_properties.delete(:id)
|
|
62
65
|
|
|
63
66
|
add_accessors(id_or_properties.keys)
|
data/spec/factories/contacts.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
1
|
FactoryBot.define do
|
|
3
|
-
factory :contact, class: Hubspot::Contact do
|
|
2
|
+
factory :contact, class: 'Hubspot::Contact' do
|
|
4
3
|
to_create { |instance| instance.save }
|
|
5
4
|
|
|
6
5
|
firstname { Faker::Name.first_name }
|
|
7
6
|
lastname { Faker::Name.last_name }
|
|
8
|
-
email
|
|
7
|
+
email do
|
|
8
|
+
Faker::Internet.email(name: "#{Time.new.to_i.to_s[-5..-1]}#{(0..3).map { rand(65..90).chr }.join}",
|
|
9
|
+
domain: 'hubspot.com')
|
|
10
|
+
end
|
|
9
11
|
end
|
|
10
12
|
end
|
|
@@ -212,9 +212,9 @@ describe Hubspot::Connection do
|
|
|
212
212
|
end
|
|
213
213
|
|
|
214
214
|
context "passing Array as parameters for batch mode, key is prefixed with batch_" do
|
|
215
|
-
let(:path) { Hubspot::ContactList::
|
|
215
|
+
let(:path) { Hubspot::ContactList::LISTS_PATH }
|
|
216
216
|
let(:params) { { batch_list_id: [1,2,3] } }
|
|
217
|
-
it { should == "https://api.hubapi.com/
|
|
217
|
+
it { should == "https://api.hubapi.com/crm/v3/lists?listId=1&listId=2&listId=3" }
|
|
218
218
|
end
|
|
219
219
|
end
|
|
220
220
|
end
|
|
@@ -1,104 +1,88 @@
|
|
|
1
1
|
describe Hubspot::ContactList do
|
|
2
2
|
# uncomment if you need to create test data in your panel.
|
|
3
|
-
# note that sandboxes have a limit of
|
|
3
|
+
# note that sandboxes have a limit of 10 dynamic lists
|
|
4
4
|
# before(:all) do
|
|
5
5
|
# VCR.use_cassette("create_all_lists") do
|
|
6
6
|
# 25.times { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
|
7
|
-
# 3.times { Hubspot::ContactList.create!(name: SecureRandom.hex,
|
|
7
|
+
# 3.times { Hubspot::ContactList.create!(name: SecureRandom.hex, processing_type: 'DYNAMIC', "filterBranch": { "filterBranches": [{ "filterBranches": [], "filterBranchType": "AND", "filters": [{ "filterType": "PROPERTY", property: "twitterhandle", operation: { operationType: 'STRING', operator: 'IS_EQUAL_TO', value: '@hubspot'}}]}], "filterBranchType": "OR", "filters": [] } ) }
|
|
8
8
|
# end
|
|
9
9
|
# end
|
|
10
10
|
|
|
11
|
-
let(:example_contact_list_hash) do
|
|
12
|
-
VCR.use_cassette("contact_list_example") do
|
|
13
|
-
headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
|
|
14
|
-
response = HTTParty.get("https://api.hubapi.com/contacts/v1/lists/static?count=1", headers: headers).parsed_response
|
|
15
|
-
response['lists'].first
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
11
|
let(:static_list) do
|
|
20
12
|
Hubspot::ContactList.create!(name: "static list #{SecureRandom.hex}")
|
|
21
13
|
end
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
result = instance_exec(count: 2, ¶ms[:block])
|
|
26
|
-
expect(result.size).to eql 2
|
|
15
|
+
describe '#initialize' do
|
|
16
|
+
subject { Hubspot::ContactList.new(example_contact_list_hash) }
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
let(:example_contact_list_hash) do
|
|
19
|
+
VCR.use_cassette('contact_list_example') do
|
|
20
|
+
headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
|
|
21
|
+
response = HTTParty.get('https://api.hubapi.com/contacts/v1/lists?count=2', headers: headers).parsed_response
|
|
22
|
+
response['lists'].last
|
|
23
|
+
end
|
|
30
24
|
end
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(
|
|
26
|
+
specify(:aggregate_failures) do
|
|
27
|
+
expect(subject).to be_an_instance_of Hubspot::ContactList
|
|
28
|
+
expect(subject.name).not_to be_empty
|
|
29
|
+
expect(subject.processing_type).to be_nil
|
|
30
|
+
expect(subject.properties).to be_a(Hash)
|
|
36
31
|
end
|
|
37
32
|
end
|
|
38
33
|
|
|
39
|
-
describe '#
|
|
40
|
-
subject { Hubspot::ContactList.new(example_contact_list_hash) }
|
|
41
|
-
|
|
42
|
-
it { should be_an_instance_of Hubspot::ContactList }
|
|
43
|
-
its(:id) { should be_an(Integer) }
|
|
44
|
-
its(:portal_id) { should be_a(Integer) }
|
|
45
|
-
its(:name) { should_not be_empty }
|
|
46
|
-
its(:dynamic) { should be false }
|
|
47
|
-
its(:properties) { should be_a(Hash) }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
describe '#contacts' do
|
|
34
|
+
describe '#contact_ids' do
|
|
51
35
|
cassette 'contacts_among_list'
|
|
52
36
|
|
|
53
37
|
let(:list) { @list }
|
|
54
38
|
|
|
55
39
|
before(:all) do
|
|
56
|
-
VCR.use_cassette 'create_and_add_all_contacts' do
|
|
40
|
+
VCR.use_cassette 'contact_lists/create_and_add_all_contacts' do
|
|
57
41
|
@list = Hubspot::ContactList.create!(name: "contacts list #{SecureRandom.hex}")
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@list.add(contact)
|
|
61
|
-
end
|
|
42
|
+
contacts = (1..30).map { Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com") }
|
|
43
|
+
@list.add(contacts.map(&:id))
|
|
62
44
|
end
|
|
63
45
|
end
|
|
64
46
|
|
|
65
|
-
it 'returns by default
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
expect(
|
|
70
|
-
expect(
|
|
71
|
-
|
|
72
|
-
expect(contacts.count).to eql 20
|
|
73
|
-
contact = contacts.first
|
|
74
|
-
expect(contact).to be_a(Hubspot::Contact)
|
|
75
|
-
expect(contact.email).to_not be_empty
|
|
47
|
+
it 'returns by default 25 contact lists with paging data' do
|
|
48
|
+
results = list.contact_ids
|
|
49
|
+
expect(results).to be_a(Hubspot::PagedCollection)
|
|
50
|
+
expect(results.first).to be_a(String)
|
|
51
|
+
expect(results.more?).to be true
|
|
52
|
+
expect(results.count).to eql 25
|
|
76
53
|
end
|
|
77
|
-
|
|
78
|
-
it_behaves_like 'count and offset', {block: ->(r) { Hubspot::ContactList.find(list.id).contacts(r) }}
|
|
79
54
|
end
|
|
80
55
|
|
|
81
56
|
describe '.create' do
|
|
82
|
-
subject{ Hubspot::ContactList.create!(
|
|
57
|
+
subject { Hubspot::ContactList.create!(name:) }
|
|
83
58
|
|
|
84
59
|
context 'with all required parameters' do
|
|
85
60
|
cassette 'create_list'
|
|
86
61
|
|
|
87
62
|
let(:name) { "testing list #{SecureRandom.hex}" }
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
63
|
+
|
|
64
|
+
specify(:aggregate_failures) do
|
|
65
|
+
expect(subject).to be_an_instance_of Hubspot::ContactList
|
|
66
|
+
expect(subject.processing_type).to eq described_class::MANUAL_PROCESSING_TYPE
|
|
67
|
+
end
|
|
92
68
|
|
|
93
69
|
context 'adding filters parameters' do
|
|
94
70
|
cassette 'create_list_with_filters'
|
|
95
71
|
|
|
96
72
|
it 'returns a ContactList object with filters set' do
|
|
97
73
|
name = "list with filters #{SecureRandom.hex}"
|
|
98
|
-
|
|
99
|
-
|
|
74
|
+
filter_branch = { filterBranches: [
|
|
75
|
+
{ filterBranches: [], filterBranchType: 'AND', filters: [
|
|
76
|
+
{ filterType: 'PROPERTY', property: 'twitterhandle',
|
|
77
|
+
operation: { operationType: 'STRING', operator: 'IS_EQUAL_TO', value: '@hubspot' } }
|
|
78
|
+
] }
|
|
79
|
+
], filterBranchType: 'OR', filters: [] }
|
|
80
|
+
|
|
81
|
+
list_with_filters = Hubspot::ContactList.create!(processing_type: 'DYNAMIC', name: name,
|
|
82
|
+
filterBranch: filter_branch)
|
|
100
83
|
expect(list_with_filters).to be_a(Hubspot::ContactList)
|
|
101
|
-
expect(list_with_filters.properties['
|
|
84
|
+
expect(list_with_filters.properties['filterBranch']).not_to be_empty
|
|
85
|
+
expect(list_with_filters.processing_type).to eq 'DYNAMIC'
|
|
102
86
|
end
|
|
103
87
|
end
|
|
104
88
|
end
|
|
@@ -107,75 +91,49 @@ describe Hubspot::ContactList do
|
|
|
107
91
|
cassette 'fail_to_create_list'
|
|
108
92
|
|
|
109
93
|
it 'raises an error' do
|
|
110
|
-
expect { Hubspot::ContactList.create!(
|
|
94
|
+
expect { Hubspot::ContactList.create!(name: nil) }.to raise_error(Hubspot::RequestError)
|
|
111
95
|
end
|
|
112
96
|
end
|
|
113
97
|
end
|
|
114
98
|
|
|
115
99
|
describe '.all' do
|
|
116
|
-
|
|
117
|
-
cassette 'find_all_lists'
|
|
100
|
+
cassette 'find_all_lists'
|
|
118
101
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
102
|
+
it 'returns by default 20 contact lists' do
|
|
103
|
+
lists = Hubspot::ContactList.all
|
|
104
|
+
expect(lists).to be_a(Hubspot::PagedCollection)
|
|
105
|
+
expect(lists.count).to eql 20
|
|
122
106
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it_behaves_like 'count and offset', {block: ->(r) { Hubspot::ContactList.all(r) }}
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
context 'static lists' do
|
|
132
|
-
cassette 'find_all_stastic_lists'
|
|
133
|
-
|
|
134
|
-
it 'returns by defaut all the static contact lists' do
|
|
135
|
-
lists = Hubspot::ContactList.all(static: true)
|
|
136
|
-
expect(lists.count).to be > 2
|
|
137
|
-
|
|
138
|
-
list = lists.first
|
|
139
|
-
expect(list).to be_a(Hubspot::ContactList)
|
|
140
|
-
expect(list.dynamic).to be false
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context 'dynamic lists' do
|
|
145
|
-
cassette 'find_all_dynamic_lists'
|
|
146
|
-
|
|
147
|
-
it 'returns by defaut all the dynamic contact lists' do
|
|
148
|
-
lists = Hubspot::ContactList.all(dynamic: true)
|
|
149
|
-
expect(lists.count).to be > 2
|
|
150
|
-
|
|
151
|
-
list = lists.first
|
|
152
|
-
expect(list).to be_a(Hubspot::ContactList)
|
|
153
|
-
expect(list.dynamic).to be true
|
|
154
|
-
end
|
|
107
|
+
list = lists.first
|
|
108
|
+
expect(list).to be_a(Hubspot::ContactList)
|
|
109
|
+
expect(list.id).to be_present
|
|
155
110
|
end
|
|
156
111
|
end
|
|
157
112
|
|
|
158
113
|
describe '.find' do
|
|
159
114
|
context 'given an id' do
|
|
160
|
-
cassette
|
|
115
|
+
cassette 'contact_list_find'
|
|
161
116
|
subject { Hubspot::ContactList.find(id) }
|
|
162
117
|
|
|
163
|
-
let(:list) { Hubspot::ContactList.
|
|
118
|
+
let(:list) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
|
164
119
|
|
|
165
120
|
context 'when the contact list is found' do
|
|
166
121
|
let(:id) { list.id.to_i }
|
|
167
|
-
it { should be_an_instance_of Hubspot::ContactList }
|
|
168
|
-
its(:name) { should == list.name }
|
|
169
122
|
|
|
170
|
-
|
|
123
|
+
it { is_expected.to be_an_instance_of Hubspot::ContactList }
|
|
124
|
+
its(:name) { is_expected.to eq list.name }
|
|
125
|
+
|
|
126
|
+
context 'string id' do
|
|
171
127
|
let(:id) { list.id.to_s }
|
|
172
|
-
|
|
128
|
+
|
|
129
|
+
it { is_expected.to be_an_instance_of Hubspot::ContactList }
|
|
130
|
+
its(:name) { is_expected.to eq list.name }
|
|
173
131
|
end
|
|
174
132
|
end
|
|
175
133
|
|
|
176
134
|
context 'Wrong parameter type given' do
|
|
177
135
|
it 'raises an error' do
|
|
178
|
-
expect { Hubspot::ContactList.find(
|
|
136
|
+
expect { Hubspot::ContactList.find(foo: :bar) }.to raise_error(Hubspot::InvalidParams)
|
|
179
137
|
end
|
|
180
138
|
end
|
|
181
139
|
|
|
@@ -187,32 +145,30 @@ describe Hubspot::ContactList do
|
|
|
187
145
|
end
|
|
188
146
|
|
|
189
147
|
context 'given a list of ids' do
|
|
190
|
-
cassette
|
|
148
|
+
cassette 'contact_list_batch_find'
|
|
191
149
|
|
|
192
150
|
let(:list1) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
|
193
151
|
let(:list2) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
|
194
152
|
let(:list3) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
|
|
195
153
|
|
|
196
154
|
it 'find lists of contacts' do
|
|
197
|
-
lists = Hubspot::ContactList.find([list1.id,list2.id,list3.id])
|
|
155
|
+
lists = Hubspot::ContactList.find([list1.id, list2.id, list3.id])
|
|
198
156
|
list = lists.first
|
|
199
157
|
expect(list).to be_a(Hubspot::ContactList)
|
|
200
|
-
expect(
|
|
201
|
-
expect(lists.second.id).to be == list2.id
|
|
202
|
-
expect(lists.last.id).to be == list3.id
|
|
158
|
+
expect(lists.map(&:id)).to contain_exactly(list1.id, list2.id, list3.id)
|
|
203
159
|
end
|
|
204
160
|
end
|
|
205
161
|
end
|
|
206
162
|
|
|
207
|
-
describe
|
|
208
|
-
context
|
|
209
|
-
it
|
|
210
|
-
VCR.use_cassette(
|
|
163
|
+
describe '#add' do
|
|
164
|
+
context 'for a static list' do
|
|
165
|
+
it 'adds the contact to the contact list' do
|
|
166
|
+
VCR.use_cassette('contact_lists/add_contact') do
|
|
211
167
|
contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
|
|
212
168
|
contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
|
|
213
169
|
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
|
214
170
|
|
|
215
|
-
result = contact_list.add([contact])
|
|
171
|
+
result = contact_list.add([contact.id])
|
|
216
172
|
|
|
217
173
|
expect(result).to be true
|
|
218
174
|
|
|
@@ -221,18 +177,18 @@ describe Hubspot::ContactList do
|
|
|
221
177
|
end
|
|
222
178
|
end
|
|
223
179
|
|
|
224
|
-
context
|
|
225
|
-
it
|
|
226
|
-
VCR.use_cassette(
|
|
180
|
+
context 'when the contact already exists in the contact list' do
|
|
181
|
+
it 'returns false' do
|
|
182
|
+
VCR.use_cassette('contact_lists/add_existing_contact') do
|
|
227
183
|
contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
|
|
228
184
|
|
|
229
185
|
contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
|
|
230
186
|
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
|
231
|
-
contact_list.add([contact])
|
|
187
|
+
contact_list.add([contact.id])
|
|
232
188
|
|
|
233
|
-
result = contact_list.add([contact])
|
|
189
|
+
result = contact_list.add([contact.id])
|
|
234
190
|
|
|
235
|
-
expect(result).to be
|
|
191
|
+
expect(result).to be false
|
|
236
192
|
|
|
237
193
|
contact.delete
|
|
238
194
|
contact_list.destroy!
|
|
@@ -241,70 +197,76 @@ describe Hubspot::ContactList do
|
|
|
241
197
|
end
|
|
242
198
|
end
|
|
243
199
|
|
|
244
|
-
context
|
|
245
|
-
it
|
|
246
|
-
VCR.use_cassette(
|
|
200
|
+
context 'for a dynamic list' do
|
|
201
|
+
it 'raises an error as dynamic lists add contacts via on filters' do
|
|
202
|
+
VCR.use_cassette('contact_lists/add_contact_to_dynamic_list') do
|
|
247
203
|
contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
|
|
204
|
+
filter_branch = {
|
|
205
|
+
filterBranches: [{ filterBranches: [], filterBranchType: 'AND', filters: [
|
|
206
|
+
{ filterType: 'PROPERTY', property: 'twitterhandle',
|
|
207
|
+
operation: { operationType: 'STRING', operator: 'IS_EQUAL_TO', value: '@hubspot' } }
|
|
208
|
+
] }], filterBranchType: 'OR', filters: []
|
|
209
|
+
}
|
|
248
210
|
contact_list_params = {
|
|
249
211
|
name: "my-contacts-list-#{SecureRandom.hex}",
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
[
|
|
253
|
-
{
|
|
254
|
-
"operator": "EQ",
|
|
255
|
-
"property": "email",
|
|
256
|
-
"type": "string",
|
|
257
|
-
"value": "@hubspot.com"
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
],
|
|
212
|
+
processing_type: 'DYNAMIC',
|
|
213
|
+
filterBranch: filter_branch
|
|
261
214
|
}
|
|
262
215
|
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
|
263
216
|
|
|
264
|
-
expect {
|
|
265
|
-
contact_list.add(contact)
|
|
266
|
-
}.to raise_error(Hubspot::RequestError)
|
|
217
|
+
expect { contact_list.add(contact) }.to raise_error(Hubspot::RequestError)
|
|
267
218
|
end
|
|
268
219
|
end
|
|
269
220
|
end
|
|
270
221
|
end
|
|
271
222
|
|
|
272
223
|
describe '#remove' do
|
|
273
|
-
|
|
224
|
+
it 'returns true if removes all contacts' do
|
|
225
|
+
VCR.use_cassette('contact_lists/remove_contact') do
|
|
226
|
+
contact_ids = (1..2).map { Hubspot::Contact.create("#{SecureRandom.hex}@example.com").id }
|
|
227
|
+
contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
|
|
228
|
+
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
|
229
|
+
|
|
230
|
+
contact_list.add(contact_ids)
|
|
231
|
+
result = contact_list.remove(contact_ids)
|
|
232
|
+
|
|
233
|
+
expect(result).to be true
|
|
274
234
|
|
|
275
|
-
|
|
276
|
-
it 'returns true if removes all contacts in batch mode' do
|
|
277
|
-
list = Hubspot::ContactList.new(example_contact_list_hash)
|
|
278
|
-
contacts = list.contacts(count: 2)
|
|
279
|
-
expect(list.remove([contacts.first, contacts.last])).to be true
|
|
235
|
+
contact_list.destroy!
|
|
280
236
|
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
it 'returns false if the contact cannot be removed' do
|
|
240
|
+
VCR.use_cassette('contact_lists/remove_unknown_contact') do
|
|
241
|
+
contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
|
|
242
|
+
contact_list = Hubspot::ContactList.create!(contact_list_params)
|
|
243
|
+
result = contact_list.remove([42])
|
|
244
|
+
expect(result).to be false
|
|
281
245
|
|
|
282
|
-
|
|
283
|
-
contact_not_present_in_list = Hubspot::Contact.new(1234)
|
|
284
|
-
expect(static_list.remove(contact_not_present_in_list)).to be false
|
|
246
|
+
contact_list.destroy!
|
|
285
247
|
end
|
|
286
248
|
end
|
|
287
249
|
end
|
|
288
250
|
|
|
289
|
-
describe '#
|
|
290
|
-
cassette
|
|
291
|
-
|
|
292
|
-
let(:params) { { name: "updated list name" } }
|
|
293
|
-
subject { static_list.update!(params) }
|
|
251
|
+
describe '#update_name!' do
|
|
252
|
+
cassette 'contact_list_update'
|
|
294
253
|
|
|
295
|
-
|
|
296
|
-
its(:name){ should == params[:name] }
|
|
254
|
+
subject { static_list.update_name!('updated list name') }
|
|
297
255
|
|
|
298
256
|
after { static_list.destroy! }
|
|
257
|
+
|
|
258
|
+
it { is_expected.to be_an_instance_of Hubspot::ContactList }
|
|
259
|
+
its(:name) { is_expected.to eq 'updated list name' }
|
|
299
260
|
end
|
|
300
261
|
|
|
301
262
|
describe '#destroy!' do
|
|
302
|
-
cassette
|
|
263
|
+
cassette 'contact_list_destroy'
|
|
264
|
+
|
|
265
|
+
subject { static_list.destroy! }
|
|
303
266
|
|
|
304
|
-
|
|
305
|
-
it { should be true }
|
|
267
|
+
it { is_expected.to be true }
|
|
306
268
|
|
|
307
|
-
it
|
|
269
|
+
it 'is destroyed' do
|
|
308
270
|
subject
|
|
309
271
|
expect(static_list).to be_destroyed
|
|
310
272
|
end
|
|
@@ -1,23 +1,81 @@
|
|
|
1
1
|
RSpec.describe Hubspot::Contact do
|
|
2
|
-
|
|
3
|
-
it_behaves_like "a saveable resource", :contact do
|
|
2
|
+
it_behaves_like 'a saveable resource', :contact do
|
|
4
3
|
def set_property(contact)
|
|
5
|
-
contact.firstname =
|
|
4
|
+
contact.firstname = 'foobar'
|
|
6
5
|
end
|
|
7
6
|
end
|
|
8
7
|
|
|
9
|
-
it_behaves_like
|
|
10
|
-
let(:changed_properties) { { firstname:
|
|
11
|
-
let(:overlapping_properties) { { firstname:
|
|
8
|
+
it_behaves_like 'an updateable resource', :contact do
|
|
9
|
+
let(:changed_properties) { { firstname: 'foobar' } }
|
|
10
|
+
let(:overlapping_properties) { { firstname: 'asdf', lastname: 'qwer' } }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.all' do
|
|
14
|
+
context 'without options' do
|
|
15
|
+
cassette
|
|
16
|
+
|
|
17
|
+
subject { described_class.all }
|
|
18
|
+
|
|
19
|
+
it 'returns a collection' do
|
|
20
|
+
expect(subject).to be_a(Hubspot::PagedCollection)
|
|
21
|
+
expect(subject.first).to be_a(Hubspot::Contact)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'has an offset' do
|
|
25
|
+
expect(subject.next_offset).not_to be_blank
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'identifies if there are more resources' do
|
|
29
|
+
expect(subject.more?).to be true
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context 'with an offset' do
|
|
34
|
+
cassette
|
|
35
|
+
|
|
36
|
+
subject { described_class.all offset: contact.id }
|
|
37
|
+
|
|
38
|
+
let!(:contact) { create :contact }
|
|
39
|
+
|
|
40
|
+
it 'returns a collection' do
|
|
41
|
+
expect(subject).to be_a(Hubspot::PagedCollection)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'has an offset' do
|
|
45
|
+
expect(subject.next_offset).not_to be_blank
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'identifies if there are more resources' do
|
|
49
|
+
expect(subject.more?).not_to be_nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context 'with a limit' do
|
|
54
|
+
cassette
|
|
55
|
+
|
|
56
|
+
subject { described_class.all limit: limit }
|
|
57
|
+
|
|
58
|
+
let(:limit) { 1 }
|
|
59
|
+
|
|
60
|
+
it 'returns a collection' do
|
|
61
|
+
expect(subject).to be_a(Hubspot::PagedCollection)
|
|
62
|
+
expect(subject.first).to be_a(Hubspot::Contact)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'respects the limit' do
|
|
66
|
+
expect(subject.size).to eq(limit)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
12
69
|
end
|
|
13
70
|
|
|
14
71
|
describe '.find' do
|
|
15
72
|
context 'with a valid ID' do
|
|
16
73
|
cassette
|
|
17
74
|
|
|
75
|
+
subject { described_class.find contact.id }
|
|
76
|
+
|
|
18
77
|
let(:company) { create :company }
|
|
19
78
|
let(:contact) { create :contact, associatedcompanyid: company.id }
|
|
20
|
-
subject { described_class.find contact.id }
|
|
21
79
|
|
|
22
80
|
it 'finds the contact' do
|
|
23
81
|
expect(subject).to be_a(described_class)
|
|
@@ -31,9 +89,9 @@ RSpec.describe Hubspot::Contact do
|
|
|
31
89
|
subject { described_class.find 0 }
|
|
32
90
|
|
|
33
91
|
it 'raises an error' do
|
|
34
|
-
expect
|
|
92
|
+
expect do
|
|
35
93
|
subject
|
|
36
|
-
|
|
94
|
+
end.to raise_error(Hubspot::NotFoundError, /contact does not exist/)
|
|
37
95
|
end
|
|
38
96
|
end
|
|
39
97
|
end
|
|
@@ -42,9 +100,10 @@ RSpec.describe Hubspot::Contact do
|
|
|
42
100
|
context 'without properties' do
|
|
43
101
|
cassette
|
|
44
102
|
|
|
45
|
-
let(:email) { Faker::Internet.email(name: "#{(0..3).map { (65 + rand(26)).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
|
|
46
103
|
subject { described_class.create email }
|
|
47
104
|
|
|
105
|
+
let(:email) { Faker::Internet.email(name: "#{(0..3).map { rand(65..90).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
|
|
106
|
+
|
|
48
107
|
it 'creates a new contact' do
|
|
49
108
|
expect(subject).to be_a(described_class)
|
|
50
109
|
expect(subject.id).not_to be_nil
|
|
@@ -54,12 +113,12 @@ RSpec.describe Hubspot::Contact do
|
|
|
54
113
|
context 'with properties' do
|
|
55
114
|
cassette
|
|
56
115
|
|
|
57
|
-
let(:email) { Faker::Internet.email(name: "#{(0..3).map { (65 + rand(26)).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
|
|
58
|
-
let(:firstname) { "Allison" }
|
|
59
|
-
let(:properties) { { firstname: firstname } }
|
|
60
|
-
|
|
61
116
|
subject { described_class.create email, properties }
|
|
62
117
|
|
|
118
|
+
let(:email) { Faker::Internet.email(name: "#{(0..3).map { rand(65..90).chr }.join}#{Time.new.to_i.to_s[-5..-1]}") }
|
|
119
|
+
let(:firstname) { 'Allison' }
|
|
120
|
+
let(:properties) { { firstname: firstname } }
|
|
121
|
+
|
|
63
122
|
it 'creates a new contact' do
|
|
64
123
|
expect(subject).to be_a(described_class)
|
|
65
124
|
expect(subject.id).not_to be_nil
|
|
@@ -77,29 +136,29 @@ RSpec.describe Hubspot::Contact do
|
|
|
77
136
|
context 'with an existing email address' do
|
|
78
137
|
cassette
|
|
79
138
|
|
|
139
|
+
subject { described_class.create email }
|
|
140
|
+
|
|
80
141
|
let(:contact) { create :contact }
|
|
81
142
|
let(:email) { contact.email }
|
|
82
143
|
|
|
83
|
-
subject { described_class.create email }
|
|
84
|
-
|
|
85
144
|
it 'raises an error' do
|
|
86
|
-
expect
|
|
145
|
+
expect do
|
|
87
146
|
subject
|
|
88
|
-
|
|
147
|
+
end.to raise_error(Hubspot::RequestError)
|
|
89
148
|
end
|
|
90
149
|
end
|
|
91
150
|
|
|
92
151
|
context 'with an invalid email address' do
|
|
93
152
|
cassette
|
|
94
153
|
|
|
95
|
-
let(:email) { 'an_invalid_email' }
|
|
96
|
-
|
|
97
154
|
subject { described_class.create email }
|
|
98
155
|
|
|
156
|
+
let(:email) { 'an_invalid_email' }
|
|
157
|
+
|
|
99
158
|
it 'raises an error' do
|
|
100
|
-
expect
|
|
159
|
+
expect do
|
|
101
160
|
subject
|
|
102
|
-
|
|
161
|
+
end.to raise_error(Hubspot::RequestError)
|
|
103
162
|
end
|
|
104
163
|
end
|
|
105
164
|
end
|
|
@@ -107,10 +166,10 @@ RSpec.describe Hubspot::Contact do
|
|
|
107
166
|
describe '.find_by_email' do
|
|
108
167
|
cassette
|
|
109
168
|
|
|
110
|
-
let(:contact) { create :contact }
|
|
111
|
-
|
|
112
169
|
subject { described_class.find_by_email contact.email }
|
|
113
170
|
|
|
171
|
+
let(:contact) { create :contact }
|
|
172
|
+
|
|
114
173
|
it 'finds the contact' do
|
|
115
174
|
expect(subject).to be_a(described_class)
|
|
116
175
|
expect(subject.id).to eq(contact.id)
|
|
@@ -124,9 +183,10 @@ RSpec.describe Hubspot::Contact do
|
|
|
124
183
|
describe '.find_by_user_token' do
|
|
125
184
|
cassette
|
|
126
185
|
|
|
127
|
-
let(:contact) { create :contact }
|
|
128
186
|
subject { described_class.find_by_user_token contact.utk }
|
|
129
187
|
|
|
188
|
+
let(:contact) { create :contact }
|
|
189
|
+
|
|
130
190
|
it 'finds the contact' do
|
|
131
191
|
skip 'need a contact with a user token'
|
|
132
192
|
expect(subject).to be_a(described_class)
|
|
@@ -167,11 +227,11 @@ RSpec.describe Hubspot::Contact do
|
|
|
167
227
|
context 'with valid contact ids' do
|
|
168
228
|
cassette
|
|
169
229
|
|
|
230
|
+
subject { described_class.merge contact1.id, contact2.id }
|
|
231
|
+
|
|
170
232
|
let!(:contact1) { create :contact }
|
|
171
233
|
let!(:contact2) { create :contact }
|
|
172
234
|
|
|
173
|
-
subject { described_class.merge contact1.id, contact2.id }
|
|
174
|
-
|
|
175
235
|
it 'succeeds' do
|
|
176
236
|
expect(subject).to be_truthy
|
|
177
237
|
end
|
|
@@ -183,9 +243,9 @@ RSpec.describe Hubspot::Contact do
|
|
|
183
243
|
subject { described_class.merge 1, 2 }
|
|
184
244
|
|
|
185
245
|
it 'raises an error' do
|
|
186
|
-
expect
|
|
246
|
+
expect do
|
|
187
247
|
subject
|
|
188
|
-
|
|
248
|
+
end.to raise_error(Hubspot::RequestError)
|
|
189
249
|
end
|
|
190
250
|
end
|
|
191
251
|
end
|
|
@@ -194,11 +254,11 @@ RSpec.describe Hubspot::Contact do
|
|
|
194
254
|
context 'with a valid contact' do
|
|
195
255
|
cassette
|
|
196
256
|
|
|
257
|
+
subject { contact1.merge(contact2) }
|
|
258
|
+
|
|
197
259
|
let!(:contact1) { create :contact }
|
|
198
260
|
let!(:contact2) { create :contact }
|
|
199
261
|
|
|
200
|
-
subject { contact1.merge(contact2) }
|
|
201
|
-
|
|
202
262
|
it 'succeeds' do
|
|
203
263
|
expect(subject).to be_truthy
|
|
204
264
|
end
|
|
@@ -207,14 +267,14 @@ RSpec.describe Hubspot::Contact do
|
|
|
207
267
|
context 'with an invalid contact' do
|
|
208
268
|
cassette
|
|
209
269
|
|
|
210
|
-
let!(:contact1) { create :contact }
|
|
211
|
-
|
|
212
270
|
subject { contact1.merge(contact1.id) }
|
|
213
271
|
|
|
272
|
+
let!(:contact1) { create :contact }
|
|
273
|
+
|
|
214
274
|
it 'raises an error' do
|
|
215
|
-
expect
|
|
275
|
+
expect do
|
|
216
276
|
subject
|
|
217
|
-
|
|
277
|
+
end.to raise_error(Hubspot::RequestError)
|
|
218
278
|
end
|
|
219
279
|
end
|
|
220
280
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hubspot-api-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.22.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathan
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -248,6 +247,20 @@ dependencies:
|
|
|
248
247
|
- - ">="
|
|
249
248
|
- !ruby/object:Gem::Version
|
|
250
249
|
version: '0'
|
|
250
|
+
- !ruby/object:Gem::Dependency
|
|
251
|
+
name: irb
|
|
252
|
+
requirement: !ruby/object:Gem::Requirement
|
|
253
|
+
requirements:
|
|
254
|
+
- - ">="
|
|
255
|
+
- !ruby/object:Gem::Version
|
|
256
|
+
version: '0'
|
|
257
|
+
type: :development
|
|
258
|
+
prerelease: false
|
|
259
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
260
|
+
requirements:
|
|
261
|
+
- - ">="
|
|
262
|
+
- !ruby/object:Gem::Version
|
|
263
|
+
version: '0'
|
|
251
264
|
description: hubspot-api-ruby is a wrapper for the HubSpot REST API
|
|
252
265
|
email:
|
|
253
266
|
- jonathan@hoggo.com
|
|
@@ -339,7 +352,6 @@ licenses:
|
|
|
339
352
|
- MIT
|
|
340
353
|
metadata:
|
|
341
354
|
changelog_uri: https://github.com/captaincontrat/hubspot-api-ruby/blob/master/History.md
|
|
342
|
-
post_install_message:
|
|
343
355
|
rdoc_options: []
|
|
344
356
|
require_paths:
|
|
345
357
|
- lib
|
|
@@ -347,15 +359,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
347
359
|
requirements:
|
|
348
360
|
- - ">="
|
|
349
361
|
- !ruby/object:Gem::Version
|
|
350
|
-
version: '3.
|
|
362
|
+
version: '3.2'
|
|
351
363
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
352
364
|
requirements:
|
|
353
365
|
- - ">="
|
|
354
366
|
- !ruby/object:Gem::Version
|
|
355
367
|
version: '0'
|
|
356
368
|
requirements: []
|
|
357
|
-
rubygems_version:
|
|
358
|
-
signing_key:
|
|
369
|
+
rubygems_version: 4.0.6
|
|
359
370
|
specification_version: 4
|
|
360
371
|
summary: hubspot-api-ruby is a wrapper for the HubSpot REST API
|
|
361
372
|
test_files: []
|