Skip to content

Commit 605ddf5

Browse files
authored
0.1.10 Add Deal Object CRUD Methods (#7)
1 parent 47896ff commit 605ddf5

21 files changed

+403
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- [0.1.7] - 2023-02-10
33
- [0.1.8] - 2023-02-10
44
- [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
56

67
## [Unreleased]
78

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# EasyHubspot
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)
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)
44
[![CI](https://github.com/oroth8/easy_hubspot/actions/workflows/ci.yml/badge.svg)](https://github.com/oroth8/easy_hubspot/actions/workflows/ci.yml)
55
[![Code Climate](https://codeclimate.com/github/oroth8/easy_hubspot/badges/gpa.svg)](https://codeclimate.com/github/oroth8/easy_hubspot)
66

77
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.
88

99
This gem utilizes the `v3` hubspot-api
1010

11+
## CRM Objects
12+
- [Contacts](#contacts)
13+
- [Deals](#deals)
14+
15+
- [Error Handling](#error-handling)
16+
1117
### Dependencies
1218
- [gem "httparty", "~> 0.21.0"](https://github.com/jnunemaker/httparty)
1319

@@ -101,6 +107,36 @@ Please refrence the [hubspot docs](https://developers.hubspot.com/docs/api/crm/c
101107
:archived=>false}
102108
```
103109

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+
104140
## Error Handling
105141

106142
```ruby

lib/easy_hubspot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'easy_hubspot/base'
44
require 'easy_hubspot/client'
55
require 'easy_hubspot/contact'
6+
require 'easy_hubspot/deal'
67
require 'easy_hubspot/version'
78
require 'easy_hubspot/generators/install_generator'
89
require 'easy_hubspot/exceptions'

lib/easy_hubspot/deal.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/easy_hubspot/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module EasyHubspot
4-
VERSION = '0.1.9'
4+
VERSION = '0.1.10'
55
end

spec/easy_hubspot/contact_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'User-Agent' => 'Ruby'
2323
}
2424
)
25-
.to_return(status: 200, body: load_json('contact'), headers: {})
25+
.to_return(status: 200, body: load_contact_json('contact'), headers: {})
2626
end
2727

2828
let(:response) { described_class.get_contact('701') }
@@ -45,7 +45,7 @@
4545
'User-Agent' => 'Ruby'
4646
}
4747
)
48-
.to_return(status: 200, body: load_json('contact'), headers: {})
48+
.to_return(status: 200, body: load_contact_json('contact'), headers: {})
4949
end
5050

5151
let(:response) { described_class.get_contact('[email protected]') }
@@ -70,7 +70,7 @@
7070
'User-Agent' => 'Ruby'
7171
}
7272
)
73-
.to_return(status: 200, body: load_json('contacts'), headers: {})
73+
.to_return(status: 200, body: load_contact_json('contacts'), headers: {})
7474
end
7575

7676
let(:response) { described_class.get_contacts }
@@ -95,7 +95,7 @@
9595
'User-Agent' => 'Ruby'
9696
}
9797
)
98-
.to_return(status: 201, body: load_json('create_contact'), headers: {})
98+
.to_return(status: 201, body: load_contact_json('create_contact'), headers: {})
9999
end
100100

101101
let(:body) do
@@ -125,7 +125,7 @@
125125
'User-Agent' => 'Ruby'
126126
}
127127
)
128-
.to_return(status: 200, body: load_json('update_contact'), headers: {})
128+
.to_return(status: 200, body: load_contact_json('update_contact'), headers: {})
129129
end
130130

131131
let(:body) do
@@ -154,7 +154,7 @@
154154
'User-Agent' => 'Ruby'
155155
}
156156
)
157-
.to_return(status: 200, body: load_json('update_contact'), headers: {})
157+
.to_return(status: 200, body: load_contact_json('update_contact'), headers: {})
158158
end
159159

160160
let(:body) do
@@ -233,7 +233,7 @@
233233
'User-Agent' => 'Ruby'
234234
}
235235
)
236-
.to_return(status: 400, body: load_json('duplicate_contact'), headers: {})
236+
.to_return(status: 400, body: load_contact_json('duplicate_contact'), headers: {})
237237
end
238238

239239
let(:body) do
@@ -260,7 +260,7 @@
260260
'User-Agent' => 'Ruby'
261261
}
262262
)
263-
.to_return(status: 400, body: load_json('contact_not_found'), headers: {})
263+
.to_return(status: 400, body: load_contact_json('contact_not_found'), headers: {})
264264
end
265265

266266
let(:body) do
@@ -286,7 +286,7 @@
286286
'User-Agent' => 'Ruby'
287287
}
288288
)
289-
.to_return(status: 404, body: load_json('contact_not_found'), headers: {})
289+
.to_return(status: 404, body: load_contact_json('contact_not_found'), headers: {})
290290
end
291291

292292
let(:response) { described_class.get_contact('4040') }
@@ -316,7 +316,7 @@
316316
'User-Agent' => 'Ruby'
317317
}
318318
)
319-
.to_return(status: 200, body: load_json('contact'), headers: {})
319+
.to_return(status: 200, body: load_contact_json('contact'), headers: {})
320320
stub_request(:patch, 'https://api.hubapi.com/crm/v3/objects/contacts/[email protected]?idProperty=email')
321321
.with(
322322
body: 'properties%5Bemail%5D=amber_becker%40quigley.io&properties%5Bfirstname%5D=Amber&properties%5Blastname%5D=Quigley&properties%5Bhs_content_membership_status%5D=inactive',
@@ -328,11 +328,11 @@
328328
'User-Agent' => 'Ruby'
329329
}
330330
)
331-
.to_return(status: 200, body: load_json('update_or_create_contact'), headers: {})
331+
.to_return(status: 200, body: load_contact_json('update_or_create_contact'), headers: {})
332332
end
333333

334334
it 'updates the contact' do
335-
expect(response).to eq JSON.parse load_json('update_or_create_contact'), symbolize_names: true
335+
expect(response).to eq JSON.parse load_contact_json('update_or_create_contact'), symbolize_names: true
336336
end
337337
end
338338

@@ -366,11 +366,11 @@
366366
'User-Agent' => 'Ruby'
367367
}
368368
)
369-
.to_return(status: 200, body: load_json('update_or_create_post'), headers: {})
369+
.to_return(status: 200, body: load_contact_json('update_or_create_post'), headers: {})
370370
end
371371

372372
it 'creates the contact' do
373-
expect(response).to eq JSON.parse load_json('update_or_create_post'), symbolize_names: true
373+
expect(response).to eq JSON.parse load_contact_json('update_or_create_post'), symbolize_names: true
374374
end
375375
end
376376
end

0 commit comments

Comments
 (0)