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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8afd7c12ba165b752df83f2a711ad3220f0efb7f9fef8a73340ae9dd9c95adeb
4
- data.tar.gz: dcd135320a2274849e576f7b2c5497a74323c1713b330f275c6c4f6dfa3cedef
3
+ metadata.gz: e3bedf368c82ea90f5c0b8762a73b85e8ffb612b6cdc12fb1675aa37e988ca59
4
+ data.tar.gz: 4886a66107567facb93da095cc9025b26c47d433757213adb2aa67823a7ead9f
5
5
  SHA512:
6
- metadata.gz: 4b5da8b90ae02f92056d2af35dea0cbbe8207e84d486345dd89fd7d155b75a13680b735788f2e4b64ba3c9acc617830c8fe29feb3a5b3156c5ceb3cab3b2f724
7
- data.tar.gz: c90fb31a0954a82c9bdfbf7c3b0c5df4fde0e4f5c40da12fa09f32afad0f8ca5c7679ae561ca52196b016bebf06bcdeb93edb6d14c57ed354b99b2faf5a75f95
6
+ metadata.gz: c99f809956ec2c4432941218fafc0f52b6ecccd27f0a34c47f18f5b7dc2c1e6ab676e59ce5ffa2cfbf360570b41076e0ceb561140ccd24b847eb83ee4616950d
7
+ data.tar.gz: 02e13fb5fecc8b6ff01d119482ce6489a8e7064595a9db88848e1157df4b11d052fc242c82391ca8a9a2d0f487b5f6c1f10e742110849f29cd77443ab8560862
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,8 @@
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
5
+ - [0.1.10] - 2023-02-14 https://github.com/oroth8/easy_hubspot/pull/7
3
6
 
4
7
  ## [Unreleased]
5
8
 
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.10-green)
3
+ Latest: ![latest version](https://img.shields.io/badge/version-0.1.10-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,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
- EasyHubspot::Contact.create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})
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
- EasyHubspot::Contact.update_contact(123, properties: { email: '', firstname: '', lastname: '' , etc: ''})
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
- EasyHubspot::Contact.get_contact(123)
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
- EasyHubspot::Contact.get_contacts
73
+ # Get all contacts
74
+ # returns: parsed hubspot contacts
75
+ EasyHubspot::Contact.get_contacts
53
76
 
54
- # Delete a contact
55
- EasyHubspot::Contact.delete_contact(123)
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
@@ -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
 
@@ -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
@@ -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.10'
5
5
  end
data/lib/easy_hubspot.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'easy_hubspot/base'
4
4
  require 'easy_hubspot/client'
5
5
  require 'easy_hubspot/contact'
6
+ require 'easy_hubspot/deal'
6
7
  require 'easy_hubspot/version'
7
8
  require 'easy_hubspot/generators/install_generator'
8
9
  require 'easy_hubspot/exceptions'
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.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-10 00:00:00.000000000 Z
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