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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8afd7c12ba165b752df83f2a711ad3220f0efb7f9fef8a73340ae9dd9c95adeb
4
- data.tar.gz: dcd135320a2274849e576f7b2c5497a74323c1713b330f275c6c4f6dfa3cedef
3
+ metadata.gz: 10948cb420b0963c35938bdfbc87c017236894bcdb5072ee32e0be6c7e67b313
4
+ data.tar.gz: 3a4c3668452becd0bada81aa3c9e270606e3d5c7e4347fd9e614d36da27e8234
5
5
  SHA512:
6
- metadata.gz: 4b5da8b90ae02f92056d2af35dea0cbbe8207e84d486345dd89fd7d155b75a13680b735788f2e4b64ba3c9acc617830c8fe29feb3a5b3156c5ceb3cab3b2f724
7
- data.tar.gz: c90fb31a0954a82c9bdfbf7c3b0c5df4fde0e4f5c40da12fa09f32afad0f8ca5c7679ae561ca52196b016bebf06bcdeb93edb6d14c57ed354b99b2faf5a75f95
6
+ metadata.gz: 28470604e252338702a3fd8f8d64bf3c15bdd438032dd1b894a8dc88469aaac423e8fc26c8c7ab75605f934e4a57a7c03ea39ac9852da98d3db6d7a12136d020
7
+ data.tar.gz: fe41f9081b7534da09bf8e425e9c9fa7f60beb0c870f3aec52ad649d5f4bf8ceb2361b7644c03fb79efb964b87d4d8afa0ee527cdd7cfc0fcd42e19fac52b19f
data/.rubocop.yml CHANGED
@@ -15,7 +15,9 @@ Naming/AccessorMethodName:
15
15
  - 'lib/easy_hubspot/client.rb'
16
16
 
17
17
  Layout/LineLength:
18
- Max: 125
18
+ Enabled: true
19
+ Exclude:
20
+ - 'spec/**/*'
19
21
 
20
22
  RSpec/BeforeAfterAll:
21
23
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## [Official Release]
2
2
  - [0.1.7] - 2023-02-10
3
+ - [0.1.8] - 2023-02-10
4
+ - [0.1.9] - 2023-02-14 https://github.com/oroth8/easy_hubspot/pull/6
3
5
 
4
6
  ## [Unreleased]
5
7
 
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # EasyHubspot
2
- ![version](https://img.shields.io/badge/version-0.1.7-green)
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
- EasyHubspot::Contact.create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})
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
- EasyHubspot::Contact.update_contact(123, properties: { email: '', firstname: '', lastname: '' , etc: ''})
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
- EasyHubspot::Contact.get_contact(123)
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
- EasyHubspot::Contact.get_contacts
67
+ # Get all contacts
68
+ # returns: parsed hubspot contacts
69
+ EasyHubspot::Contact.get_contacts
53
70
 
54
- # Delete a contact
55
- EasyHubspot::Contact.delete_contact(123)
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
@@ -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.body.nil?
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'
@@ -26,11 +26,14 @@ module EasyHubspot
26
26
  Client.do_delete(determine_endpoint(contact_id), headers)
27
27
  end
28
28
 
29
- # def get_associated_contacts(contact_id, object_type, object_id, association_id)
30
- # # TODO: Error handling arguments
31
- # path = merge_path("#{CONTACT_ENDPOINT}/#{contact_id}/associations/#{object_type}/#{object_id}/#{association_id}")
32
- # Client.do_get(path, headers)
33
- # end
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyHubspot
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
5
  end
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.8
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-10 00:00:00.000000000 Z
11
+ date: 2023-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty