easy_hubspot 0.1.8 → 0.1.10
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/.rubocop.yml +3 -1
- data/CHANGELOG.md +3 -0
- data/README.md +106 -12
- data/lib/easy_hubspot/client.rb +4 -2
- data/lib/easy_hubspot/contact.rb +8 -5
- data/lib/easy_hubspot/deal.rb +36 -0
- data/lib/easy_hubspot/version.rb +1 -1
- data/lib/easy_hubspot.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3bedf368c82ea90f5c0b8762a73b85e8ffb612b6cdc12fb1675aa37e988ca59
|
4
|
+
data.tar.gz: 4886a66107567facb93da095cc9025b26c47d433757213adb2aa67823a7ead9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c99f809956ec2c4432941218fafc0f52b6ecccd27f0a34c47f18f5b7dc2c1e6ab676e59ce5ffa2cfbf360570b41076e0ceb561140ccd24b847eb83ee4616950d
|
7
|
+
data.tar.gz: 02e13fb5fecc8b6ff01d119482ce6489a8e7064595a9db88848e1157df4b11d052fc242c82391ca8a9a2d0f487b5f6c1f10e742110849f29cd77443ab8560862
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# EasyHubspot
|
2
|
-

|
3
|
+
Latest: 
|
3
4
|
[](https://github.com/oroth8/easy_hubspot/actions/workflows/ci.yml)
|
4
5
|
[](https://codeclimate.com/github/oroth8/easy_hubspot)
|
5
6
|
|
@@ -7,6 +8,19 @@ This is a lightweight wrapper for the Hubspot API. It is designed to be easy to
|
|
7
8
|
|
8
9
|
This gem utilizes the `v3` hubspot-api
|
9
10
|
|
11
|
+
## CRM Objects
|
12
|
+
- [Contacts](#contacts)
|
13
|
+
- [Deals](#deals)
|
14
|
+
|
15
|
+
- [Error Handling](#error-handling)
|
16
|
+
|
17
|
+
### Dependencies
|
18
|
+
- [gem "httparty", "~> 0.21.0"](https://github.com/jnunemaker/httparty)
|
19
|
+
|
20
|
+
### Compatibility
|
21
|
+
- `ruby >= 2.6.10`
|
22
|
+
- `rails >= 6.0`
|
23
|
+
|
10
24
|
## Installation
|
11
25
|
|
12
26
|
Add this line to your application's Gemfile:
|
@@ -37,24 +51,104 @@ rails g easy_hubspot:install
|
|
37
51
|
Please refrence the [hubspot docs](https://developers.hubspot.com/docs/api/crm/contacts)
|
38
52
|
|
39
53
|
```ruby
|
40
|
-
# Create a contact
|
41
|
-
|
54
|
+
# Create a contact
|
55
|
+
# required: body
|
56
|
+
# returns: parsed hubspot contact
|
57
|
+
EasyHubspot::Contact.create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})
|
42
58
|
|
43
|
-
# Update a contact
|
44
|
-
|
59
|
+
# Update a contact
|
60
|
+
# required: contact_id, body
|
61
|
+
# - contact_id: can be a hubspot contact_id or email
|
62
|
+
# returns: parsed hubspot contact
|
63
|
+
EasyHubspot::Contact.update_contact(123, properties: { email: '', firstname: '', lastname: '' , etc: ''})
|
45
64
|
|
46
65
|
# Get a contact
|
47
|
-
|
66
|
+
# required: contact_id
|
67
|
+
# - contact_id: can be a hubspot contact_id or email
|
68
|
+
# returns: parsed hubspot contact
|
69
|
+
EasyHubspot::Contact.get_contact(123)
|
48
70
|
# or
|
49
|
-
EasyHubspot::Contact.get_contact('test@gmail.com')
|
71
|
+
EasyHubspot::Contact.get_contact('test@gmail.com')
|
50
72
|
|
51
|
-
# Get all contacts
|
52
|
-
|
73
|
+
# Get all contacts
|
74
|
+
# returns: parsed hubspot contacts
|
75
|
+
EasyHubspot::Contact.get_contacts
|
53
76
|
|
54
|
-
# Delete a contact
|
55
|
-
|
77
|
+
# Delete a contact
|
78
|
+
# required: contact_id
|
79
|
+
# - contact_id: can be a hubspot contact_id or email
|
80
|
+
# returns: {status: 'success'}
|
81
|
+
EasyHubspot::Contact.delete_contact(123)
|
56
82
|
# or
|
57
|
-
EasyHubspot::Contact.delete_contact('test@gmail.com')
|
83
|
+
EasyHubspot::Contact.delete_contact('test@gmail.com')
|
84
|
+
|
85
|
+
# Update or Create a contact
|
86
|
+
# required: email, body
|
87
|
+
# returns: parsed hubspot contact
|
88
|
+
EasyHubspot::Contact.update_or_create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})
|
89
|
+
|
90
|
+
|
91
|
+
# Parse hubspot contact example
|
92
|
+
{:id=>"701",
|
93
|
+
:properties=>
|
94
|
+
{:createdate=>"2023-02-08T20:10:36.858Z",
|
95
|
+
:email=>"amber_becker@quigley.io",
|
96
|
+
:firstname=>"Amber",
|
97
|
+
:hs_content_membership_status=>"inactive",
|
98
|
+
:hs_is_contact=>"true",
|
99
|
+
:hs_is_unworked=>"true",
|
100
|
+
:hs_object_id=>"701",
|
101
|
+
:hs_pipeline=>"contacts-lifecycle-pipeline",
|
102
|
+
:lastmodifieddate=>"2023-02-14T18:24:07.654Z",
|
103
|
+
:lastname=>"Quigley",
|
104
|
+
:lifecyclestage=>"lead"},
|
105
|
+
:createdAt=>"2023-02-08T20:10:36.858Z",
|
106
|
+
:updatedAt=>"2023-02-14T18:24:07.654Z",
|
107
|
+
:archived=>false}
|
108
|
+
```
|
109
|
+
|
110
|
+
### Deals
|
111
|
+
```ruby
|
112
|
+
# Create a deal
|
113
|
+
# required: body
|
114
|
+
# returns: parsed hubspot deal
|
115
|
+
EasyHubspot::Deal.create_deal(properties: { dealname: '', amount: '', etc: ''})
|
116
|
+
|
117
|
+
# Update a deal
|
118
|
+
# required: deal_id, body
|
119
|
+
# - deal_id: must be a hubspot deal_id
|
120
|
+
# returns: parsed hubspot deal
|
121
|
+
EasyHubspot::Deal.update_deal(123, properties: { dealname: '', amount: '', etc: ''})
|
122
|
+
|
123
|
+
# Get a deal
|
124
|
+
# required: deal_id
|
125
|
+
# - deal_id: must be a hubspot deal_id
|
126
|
+
# returns: parsed hubspot deal
|
127
|
+
EasyHubspot::Deal.get_deal(123)
|
128
|
+
|
129
|
+
# Get all deals
|
130
|
+
# returns: parsed hubspot deals
|
131
|
+
EasyHubspot::Deal.get_deals
|
132
|
+
|
133
|
+
# Delete a deal
|
134
|
+
# required: deal_id
|
135
|
+
# - deal_id: must be a hubspot deal_id
|
136
|
+
# returns: {status: 'success'}
|
137
|
+
EasyHubspot::Deal.delete_deal(123)
|
138
|
+
```
|
139
|
+
|
140
|
+
## Error Handling
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
def call
|
144
|
+
begin
|
145
|
+
EasyHubspot::Contact.create_contact(body)
|
146
|
+
rescue EasyHubspot::HubspotApiError => e
|
147
|
+
# handle error code
|
148
|
+
# e.message = 'Contact already exists. Existing ID: 801'
|
149
|
+
Rails.logger.info(e.message)
|
150
|
+
end
|
151
|
+
end
|
58
152
|
```
|
59
153
|
|
60
154
|
## Development
|
data/lib/easy_hubspot/client.rb
CHANGED
@@ -25,13 +25,15 @@ module EasyHubspot
|
|
25
25
|
def do_delete(path = nil, headers = {})
|
26
26
|
response = HTTParty.delete("#{EasyHubspot.configuration.base_url}#{path}", headers: headers,
|
27
27
|
format: :plain)
|
28
|
-
parse_response(response)
|
28
|
+
parse_response(response).nil? ? { status: 'success' } : parse_response(response)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def parse_response(res)
|
34
|
-
return if res.
|
34
|
+
return { status: 'error', message: '404 Not Found' } if res.code == 404
|
35
|
+
|
36
|
+
return if res.body.nil? || res.body.empty?
|
35
37
|
|
36
38
|
parsed_res = JSON.parse res, symbolize_names: true
|
37
39
|
raise EasyHubspot::HubspotApiError, parsed_res[:message] if parsed_res[:status] == 'error'
|
data/lib/easy_hubspot/contact.rb
CHANGED
@@ -26,11 +26,14 @@ module EasyHubspot
|
|
26
26
|
Client.do_delete(determine_endpoint(contact_id), headers)
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def update_or_create_contact(email, body)
|
30
|
+
res = get_contact(email)
|
31
|
+
if res && res[:id]
|
32
|
+
update_contact(email, body)
|
33
|
+
else
|
34
|
+
create_contact(body)
|
35
|
+
end
|
36
|
+
end
|
34
37
|
|
35
38
|
private
|
36
39
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EasyHubspot
|
4
|
+
# class EasyHubspot::deal
|
5
|
+
class Deal < EasyHubspot::Base
|
6
|
+
class << self
|
7
|
+
DEAL_ENDPOINT = 'crm/v3/objects/deals'
|
8
|
+
|
9
|
+
def get_deal(deal_id)
|
10
|
+
Client.do_get(deal_id_endpoint(deal_id), headers)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_deals
|
14
|
+
Client.do_get(DEAL_ENDPOINT, headers)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_deal(body)
|
18
|
+
Client.do_post(DEAL_ENDPOINT, body, headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_deal(deal_id, body)
|
22
|
+
Client.do_patch(deal_id_endpoint(deal_id), body, headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_deal(deal_id)
|
26
|
+
Client.do_delete(deal_id_endpoint(deal_id), headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def deal_id_endpoint(deal_id)
|
32
|
+
"#{DEAL_ENDPOINT}/#{deal_id}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/easy_hubspot/version.rb
CHANGED
data/lib/easy_hubspot.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_hubspot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen Roth
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/easy_hubspot/base.rb
|
185
185
|
- lib/easy_hubspot/client.rb
|
186
186
|
- lib/easy_hubspot/contact.rb
|
187
|
+
- lib/easy_hubspot/deal.rb
|
187
188
|
- lib/easy_hubspot/exceptions.rb
|
188
189
|
- lib/easy_hubspot/generators/install_generator.rb
|
189
190
|
- lib/easy_hubspot/generators/templates/easy_hubspot.rb
|