easy_hubspot 0.1.7 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ce154fdb34847454b688c962db16c2d70e1ea51f43f532f630552063fd206c6
4
- data.tar.gz: f8ede8f920e5359db248fb20a4a8e5194fe6f1344a29b720676b03e19f6761b1
3
+ metadata.gz: 10948cb420b0963c35938bdfbc87c017236894bcdb5072ee32e0be6c7e67b313
4
+ data.tar.gz: 3a4c3668452becd0bada81aa3c9e270606e3d5c7e4347fd9e614d36da27e8234
5
5
  SHA512:
6
- metadata.gz: 303dbdc024cff0b52bbfd372987cbf83ee7b61d014d0bab2407a47c618e664632c69a2e1031f7a9cfa496ae359b3044b349691c6b4d654a1faa4b97d2c8e39b2
7
- data.tar.gz: ded9e8f4717f948498b3b2d5b2e7276057edd51ca7f61d897d079802cf2a3fb1584015ff98d0f233e6c0d68e992a5076a987a06e127187aa8a7debd6c8a12ec6
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,15 @@
1
- ## [Unreleased]
1
+ ## [Official Release]
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
2
5
 
3
- ## [0.1.0] - 2023-02-08
6
+ ## [Unreleased]
4
7
 
5
- - Initial release
8
+ ## [Initial releases]
9
+ - [0.1.0] - 2023-02-08
10
+ - [0.1.1] - 2023-02-09
11
+ - [0.1.2] - 2023-02-09
12
+ - [0.1.3] - 2023-02-09
13
+ - [0.1.4] - 2023-02-09
14
+ - [0.1.5] - 2023-02-09
15
+ - [0.1.6] - 2023-02-09
data/README.md CHANGED
@@ -1,11 +1,20 @@
1
1
  # EasyHubspot
2
- ![version](https://img.shields.io/badge/version-0.1.6-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
 
6
- Work in progress: This gem is not ready for production use.
7
+ This is a lightweight wrapper for the Hubspot API. It is designed to be easy to use and to provide a simple setup for the most common use cases.
8
+
9
+ This gem utilizes the `v3` hubspot-api
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`
7
17
 
8
- This is a lightweight wrapper for the Hubspot API. It is designed to be easy to use and to provide a simple interface for the most common use cases.
9
18
  ## Installation
10
19
 
11
20
  Add this line to your application's Gemfile:
@@ -33,25 +42,77 @@ rails g easy_hubspot:install
33
42
 
34
43
  ### Contacts
35
44
 
45
+ Please refrence the [hubspot docs](https://developers.hubspot.com/docs/api/crm/contacts)
46
+
36
47
  ```ruby
37
- # Create a contact
38
- 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: ''})
39
52
 
40
- # Update a contact
41
- 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: ''})
42
58
 
43
59
  # Get a contact
44
- 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)
45
64
  # or
46
- EasyHubspot::Contact.get_contact('test@gmail.com')
65
+ EasyHubspot::Contact.get_contact('test@gmail.com')
47
66
 
48
- # Get all contacts
49
- EasyHubspot::Contact.get_contacts
67
+ # Get all contacts
68
+ # returns: parsed hubspot contacts
69
+ EasyHubspot::Contact.get_contacts
50
70
 
51
- # Delete a contact
52
- 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)
53
76
  # or
54
- 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
55
116
  ```
56
117
 
57
118
  ## Development
@@ -25,15 +25,20 @@ 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?
37
+
38
+ parsed_res = JSON.parse res, symbolize_names: true
39
+ raise EasyHubspot::HubspotApiError, parsed_res[:message] if parsed_res[:status] == 'error'
35
40
 
36
- JSON.parse res, symbolize_names: true
41
+ parsed_res
37
42
  end
38
43
  end
39
44
  end
@@ -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
 
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasyHubspot
4
+ class Error < StandardError; end
5
+ class HubspotApiError < Error; end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyHubspot
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.9'
5
5
  end
data/lib/easy_hubspot.rb CHANGED
@@ -5,6 +5,7 @@ require 'easy_hubspot/client'
5
5
  require 'easy_hubspot/contact'
6
6
  require 'easy_hubspot/version'
7
7
  require 'easy_hubspot/generators/install_generator'
8
+ require 'easy_hubspot/exceptions'
8
9
 
9
10
  require 'httparty'
10
11
  require 'json'
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.7
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
@@ -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/exceptions.rb
187
188
  - lib/easy_hubspot/generators/install_generator.rb
188
189
  - lib/easy_hubspot/generators/templates/easy_hubspot.rb
189
190
  - lib/easy_hubspot/version.rb