easy_hubspot 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -1
- data/CHANGELOG.md +2 -0
- data/README.md +70 -12
- data/lib/easy_hubspot/client.rb +4 -2
- data/lib/easy_hubspot/contact.rb +8 -5
- data/lib/easy_hubspot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10948cb420b0963c35938bdfbc87c017236894bcdb5072ee32e0be6c7e67b313
|
4
|
+
data.tar.gz: 3a4c3668452becd0bada81aa3c9e270606e3d5c7e4347fd9e614d36da27e8234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28470604e252338702a3fd8f8d64bf3c15bdd438032dd1b894a8dc88469aaac423e8fc26c8c7ab75605f934e4a57a7c03ea39ac9852da98d3db6d7a12136d020
|
7
|
+
data.tar.gz: fe41f9081b7534da09bf8e425e9c9fa7f60beb0c870f3aec52ad649d5f4bf8ceb2361b7644c03fb79efb964b87d4d8afa0ee527cdd7cfc0fcd42e19fac52b19f
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# EasyHubspot
|
2
|
-
![version](https://img.shields.io/badge/version-0.1.
|
2
|
+
Stable: ![stable version](https://img.shields.io/badge/version-0.1.8-green)
|
3
|
+
Latest: ![latest version](https://img.shields.io/badge/version-0.1.9-yellow)
|
3
4
|
[![CI](https://github.com/oroth8/easy_hubspot/actions/workflows/ci.yml/badge.svg)](https://github.com/oroth8/easy_hubspot/actions/workflows/ci.yml)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/oroth8/easy_hubspot/badges/gpa.svg)](https://codeclimate.com/github/oroth8/easy_hubspot)
|
5
6
|
|
@@ -7,6 +8,13 @@ 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
|
+
### Dependencies
|
12
|
+
- [gem "httparty", "~> 0.21.0"](https://github.com/jnunemaker/httparty)
|
13
|
+
|
14
|
+
### Compatibility
|
15
|
+
- `ruby >= 2.6.10`
|
16
|
+
- `rails >= 6.0`
|
17
|
+
|
10
18
|
## Installation
|
11
19
|
|
12
20
|
Add this line to your application's Gemfile:
|
@@ -37,24 +45,74 @@ rails g easy_hubspot:install
|
|
37
45
|
Please refrence the [hubspot docs](https://developers.hubspot.com/docs/api/crm/contacts)
|
38
46
|
|
39
47
|
```ruby
|
40
|
-
# Create a contact
|
41
|
-
|
48
|
+
# Create a contact
|
49
|
+
# required: body
|
50
|
+
# returns: parsed hubspot contact
|
51
|
+
EasyHubspot::Contact.create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})
|
42
52
|
|
43
|
-
# Update a contact
|
44
|
-
|
53
|
+
# Update a contact
|
54
|
+
# required: contact_id, body
|
55
|
+
# - contact_id: can be a hubspot contact_id or email
|
56
|
+
# returns: parsed hubspot contact
|
57
|
+
EasyHubspot::Contact.update_contact(123, properties: { email: '', firstname: '', lastname: '' , etc: ''})
|
45
58
|
|
46
59
|
# Get a contact
|
47
|
-
|
60
|
+
# required: contact_id
|
61
|
+
# - contact_id: can be a hubspot contact_id or email
|
62
|
+
# returns: parsed hubspot contact
|
63
|
+
EasyHubspot::Contact.get_contact(123)
|
48
64
|
# or
|
49
|
-
EasyHubspot::Contact.get_contact('test@gmail.com')
|
65
|
+
EasyHubspot::Contact.get_contact('test@gmail.com')
|
50
66
|
|
51
|
-
# Get all contacts
|
52
|
-
|
67
|
+
# Get all contacts
|
68
|
+
# returns: parsed hubspot contacts
|
69
|
+
EasyHubspot::Contact.get_contacts
|
53
70
|
|
54
|
-
# Delete a contact
|
55
|
-
|
71
|
+
# Delete a contact
|
72
|
+
# required: contact_id
|
73
|
+
# - contact_id: can be a hubspot contact_id or email
|
74
|
+
# returns: {status: 'success'}
|
75
|
+
EasyHubspot::Contact.delete_contact(123)
|
56
76
|
# or
|
57
|
-
EasyHubspot::Contact.delete_contact('test@gmail.com')
|
77
|
+
EasyHubspot::Contact.delete_contact('test@gmail.com')
|
78
|
+
|
79
|
+
# Update or Create a contact
|
80
|
+
# required: email, body
|
81
|
+
# returns: parsed hubspot contact
|
82
|
+
EasyHubspot::Contact.update_or_create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})
|
83
|
+
|
84
|
+
|
85
|
+
# Parse hubspot contact example
|
86
|
+
{:id=>"701",
|
87
|
+
:properties=>
|
88
|
+
{:createdate=>"2023-02-08T20:10:36.858Z",
|
89
|
+
:email=>"amber_becker@quigley.io",
|
90
|
+
:firstname=>"Amber",
|
91
|
+
:hs_content_membership_status=>"inactive",
|
92
|
+
:hs_is_contact=>"true",
|
93
|
+
:hs_is_unworked=>"true",
|
94
|
+
:hs_object_id=>"701",
|
95
|
+
:hs_pipeline=>"contacts-lifecycle-pipeline",
|
96
|
+
:lastmodifieddate=>"2023-02-14T18:24:07.654Z",
|
97
|
+
:lastname=>"Quigley",
|
98
|
+
:lifecyclestage=>"lead"},
|
99
|
+
:createdAt=>"2023-02-08T20:10:36.858Z",
|
100
|
+
:updatedAt=>"2023-02-14T18:24:07.654Z",
|
101
|
+
:archived=>false}
|
102
|
+
```
|
103
|
+
|
104
|
+
## Error Handling
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
def call
|
108
|
+
begin
|
109
|
+
EasyHubspot::Contact.create_contact(body)
|
110
|
+
rescue EasyHubspot::HubspotApiError => e
|
111
|
+
# handle error code
|
112
|
+
# e.message = 'Contact already exists. Existing ID: 801'
|
113
|
+
Rails.logger.info(e.message)
|
114
|
+
end
|
115
|
+
end
|
58
116
|
```
|
59
117
|
|
60
118
|
## 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
|
|
data/lib/easy_hubspot/version.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.9
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|