From 2b752fb8eb3df89f2bc3ba0bcfa2afb0699308ef Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Tue, 17 Jan 2023 10:09:59 -0700 Subject: [PATCH] feat: Add function in retrieve all pickups (#238) - Add (enable) function to retrieve all pickups - Add (enable) unit test to test retrieving all pickups --- CHANGELOG.md | 1 + lib/easypost/pickup.rb | 5 -- ...yPost_Pickup_all_retrieves_all_pickups.yml | 82 +++++++++++++++++++ spec/pickup_spec.rb | 12 ++- 4 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 spec/cassettes/pickup/EasyPost_Pickup_all_retrieves_all_pickups.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index f01b5246..b9838bfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- Added function to retrieve all pickups, accessible via `EasyPost::Pickup.all` - Added payload functions `retrieve_all_payloads` and `retrieve_payload` to retrieve all payloads or a specific payload for an event. ## v4.10.0 (2023-01-11) diff --git a/lib/easypost/pickup.rb b/lib/easypost/pickup.rb index 2f12b7e5..602a6290 100644 --- a/lib/easypost/pickup.rb +++ b/lib/easypost/pickup.rb @@ -25,11 +25,6 @@ def cancel(params = {}) self end - # Retrieve a list of all Pickup objects. - def self.all(_filters = {}, _api_key = nil) - raise NotImplementedError.new('Pickup.all not implemented.') - end - # Get the lowest rate of a Pickup (can exclude by having `'!'` as the first element of your optional filter lists). def lowest_rate(carriers = [], services = []) EasyPost::Util.get_lowest_object_rate(self, carriers, services, 'pickup_rates') diff --git a/spec/cassettes/pickup/EasyPost_Pickup_all_retrieves_all_pickups.yml b/spec/cassettes/pickup/EasyPost_Pickup_all_retrieves_all_pickups.yml new file mode 100644 index 00000000..1bd405a7 --- /dev/null +++ b/spec/cassettes/pickup/EasyPost_Pickup_all_retrieves_all_pickups.yml @@ -0,0 +1,82 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.easypost.com/v2/pickups + body: + encoding: UTF-8 + string: '{"page_size":5}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: "" + Content-Type: + - application/json + Authorization: "" + response: + status: + code: 200 + message: OK + headers: + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + X-Ep-Request-Uuid: + - 479fb94963c1b305e78bb04d00070ae0 + Cache-Control: + - private, no-cache, no-store + Pragma: + - no-cache + Expires: + - '0' + Content-Type: + - application/json; charset=utf-8 + Etag: + - W/"132f0b6fecbdf9cbd6a2fc218ec08982" + X-Runtime: + - '0.077629' + Transfer-Encoding: + - chunked + X-Node: + - bigweb6nuq + X-Version-Label: + - easypost-202301131832-957dabd382-master + X-Backend: + - easypost + X-Proxied: + - extlb4wdc 29913d444b + - intlb1nuq 29913d444b + - intlb1wdc 29913d444b + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + body: + encoding: UTF-8 + string: '{"pickups":[{"id":"pickup_df75bf159ec74873899659d69718a7bd","object":"Pickup","created_at":"2022-09-28T04:40:45Z","updated_at":"2022-09-28T04:40:47Z","mode":"test","status":"scheduled","reference":null,"min_datetime":"2022-09-29T00:00:00Z","max_datetime":"2022-09-29T00:00:00Z","is_account_address":false,"instructions":"Pickup + at front door","messages":[],"confirmation":"WTC62239086","address":{"id":"adr_b795ddfb3ee711edbd09ac1f6bc7b362","object":"Address","created_at":"2022-09-28T04:40:45+00:00","updated_at":"2022-09-28T04:40:45+00:00","name":"Jack + Sparrow","company":null,"street1":"388 Townsend St","street2":"Apt 20","city":"San + Francisco","state":"CA","zip":"94107","country":"US","phone":"","email":"","mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"carrier_accounts":[],"pickup_rates":[{"mode":"test","service":"NextDay","rate":"0.00","currency":"USD","created_at":"2022-09-28T04:40:46Z","updated_at":"2022-09-28T04:40:46Z","carrier":"USPS","pickup_id":"pickup_df75bf159ec74873899659d69718a7bd","id":"pickuprate_086e9e6249894e13b512342092028f76","object":"PickupRate"}]},{"id":"pickup_5b954df5448f41b39ab7095abc8d40ab","object":"Pickup","created_at":"2022-09-28T04:39:29Z","updated_at":"2022-09-28T04:39:29Z","mode":"test","status":"unknown","reference":null,"min_datetime":"2022-09-29T00:00:00Z","max_datetime":"2022-09-29T00:00:00Z","is_account_address":false,"instructions":"Pickup + at front door","messages":[],"confirmation":null,"address":{"id":"adr_89ee242d3ee711edb87fac1f6bc72124","object":"Address","created_at":"2022-09-28T04:39:29+00:00","updated_at":"2022-09-28T04:39:29+00:00","name":"Jack + Sparrow","company":null,"street1":"388 Townsend St","street2":"Apt 20","city":"San + Francisco","state":"CA","zip":"94107","country":"US","phone":"","email":"","mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"carrier_accounts":[],"pickup_rates":[{"mode":"test","service":"NextDay","rate":"0.00","currency":"USD","created_at":"2022-09-28T04:39:29Z","updated_at":"2022-09-28T04:39:29Z","carrier":"USPS","pickup_id":"pickup_5b954df5448f41b39ab7095abc8d40ab","id":"pickuprate_65566341b2804ae29cda686082e9888f","object":"PickupRate"}]},{"id":"pickup_1d43a620f8da436c996bdfa47e136023","object":"Pickup","created_at":"2022-09-28T04:39:24Z","updated_at":"2022-09-28T04:39:27Z","mode":"test","status":"canceled","reference":null,"min_datetime":"2022-09-29T00:00:00Z","max_datetime":"2022-09-29T00:00:00Z","is_account_address":false,"instructions":"Pickup + at front door","messages":[],"confirmation":"WTC62239100","address":{"id":"adr_86fa34543ee711ed869eac1f6bc7bdc6","object":"Address","created_at":"2022-09-28T04:39:24+00:00","updated_at":"2022-09-28T04:39:24+00:00","name":"Jack + Sparrow","company":null,"street1":"388 Townsend St","street2":"Apt 20","city":"San + Francisco","state":"CA","zip":"94107","country":"US","phone":"","email":"","mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"carrier_accounts":[],"pickup_rates":[{"mode":"test","service":"NextDay","rate":"0.00","currency":"USD","created_at":"2022-09-28T04:39:24Z","updated_at":"2022-09-28T04:39:24Z","carrier":"USPS","pickup_id":"pickup_1d43a620f8da436c996bdfa47e136023","id":"pickuprate_41e5deef77de4ac6b6c9e30a0af05404","object":"PickupRate"}]},{"id":"pickup_a3e0756baea946799146ccdae1b2be36","object":"Pickup","created_at":"2022-09-28T04:39:20Z","updated_at":"2022-09-28T04:39:22Z","mode":"test","status":"scheduled","reference":null,"min_datetime":"2022-09-29T00:00:00Z","max_datetime":"2022-09-29T00:00:00Z","is_account_address":false,"instructions":"Pickup + at front door","messages":[],"confirmation":"WTC62239084","address":{"id":"adr_84c79f173ee711ed8043ac1f6bc7bdc6","object":"Address","created_at":"2022-09-28T04:39:20+00:00","updated_at":"2022-09-28T04:39:20+00:00","name":"Jack + Sparrow","company":null,"street1":"388 Townsend St","street2":"Apt 20","city":"San + Francisco","state":"CA","zip":"94107","country":"US","phone":"","email":"","mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"carrier_accounts":[],"pickup_rates":[{"mode":"test","service":"NextDay","rate":"0.00","currency":"USD","created_at":"2022-09-28T04:39:21Z","updated_at":"2022-09-28T04:39:21Z","carrier":"USPS","pickup_id":"pickup_a3e0756baea946799146ccdae1b2be36","id":"pickuprate_a27b8255526e4f1d8b93c14e702f3fb8","object":"PickupRate"}]},{"id":"pickup_f5ba2f49d7a14ef3988f781af755e54f","object":"Pickup","created_at":"2022-09-28T04:39:15Z","updated_at":"2022-09-28T04:39:17Z","mode":"test","status":"scheduled","reference":null,"min_datetime":"2022-09-29T00:00:00Z","max_datetime":"2022-09-29T00:00:00Z","is_account_address":false,"instructions":"Pickup + at front door","messages":[],"confirmation":"WTC62239082","address":{"id":"adr_81e688f73ee711ed90c4ac1f6bc72124","object":"Address","created_at":"2022-09-28T04:39:15+00:00","updated_at":"2022-09-28T04:39:15+00:00","name":"Jack + Sparrow","company":null,"street1":"388 Townsend St","street2":"Apt 20","city":"San + Francisco","state":"CA","zip":"94107","country":"US","phone":"","email":"","mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"carrier_accounts":[],"pickup_rates":[{"mode":"test","service":"NextDay","rate":"0.00","currency":"USD","created_at":"2022-09-28T04:39:16Z","updated_at":"2022-09-28T04:39:16Z","carrier":"USPS","pickup_id":"pickup_f5ba2f49d7a14ef3988f781af755e54f","id":"pickuprate_8225032ad74d4fd797f0a0af75110821","object":"PickupRate"}]}],"has_more":true}' + recorded_at: Fri, 13 Jan 2023 19:37:41 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/pickup_spec.rb b/spec/pickup_spec.rb index 295c6802..3b1af004 100644 --- a/spec/pickup_spec.rb +++ b/spec/pickup_spec.rb @@ -35,8 +35,16 @@ end describe '.all' do - it 'raises not implemented error' do - expect { described_class.all }.to raise_error(NotImplementedError) + it 'retrieves all pickups' do + pickups = described_class.all( + page_size: Fixture.page_size, + ) + + pickups_array = pickups.pickups + + expect(pickups_array.count).to be <= Fixture.page_size + expect(pickups.has_more).not_to be_nil + expect(pickups_array).to all(be_an_instance_of(described_class)) end end