hubspot-ruby 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hubspot-ruby.gemspec +3 -3
- data/lib/hubspot/company.rb +25 -8
- data/lib/hubspot/contact.rb +6 -1
- data/lib/hubspot/properties.rb +1 -1
- data/spec/lib/hubspot/company_spec.rb +29 -5
- data/spec/lib/hubspot/contact_spec.rb +16 -0
- data/spec/lib/hubspot/deal_spec.rb +26 -9
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3a1711f64e0786c4ea7fea3ae863130e3f8a3d5
|
4
|
+
data.tar.gz: 7c350471fe6a943453353c4a54021a104abb6b1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbf007dcda9eed037c323f4f9209b9cfed55926458b923fc9a7bbf95c88cf5ef0bd7e01857affd32c8d8d4649613ebfa1a614d84897ec8e9ba7ca4398550c615
|
7
|
+
data.tar.gz: 96a5651da299bdd400c02da77be240d76aecdf7acc72bc1c6e93b9dd6b24fbb3653dcbbb8da09413b83a90c6bc4c0557ef4a5dfa0c06c3fcb0e6b536a895c9b6
|
data/hubspot-ruby.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "hubspot-ruby"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.4.0"
|
4
4
|
s.require_paths = ["lib"]
|
5
|
-
s.authors = ["Andrew DiMichele"]
|
5
|
+
s.authors = ["Andrew DiMichele", "Chris Bisnett"]
|
6
6
|
s.description = "hubspot-ruby is a wrapper for the HubSpot REST API"
|
7
7
|
s.files = [".rspec", "Gemfile", "Guardfile", "LICENSE.txt", "README.md", "RELEASING.md", "Rakefile", "hubspot-ruby.gemspec"]
|
8
8
|
s.files += Dir["lib/**/*.rb"]
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_runtime_dependency "httparty", ">=0.10.0"
|
17
17
|
|
18
18
|
# Add development-only dependencies here
|
19
|
-
s.add_development_dependency("rake")
|
19
|
+
s.add_development_dependency("rake", "~> 11.0")
|
20
20
|
s.add_development_dependency("rspec", "~> 2.0")
|
21
21
|
s.add_development_dependency("rr")
|
22
22
|
s.add_development_dependency("webmock", "< 1.10")
|
data/lib/hubspot/company.rb
CHANGED
@@ -9,7 +9,7 @@ module Hubspot
|
|
9
9
|
RECENTLY_CREATED_COMPANIES_PATH = "/companies/v2/companies/recent/created"
|
10
10
|
RECENTLY_MODIFIED_COMPANIES_PATH = "/companies/v2/companies/recent/modified"
|
11
11
|
GET_COMPANY_BY_ID_PATH = "/companies/v2/companies/:company_id"
|
12
|
-
GET_COMPANY_BY_DOMAIN_PATH = "/companies/v2/
|
12
|
+
GET_COMPANY_BY_DOMAIN_PATH = "/companies/v2/domains/:domain/companies"
|
13
13
|
UPDATE_COMPANY_PATH = "/companies/v2/companies/:company_id"
|
14
14
|
ADD_CONTACT_TO_COMPANY_PATH = "/companies/v2/companies/:company_id/contacts/:vid"
|
15
15
|
DESTROY_COMPANY_PATH = "/companies/v2/companies/:company_id"
|
@@ -39,18 +39,35 @@ module Hubspot
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Finds a list of companies by domain
|
42
|
-
# {
|
42
|
+
# {https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain}
|
43
43
|
# @param domain [String] company domain to search by
|
44
|
+
# @param options [Hash] Possible options are:
|
45
|
+
# limit [Integer] for pagination
|
46
|
+
# properties [Array] list of company properties to recieve
|
47
|
+
# offset_company_id [Integer] for pagination (should be company ID)
|
44
48
|
# @return [Array] Array of Hubspot::Company records
|
45
|
-
def find_by_domain(domain)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
def find_by_domain(domain, options = {})
|
50
|
+
raise Hubspot::InvalidParams, 'expecting String parameter' unless domain.try(:is_a?, String)
|
51
|
+
|
52
|
+
limit = options.fetch(:limit, 100)
|
53
|
+
properties = options.fetch(:properties) { Hubspot::CompanyProperties.all.map { |property| property["name"] } }
|
54
|
+
offset_company_id = options.fetch(:offset_company_id, nil)
|
55
|
+
|
56
|
+
post_data = {
|
57
|
+
"limit" => limit,
|
58
|
+
"requestOptions" => {
|
59
|
+
"properties" => properties
|
60
|
+
}
|
61
|
+
}
|
62
|
+
post_data["offset"] = {
|
63
|
+
"isPrimary" => true,
|
64
|
+
"companyId" => offset_company_id
|
65
|
+
} if offset_company_id
|
49
66
|
|
50
67
|
companies = []
|
51
68
|
begin
|
52
|
-
response = Hubspot::Connection.
|
53
|
-
companies = response.try(:map) { |company| new(company) }
|
69
|
+
response = Hubspot::Connection.post_json(GET_COMPANY_BY_DOMAIN_PATH, params: { domain: domain }, body: post_data )
|
70
|
+
companies = response["results"].try(:map) { |company| new(company) }
|
54
71
|
rescue => e
|
55
72
|
raise e unless e.message =~ /not found/ # 404 / hanle the error and kindly return an empty array
|
56
73
|
end
|
data/lib/hubspot/contact.rb
CHANGED
@@ -18,6 +18,7 @@ module Hubspot
|
|
18
18
|
DESTROY_CONTACT_PATH = '/contacts/v1/contact/vid/:contact_id'
|
19
19
|
CONTACTS_PATH = '/contacts/v1/lists/all/contacts/all'
|
20
20
|
RECENTLY_UPDATED_PATH = '/contacts/v1/lists/recently_updated/contacts/recent'
|
21
|
+
RECENTLY_CREATED_PATH = '/contacts/v1/lists/all/contacts/recent'
|
21
22
|
CREATE_OR_UPDATE_PATH = '/contacts/v1/contact/createOrUpdate/email/:contact_email'
|
22
23
|
QUERY_PATH = '/contacts/v1/search/query'
|
23
24
|
|
@@ -33,11 +34,15 @@ module Hubspot
|
|
33
34
|
|
34
35
|
# {https://developers.hubspot.com/docs/methods/contacts/get_contacts}
|
35
36
|
# {https://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts}
|
37
|
+
# {https://developers.hubspot.com/docs/methods/contacts/get_recently_created_contacts}
|
36
38
|
def all(opts={})
|
37
39
|
recent = opts.delete(:recent) { false }
|
40
|
+
recent_created = opts.delete(:recent_created) { false }
|
38
41
|
paged = opts.delete(:paged) { false }
|
39
42
|
path, opts =
|
40
|
-
if
|
43
|
+
if recent_created
|
44
|
+
[RECENTLY_CREATED_PATH, Hubspot::ContactProperties.add_default_parameters(opts)]
|
45
|
+
elsif recent
|
41
46
|
[RECENTLY_UPDATED_PATH, Hubspot::ContactProperties.add_default_parameters(opts)]
|
42
47
|
else
|
43
48
|
[CONTACTS_PATH, opts]
|
data/lib/hubspot/properties.rb
CHANGED
@@ -5,7 +5,7 @@ module Hubspot
|
|
5
5
|
group_field_names: %w(name displayName displayOrder properties),
|
6
6
|
field_names: %w(name groupName description fieldType formField type displayOrder label options showCurrencySymbol),
|
7
7
|
valid_field_types: %w(textarea select text date file number radio checkbox booleancheckbox),
|
8
|
-
valid_types: %w(string number bool datetime enumeration),
|
8
|
+
valid_types: %w(string number bool date datetime enumeration),
|
9
9
|
options: %w(description value label hidden displayOrder)
|
10
10
|
}
|
11
11
|
DEFAULT_PROPERTY = 'email'
|
@@ -62,17 +62,41 @@ describe Hubspot::Contact do
|
|
62
62
|
describe ".find_by_domain" do
|
63
63
|
context 'given a domain' do
|
64
64
|
cassette "company_find_by_domain"
|
65
|
-
subject{ Hubspot::Company.find_by_domain("
|
65
|
+
subject(:companies) { Hubspot::Company.find_by_domain("example.com") }
|
66
66
|
|
67
67
|
context "when a company is found" do
|
68
|
-
it{ should be_an_instance_of Array }
|
69
|
-
it{ should_not be_empty }
|
68
|
+
it { should be_an_instance_of Array }
|
69
|
+
it { should_not be_empty }
|
70
|
+
|
71
|
+
it 'must contain all available properties' do
|
72
|
+
companies[0..9].each do |company|
|
73
|
+
expect(company.properties).to eql Hubspot::Company.find_by_id(company.vid).properties
|
74
|
+
end
|
75
|
+
end
|
70
76
|
end
|
71
77
|
|
72
78
|
context "when a company cannot be found" do
|
73
|
-
subject{Hubspot::Company.find_by_domain("asdf1234baddomain.com")}
|
79
|
+
subject { Hubspot::Company.find_by_domain("asdf1234baddomain.com") }
|
80
|
+
it { should be_an_instance_of Array }
|
81
|
+
it { should be_empty }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'given a domain and parameters' do
|
86
|
+
cassette 'company_find_by_domain_with_params'
|
87
|
+
subject(:companies) { Hubspot::Company.find_by_domain("example.com", limit: 2, properties: ["name", "createdate"], offset_company_id: 117004411) }
|
88
|
+
|
89
|
+
context "when a company is found" do
|
74
90
|
it{ should be_an_instance_of Array }
|
75
|
-
it{
|
91
|
+
it{ should_not be_empty }
|
92
|
+
|
93
|
+
it 'must use the parameters to search' do
|
94
|
+
expect(companies.size).to eql 2
|
95
|
+
expect(companies.first['name']).to be_a_kind_of String
|
96
|
+
expect(companies.first['createdate']).to be_a_kind_of String
|
97
|
+
expect(companies.first['domain']).to be_nil
|
98
|
+
expect(companies.first['hs_lastmodifieddate']).to be_nil
|
99
|
+
end
|
76
100
|
end
|
77
101
|
end
|
78
102
|
end
|
@@ -318,6 +318,22 @@ describe Hubspot::Contact do
|
|
318
318
|
expect(last.vid).to eql 263776
|
319
319
|
end
|
320
320
|
end
|
321
|
+
|
322
|
+
context 'recent created contacts' do
|
323
|
+
cassette 'find_all_recent_created_contacts'
|
324
|
+
|
325
|
+
it 'must get the contacts list' do
|
326
|
+
contacts = Hubspot::Contact.all(recent_created: true)
|
327
|
+
expect(contacts.size).to eql 20
|
328
|
+
|
329
|
+
first, last = contacts.first, contacts.last
|
330
|
+
expect(first).to be_a Hubspot::Contact
|
331
|
+
expect(first.vid).to eql 5478174
|
332
|
+
|
333
|
+
expect(last).to be_a Hubspot::Contact
|
334
|
+
expect(last.vid).to eql 5476674
|
335
|
+
end
|
336
|
+
end
|
321
337
|
end
|
322
338
|
|
323
339
|
describe '#update!' do
|
@@ -1,7 +1,12 @@
|
|
1
1
|
describe Hubspot::Deal do
|
2
|
+
let(:portal_id) { 62515 }
|
3
|
+
let(:company_id) { 8954037 }
|
4
|
+
let(:vid) { 27136 }
|
5
|
+
let(:amount) { '30' }
|
6
|
+
|
2
7
|
let(:example_deal_hash) do
|
3
8
|
VCR.use_cassette("deal_example") do
|
4
|
-
HTTParty.get("https://api.hubapi.com/deals/v1/deal/3?hapikey=demo&portalId
|
9
|
+
HTTParty.get("https://api.hubapi.com/deals/v1/deal/3?hapikey=demo&portalId=#{portal_id}").parsed_response
|
5
10
|
end
|
6
11
|
end
|
7
12
|
|
@@ -10,27 +15,39 @@ describe Hubspot::Deal do
|
|
10
15
|
describe "#initialize" do
|
11
16
|
subject{ Hubspot::Deal.new(example_deal_hash) }
|
12
17
|
it { should be_an_instance_of Hubspot::Deal }
|
13
|
-
its (:portal_id) { should ==
|
18
|
+
its (:portal_id) { should == portal_id }
|
14
19
|
its (:deal_id) { should == 3 }
|
15
20
|
end
|
16
21
|
|
17
22
|
describe ".create!" do
|
18
23
|
cassette "deal_create"
|
19
|
-
subject { Hubspot::Deal.create!(
|
24
|
+
subject { Hubspot::Deal.create!(portal_id, [company_id], [vid], {}) }
|
20
25
|
its(:deal_id) { should_not be_nil }
|
21
|
-
its(:portal_id) { should eql
|
22
|
-
its(:company_ids) { should eql [
|
23
|
-
its(:vids) { should eql [
|
26
|
+
its(:portal_id) { should eql portal_id }
|
27
|
+
its(:company_ids) { should eql [company_id]}
|
28
|
+
its(:vids) { should eql [vid]}
|
24
29
|
end
|
25
30
|
|
26
31
|
describe ".find" do
|
27
32
|
cassette "deal_find"
|
28
|
-
let(:deal) {Hubspot::Deal.create!(
|
33
|
+
let(:deal) {Hubspot::Deal.create!(portal_id, [company_id], [vid], { amount: amount})}
|
29
34
|
|
30
35
|
it 'must find by the deal id' do
|
31
36
|
find_deal = Hubspot::Deal.find(deal.deal_id)
|
32
37
|
find_deal.deal_id.should eql deal.deal_id
|
33
|
-
find_deal.properties["amount"].should eql
|
38
|
+
find_deal.properties["amount"].should eql amount
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.find_by_company' do
|
43
|
+
cassette 'deal_find_by_company'
|
44
|
+
let(:company) { Hubspot::Company.create!('Test Company') }
|
45
|
+
let(:deal) { Hubspot::Deal.create!(portal_id, [company.vid], [vid], { amount: amount }) }
|
46
|
+
|
47
|
+
it 'returns company deals' do
|
48
|
+
deals = Hubspot::Deal.find_by_company(company)
|
49
|
+
deals.first.deal_id.should eql deal.deal_id
|
50
|
+
deals.first.properties['amount'].should eql amount
|
34
51
|
end
|
35
52
|
end
|
36
53
|
|
@@ -68,7 +85,7 @@ describe Hubspot::Deal do
|
|
68
85
|
describe '#destroy!' do
|
69
86
|
cassette 'destroy_deal'
|
70
87
|
|
71
|
-
let(:deal) {Hubspot::Deal.create!(
|
88
|
+
let(:deal) {Hubspot::Deal.create!(portal_id, [company_id], [vid], {amount: amount})}
|
72
89
|
|
73
90
|
it 'should remove from hubspot' do
|
74
91
|
pending
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubspot-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew DiMichele
|
8
|
+
- Chris Bisnett
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2017-
|
12
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
@@ -42,16 +43,16 @@ dependencies:
|
|
42
43
|
name: rake
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - "
|
46
|
+
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
+
version: '11.0'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - "
|
53
|
+
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
+
version: '11.0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rspec
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|