Skip to content

Commit 93a1750

Browse files
authored
feat: Add functions to retrieve event payload(s) (#239)
- New functions to retrieve all payloads or a specific payload for a specific event - New unit tests, cassettes - New Payload class, JSON deserialization mapping
1 parent bce2d7f commit 93a1750

File tree

8 files changed

+789
-0
lines changed

8 files changed

+789
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## [Unreleased]
4+
5+
- Added payload functions `retrieve_all_payloads` and `retrieve_payload` to retrieve all payloads or a specific payload for an event.
6+
37
## v4.10.0 (2023-01-11)
48

59
- Added new beta billing functionality for referral customer users, accessible via `EasyPost::Beta::Referral`

lib/easypost.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
require 'easypost/insurance'
2727
require 'easypost/order'
2828
require 'easypost/parcel'
29+
require 'easypost/payload'
2930
require 'easypost/payment_method' # deprecated
3031
require 'easypost/pickup_rate'
3132
require 'easypost/pickup'

lib/easypost/event.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ class EasyPost::Event < EasyPost::Resource
88
def self.receive(values)
99
EasyPost::Util.convert_to_easypost_object(JSON.parse(values), nil)
1010
end
11+
12+
# Retrieve all payloads for an event.
13+
def retrieve_all_payloads(api_key = nil)
14+
response = EasyPost.make_request(:get, "#{url}/payloads", api_key)
15+
EasyPost::Util.convert_to_easypost_object(response, api_key)
16+
end
17+
18+
# Retrieve a specific payload for an event.
19+
def retrieve_payload(payload_id, api_key = nil)
20+
response = EasyPost.make_request(:get, "#{url}/payloads/#{payload_id}", api_key)
21+
EasyPost::Util.convert_to_easypost_object(response, api_key)
22+
end
1123
end

lib/easypost/payload.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
# Webhook Event Payloads are triggered by changes in objects you've created via the API.
4+
class EasyPost::Payload < EasyPost::Resource
5+
end

lib/easypost/util.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module EasyPost::Util
1919
'hook' => EasyPost::Webhook,
2020
'ins' => EasyPost::Insurance,
2121
'order' => EasyPost::Order,
22+
'payload' => EasyPost::Payload,
2223
'pickup' => EasyPost::Pickup,
2324
'pickuprate' => EasyPost::PickupRate,
2425
'pl' => EasyPost::PostageLabel,

0 commit comments

Comments
 (0)