diff --git a/.rubocop.yml b/.rubocop.yml index 90a1a7d..9bcbbb3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,3 +20,6 @@ Metrics/CyclomaticComplexity: Metrics/MethodLength: Enabled: false + +Metrics/ClassLength: + Max: 200 diff --git a/lib/ruber.rb b/lib/ruber.rb index 9b26a01..9fe3463 100644 --- a/lib/ruber.rb +++ b/lib/ruber.rb @@ -6,6 +6,7 @@ require "ruber/authenticator" require "ruber/request" require "ruber/resources/delivery_resource" +require "ruber/error" # a Ruby wrapper for Uber API module Ruber diff --git a/lib/ruber/error.rb b/lib/ruber/error.rb index 9f48e02..376f207 100644 --- a/lib/ruber/error.rb +++ b/lib/ruber/error.rb @@ -1,5 +1,15 @@ # frozen_string_literal: true module Ruber - class Error < StandardError; end + class Error < StandardError + attr_reader :status, :message, :metadata + + def initialize(msg, body, status) + @message = body[:message] + @metadata = body[:metadata] + @status = status + + super(msg) + end + end end diff --git a/lib/ruber/objects/delivery.rb b/lib/ruber/objects/delivery.rb index a265c3c..c7936ea 100644 --- a/lib/ruber/objects/delivery.rb +++ b/lib/ruber/objects/delivery.rb @@ -2,5 +2,6 @@ module Ruber class Delivery < Object + class ProofOfDelivery < Object; end end end diff --git a/lib/ruber/objects/proof_of_delivery.rb b/lib/ruber/objects/proof_of_delivery.rb new file mode 100644 index 0000000..6f983bb --- /dev/null +++ b/lib/ruber/objects/proof_of_delivery.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Ruber + class ProofOfDelivery < Object + end +end diff --git a/lib/ruber/request.rb b/lib/ruber/request.rb index 6cd658f..e1d71df 100644 --- a/lib/ruber/request.rb +++ b/lib/ruber/request.rb @@ -15,7 +15,7 @@ def get handle_response connection.get(@url) end - def post(body:, headers: {}) + def post(body: {}, headers: {}) handle_response connection.post(@url, body, headers) end @@ -44,25 +44,9 @@ def connection end def handle_response(response) - case response.status - when 400 - raise Error, "Your request was malformed. #{response.body["error"]}" - when 401 - raise Error, "You did not supply valid authentication credentials. #{response.body["error"]}" - when 403 - raise Error, "You are not allowed to perform that action. #{response.body["error"]}" - when 404 - raise Error, "No results were found for your request. #{response.body["error"]}" - when 429 - raise Error, "Your request exceeded the API rate limit. #{response.body["error"]}" - when 500 - raise Error, "We were unable to perform the request due to server-side problems. #{response.body["error"]}" - when 503 - raise Error, - "You have been rate limited for sending more than 20 requests per second. #{response.body["error"]}" - end + return response if response.status == 200 - response + raise Ruber::Error.new(response.body[:message], response.body, response.status) end end end diff --git a/lib/ruber/resources/delivery_resource.rb b/lib/ruber/resources/delivery_resource.rb index ae09557..1bfe3c2 100644 --- a/lib/ruber/resources/delivery_resource.rb +++ b/lib/ruber/resources/delivery_resource.rb @@ -14,6 +14,30 @@ def find(id) Delivery.new response.body end + + def create(params) + response = Request.new("customers/#{Ruber.customer_id}/deliveries").post(body: params) + + Delivery.new response.body + end + + def cancel(id) + response = Request.new("customers/#{Ruber.customer_id}/deliveries/#{id}/cancel").post + + Delivery.new response.body + end + + def update(id, params) + response = Request.new("customers/#{Ruber.customer_id}/deliveries/#{id}").post(body: params) + + Delivery.new response.body + end + + def proof_of_delivery(id, params) + response = Request.new("customers/#{Ruber.customer_id}/deliveries/#{id}/proof_of_delivery").post(body: params) + + Delivery::ProofOfDelivery.new response.body + end end end end diff --git a/test/fixtures/delivery_cancel.json b/test/fixtures/delivery_cancel.json new file mode 100644 index 0000000..68b0324 --- /dev/null +++ b/test/fixtures/delivery_cancel.json @@ -0,0 +1,295 @@ +{ + "id": "del_some_id", + "quote_id": "quote_id", + "complete": false, + "courier": { + "name": "Alex I.", + "rating": 0, + "vehicle_type": "car", + "phone_number": "+16283337630", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "img_href": "https://d1w2poirtb3as9.cloudfront.net/default.jpeg?Expires=1683022587&Signature=SDlYXhlrNUXVibLEi1veShGrVQqn~5cHlDmKHmirytOvtRPLUzMICPLoLXL8vn7XREKo6XmRjYbE~tMeCqBf3Pjyc4OKqsAyukoUr5ew7S9ipbJ-O0PCp5ThZ4j46yZquza1s~qOQISHopH734F17BaNxod9E9QPJJ3phFcrl4COKYSt3qPsn9Y9PQxyKecJ5Sr0RveI5hGqtQR~u2d3EZgXmJxuGUdk26WX-Ho1h3ziIpnIBu6P6upbOtlnxLqn-dG7tl15pnn~bW1w0qAemFUUdqWzzWfjVGLHonDqE4LM5xE~t1T~1zJCNQ-uzijjI6tnEfIHJ9LgWRRhX3sKXQ__&Key-Pair-Id=K36LFL06Z5BT10", + "public_phone_info": { + "formatted_phone_number": "+15555555557,48023618", + "phone_number": "+15555555557", + "pin_code": "48023618" + } + }, + "courier_imminent": true, + "created": "2023-05-01T22:15:13.646Z", + "currency": "usd", + "deliverable_action": "deliverable_action_meet_at_door", + "dropoff": { + "name": "Joan P.", + "phone_number": "+16283337630", + "address": "2200 Market St, San Francisco, CA 94114, US", + "detailed_address": { + "street_address_1": "2200 Market St", + "street_address_2": "", + "city": "San Francisco", + "state": "CA", + "zip_code": "94114", + "country": "US" + }, + "notes": "", + "seller_notes": "", + "courier_notes": "", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "verification": { + "signature": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb", + "name": "Joan", + "signer_relationship": "SELF" + }, + "barcodes": [ + { + "type": "CODE128", + "value": "1234567890", + "scan_result": { + "outcome": "SUCCESS", + "timestamp": "2023-05-02T04:34:04.957Z" + } + } + ], + "picture": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb" + }, + "identification": { + "min_age_verified": false + }, + "pin_code": { + "entered": "3902" + }, + "completion_location": { + "lat": 37.765987, + "lng": -122.43153 + } + }, + "verification_requirements": { + "signature": true, + "signature_requirement": { + "enabled": true, + "collect_signer_name": true, + "collect_signer_relationship": true + }, + "barcodes": [ + { + "value": "string", + "type": "CODE39" + } + ], + "pincode": { + "enabled": true, + "value": "1234" + }, + "identification": { + "min_age": 21, + "no_sobriety_check": true + }, + "picture": true + }, + "status": "completed", + "status_timestamp": "2023-05-02T02:30:07.560Z", + "external_store_id": "my_store_123" + }, + "dropoff_deadline": "2023-05-01T23:01:37.000Z", + "dropoff_eta": "2023-05-01T22:30:00.077Z", + "dropoff_identifier": "", + "dropoff_ready": "2023-05-01T22:15:13.000Z", + "external_id": "EI000001", + "fee": 1099, + "kind": "delivery", + "live_mode": true, + "manifest": { + "reference": "EI000001", + "description": "1 x Package 1\n", + "total_value": 1099 + }, + "manifest_items": { + "name": "Bow tie", + "quantity": 1, + "size": "small", + "dimensions": { + "length": 20, + "height": 20, + "depth": 20 + }, + "price": 100, + "weight": 300, + "vat_percentage": 1250000 + }, + "pickup": { + "name": "Joan P.", + "phone_number": "+16283337630", + "address": "2200 Market St, San Francisco, CA 94114, US", + "detailed_address": { + "street_address_1": "2200 Market St", + "street_address_2": "", + "city": "San Francisco", + "state": "CA", + "zip_code": "94114", + "country": "US" + }, + "notes": "", + "seller_notes": "", + "courier_notes": "", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "verification": { + "signature": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb", + "name": "Joan", + "signer_relationship": "SELF" + }, + "barcodes": [ + { + "type": "CODE128", + "value": "1234567890", + "scan_result": { + "outcome": "SUCCESS", + "timestamp": "2023-05-02T04:34:04.957Z" + } + } + ], + "picture": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb" + }, + "identification": { + "min_age_verified": false + }, + "pin_code": { + "entered": "3902" + }, + "completion_location": { + "lat": 37.765987, + "lng": -122.43153 + } + }, + "verification_requirements": { + "signature": true, + "signature_requirement": { + "enabled": true, + "collect_signer_name": true, + "collect_signer_relationship": true + }, + "barcodes": [ + { + "value": "string", + "type": "CODE39" + } + ], + "pincode": { + "enabled": true, + "value": "1234" + }, + "identification": { + "min_age": 21, + "no_sobriety_check": true + }, + "picture": true + }, + "status": "completed", + "status_timestamp": "2023-05-02T02:30:07.560Z", + "external_store_id": "my_store_123" + }, + "pickup_deadline": "2023-05-01T22:35:13.000Z", + "pickup_eta": "2023-05-01T22:16:21.749Z", + "pickup_ready": "2023-05-01T22:20:13.000Z", + "related_deliveries": [ + { + "id": "ret_BiymjKtjTwKpoS2kSIuxlv", + "relationship": "return" + } + ], + "status": "pending", + "tip": 500, + "tracking_url": "https://delivery.uber.com/orders/62105936-e413-40d5-aecd-4c335c3cd3c2", + "undeliverable_action": "", + "undeliverable_reason": "", + "updated": "2023-05-01T22:16:20.023Z", + "uuid": "62105936E41340D5AECD4C335C3CD3C2", + "return": { + "name": "Joan P.", + "phone_number": "+16283337630", + "address": "2200 Market St, San Francisco, CA 94114, US", + "detailed_address": { + "street_address_1": "2200 Market St", + "street_address_2": "", + "city": "San Francisco", + "state": "CA", + "zip_code": "94114", + "country": "US" + }, + "notes": "", + "seller_notes": "", + "courier_notes": "", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "verification": { + "signature": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb", + "name": "Joan", + "signer_relationship": "SELF" + }, + "barcodes": [ + { + "type": "CODE128", + "value": "1234567890", + "scan_result": { + "outcome": "SUCCESS", + "timestamp": "2023-05-02T04:34:04.957Z" + } + } + ], + "picture": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb" + }, + "identification": { + "min_age_verified": false + }, + "pin_code": { + "entered": "3902" + }, + "completion_location": { + "lat": 37.765987, + "lng": -122.43153 + } + }, + "verification_requirements": { + "signature": true, + "signature_requirement": { + "enabled": true, + "collect_signer_name": true, + "collect_signer_relationship": true + }, + "barcodes": [ + { + "value": "string", + "type": "CODE39" + } + ], + "pincode": { + "enabled": true, + "value": "1234" + }, + "identification": { + "min_age": 21, + "no_sobriety_check": true + }, + "picture": true + }, + "status": "completed", + "status_timestamp": "2023-05-02T02:30:07.560Z", + "external_store_id": "my_store_123" + } +} diff --git a/test/fixtures/delivery_proof_of_delivery.json b/test/fixtures/delivery_proof_of_delivery.json new file mode 100644 index 0000000..1b814e7 --- /dev/null +++ b/test/fixtures/delivery_proof_of_delivery.json @@ -0,0 +1,3 @@ +{ + "document": "document" +} diff --git a/test/fixtures/delivery_update.json b/test/fixtures/delivery_update.json new file mode 100644 index 0000000..2635273 --- /dev/null +++ b/test/fixtures/delivery_update.json @@ -0,0 +1,295 @@ +{ + "id": "del_some_id", + "quote_id": "quote_id", + "complete": false, + "courier": { + "name": "Alex I.", + "rating": 0, + "vehicle_type": "car", + "phone_number": "+16283337630", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "img_href": "https://d1w2poirtb3as9.cloudfront.net/default.jpeg?Expires=1683022587&Signature=SDlYXhlrNUXVibLEi1veShGrVQqn~5cHlDmKHmirytOvtRPLUzMICPLoLXL8vn7XREKo6XmRjYbE~tMeCqBf3Pjyc4OKqsAyukoUr5ew7S9ipbJ-O0PCp5ThZ4j46yZquza1s~qOQISHopH734F17BaNxod9E9QPJJ3phFcrl4COKYSt3qPsn9Y9PQxyKecJ5Sr0RveI5hGqtQR~u2d3EZgXmJxuGUdk26WX-Ho1h3ziIpnIBu6P6upbOtlnxLqn-dG7tl15pnn~bW1w0qAemFUUdqWzzWfjVGLHonDqE4LM5xE~t1T~1zJCNQ-uzijjI6tnEfIHJ9LgWRRhX3sKXQ__&Key-Pair-Id=K36LFL06Z5BT10", + "public_phone_info": { + "formatted_phone_number": "+15555555557,48023618", + "phone_number": "+15555555557", + "pin_code": "48023618" + } + }, + "courier_imminent": true, + "created": "2023-05-01T22:15:13.646Z", + "currency": "usd", + "deliverable_action": "deliverable_action_meet_at_door", + "dropoff": { + "name": "Joan P.", + "phone_number": "+16283337630", + "address": "2200 Market St, San Francisco, CA 94114, US", + "detailed_address": { + "street_address_1": "2200 Market St", + "street_address_2": "", + "city": "San Francisco", + "state": "CA", + "zip_code": "94114", + "country": "US" + }, + "notes": "Second floor, black door to the right.", + "seller_notes": "", + "courier_notes": "", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "verification": { + "signature": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb", + "name": "Joan", + "signer_relationship": "SELF" + }, + "barcodes": [ + { + "type": "CODE128", + "value": "1234567890", + "scan_result": { + "outcome": "SUCCESS", + "timestamp": "2023-05-02T04:34:04.957Z" + } + } + ], + "picture": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb" + }, + "identification": { + "min_age_verified": false + }, + "pin_code": { + "entered": "3902" + }, + "completion_location": { + "lat": 37.765987, + "lng": -122.43153 + } + }, + "verification_requirements": { + "signature": true, + "signature_requirement": { + "enabled": true, + "collect_signer_name": true, + "collect_signer_relationship": true + }, + "barcodes": [ + { + "value": "string", + "type": "CODE39" + } + ], + "pincode": { + "enabled": true, + "value": "1234" + }, + "identification": { + "min_age": 21, + "no_sobriety_check": true + }, + "picture": true + }, + "status": "completed", + "status_timestamp": "2023-05-02T02:30:07.560Z", + "external_store_id": "my_store_123" + }, + "dropoff_deadline": "2023-05-01T23:01:37.000Z", + "dropoff_eta": "2023-05-01T22:30:00.077Z", + "dropoff_identifier": "", + "dropoff_ready": "2023-05-01T22:15:13.000Z", + "external_id": "EI000001", + "fee": 1099, + "kind": "delivery", + "live_mode": true, + "manifest": { + "reference": "EI000001", + "description": "1 x Package 1\n", + "total_value": 1099 + }, + "manifest_items": { + "name": "Bow tie", + "quantity": 1, + "size": "small", + "dimensions": { + "length": 20, + "height": 20, + "depth": 20 + }, + "price": 100, + "weight": 300, + "vat_percentage": 1250000 + }, + "pickup": { + "name": "Lionel Messi's house", + "phone_number": "+16283337630", + "address": "2200 Market St, San Francisco, CA 94114, US", + "detailed_address": { + "street_address_1": "2200 Market St", + "street_address_2": "", + "city": "San Francisco", + "state": "CA", + "zip_code": "94114", + "country": "US" + }, + "notes": "The doorbell is not working. Knock on the door to the rhythm of Duraznito by Damas Gratis.", + "seller_notes": "", + "courier_notes": "", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "verification": { + "signature": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb", + "name": "Joan", + "signer_relationship": "SELF" + }, + "barcodes": [ + { + "type": "CODE128", + "value": "1234567890", + "scan_result": { + "outcome": "SUCCESS", + "timestamp": "2023-05-02T04:34:04.957Z" + } + } + ], + "picture": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb" + }, + "identification": { + "min_age_verified": false + }, + "pin_code": { + "entered": "3902" + }, + "completion_location": { + "lat": 37.765987, + "lng": -122.43153 + } + }, + "verification_requirements": { + "signature": true, + "signature_requirement": { + "enabled": true, + "collect_signer_name": true, + "collect_signer_relationship": true + }, + "barcodes": [ + { + "value": "string", + "type": "CODE39" + } + ], + "pincode": { + "enabled": true, + "value": "1234" + }, + "identification": { + "min_age": 21, + "no_sobriety_check": true + }, + "picture": true + }, + "status": "completed", + "status_timestamp": "2023-05-02T02:30:07.560Z", + "external_store_id": "my_store_123" + }, + "pickup_deadline": "2023-05-01T22:35:13.000Z", + "pickup_eta": "2023-05-01T22:16:21.749Z", + "pickup_ready": "2023-05-01T22:20:13.000Z", + "related_deliveries": [ + { + "id": "ret_BiymjKtjTwKpoS2kSIuxlv", + "relationship": "return" + } + ], + "status": "pending", + "tip": 500, + "tracking_url": "https://delivery.uber.com/orders/62105936-e413-40d5-aecd-4c335c3cd3c2", + "undeliverable_action": "", + "undeliverable_reason": "", + "updated": "2023-05-01T22:16:20.023Z", + "uuid": "62105936E41340D5AECD4C335C3CD3C2", + "return": { + "name": "Joan P.", + "phone_number": "+16283337630", + "address": "2200 Market St, San Francisco, CA 94114, US", + "detailed_address": { + "street_address_1": "2200 Market St", + "street_address_2": "", + "city": "San Francisco", + "state": "CA", + "zip_code": "94114", + "country": "US" + }, + "notes": "", + "seller_notes": "", + "courier_notes": "", + "location": { + "lat": 37.765987, + "lng": -122.43153 + }, + "verification": { + "signature": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb", + "name": "Joan", + "signer_relationship": "SELF" + }, + "barcodes": [ + { + "type": "CODE128", + "value": "1234567890", + "scan_result": { + "outcome": "SUCCESS", + "timestamp": "2023-05-02T04:34:04.957Z" + } + } + ], + "picture": { + "image_url": "https://tb-static.uber.com/prod/file-upload/uploads/courier-task-platform/82a0d88e-100d-40d6-a0d0-ea9c4a2e55bb" + }, + "identification": { + "min_age_verified": false + }, + "pin_code": { + "entered": "3902" + }, + "completion_location": { + "lat": 37.765987, + "lng": -122.43153 + } + }, + "verification_requirements": { + "signature": true, + "signature_requirement": { + "enabled": true, + "collect_signer_name": true, + "collect_signer_relationship": true + }, + "barcodes": [ + { + "value": "string", + "type": "CODE39" + } + ], + "pincode": { + "enabled": true, + "value": "1234" + }, + "identification": { + "min_age": 21, + "no_sobriety_check": true + }, + "picture": true + }, + "status": "completed", + "status_timestamp": "2023-05-02T02:30:07.560Z", + "external_store_id": "my_store_123" + } +} diff --git a/test/ruber/request_test.rb b/test/ruber/request_test.rb new file mode 100644 index 0000000..dea4acc --- /dev/null +++ b/test/ruber/request_test.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require File.expand_path("../test_helper", __dir__) + +module Ruber + class RequestTest < Minitest::Test + def setup + stub_token_request + + @request = Ruber::Request.new("/test") + end + + def test_get_success + stub_request(:get, /.*test.*/) + .to_return( + status: 200, + headers: { "Content-Type" => "application/json" }, + body: { message: "OK" }.to_json + ) + + response = @request.get + + assert_equal 200, response.status + assert_equal "OK", response.body[:message] + end + + def test_get_error + stub_request(:get, /.*test/) + .to_return( + headers: { "Content-Type" => "application/json" }, + status: 400, + body: { + message: "Bad Request", + metadata: { foo: "bar" } + }.to_json + ) + + error = assert_raises(Ruber::Error) { @request.get } + assert_equal "Bad Request", error.message + assert_equal "bar", error.metadata[:foo] + end + end +end diff --git a/test/ruber/resources/delivery_resource_test.rb b/test/ruber/resources/delivery_resource_test.rb index c99bfc4..b8bb82e 100644 --- a/test/ruber/resources/delivery_resource_test.rb +++ b/test/ruber/resources/delivery_resource_test.rb @@ -2,7 +2,7 @@ require File.expand_path("../../test_helper", __dir__) -class DelvieryResourceTest < Minitest::Test +class DeliveryResourceTest < Minitest::Test def test_all stub_deliveries_request deliveries = Ruber::DeliveryResource.all @@ -20,6 +20,39 @@ def test_find assert_equal "quote_id", delivery.quote_id end + def test_create + stub_delivery_creation_request + delivery = Ruber::DeliveryResource.create(create_params) + + assert_instance_of Ruber::Delivery, delivery + assert_equal "quote_id", delivery.quote_id + end + + def test_cancel + stub_delivery_cancellation_request + delivery = Ruber::DeliveryResource.cancel("del_some_id") + + assert_instance_of Ruber::Delivery, delivery + assert_equal "quote_id", delivery.quote_id + end + + def test_update + stub_delivery_update_request + delivery = Ruber::DeliveryResource.update("del_some_id", update_params) + + assert_instance_of Ruber::Delivery, delivery + assert_equal "The doorbell is not working. Knock on the door to the rhythm of Duraznito by Damas Gratis.", + delivery.pickup.notes + end + + def test_proof_of_delivery + stub_delivery_proof_of_delivery_request + proof_of_delivery = Ruber::DeliveryResource.proof_of_delivery("del_some_id", proof_of_delivery_params) + + assert_instance_of Ruber::Delivery::ProofOfDelivery, proof_of_delivery + assert_equal "document", proof_of_delivery.document + end + private def stub_delivery_request @@ -33,6 +66,50 @@ def stub_delivery_request ) end + def stub_delivery_creation_request + stub_token_request + stub_request(:post, %r{.*customers/#{Ruber.customer_id}/deliveries.*}) + .with(headers: { "Authorization" => "Bearer #{Ruber::Authenticator.access_token}" }) + .to_return( + headers: { "Content-Type" => "application/json" }, + status: 200, + body: File.new("test/fixtures/delivery.json").read + ) + end + + def stub_delivery_cancellation_request + stub_token_request + stub_request(:post, %r{.*customers/#{Ruber.customer_id}/deliveries/.*}) + .with(headers: { "Authorization" => "Bearer #{Ruber::Authenticator.access_token}" }) + .to_return( + headers: { "Content-Type" => "application/json" }, + status: 200, + body: File.new("test/fixtures/delivery_cancel.json").read + ) + end + + def stub_delivery_proof_of_delivery_request + stub_token_request + stub_request(:post, %r{.*customers/#{Ruber.customer_id}/deliveries/.*}) + .with(headers: { "Authorization" => "Bearer #{Ruber::Authenticator.access_token}" }) + .to_return( + headers: { "Content-Type" => "application/json" }, + status: 200, + body: File.new("test/fixtures/delivery_proof_of_delivery.json").read + ) + end + + def stub_delivery_update_request + stub_token_request + stub_request(:post, %r{.*customers/#{Ruber.customer_id}/deliveries/.*}) + .with(headers: { "Authorization" => "Bearer #{Ruber::Authenticator.access_token}" }) + .to_return( + headers: { "Content-Type" => "application/json" }, + status: 200, + body: File.new("test/fixtures/delivery_update.json").read + ) + end + def stub_deliveries_request stub_token_request stub_request(:get, %r{.*customers/#{Ruber.customer_id}/deliveries}) @@ -43,4 +120,60 @@ def stub_deliveries_request body: File.new("test/fixtures/deliveries.json").read ) end + + def proof_of_delivery_params + { + "waypoint": "dropoff", + "type": "picture" + } + end + + def create_params + { + pickup_name: "Store Name", + pickup_address: "{\"street_address\":[\"100 Maiden Ln\"],\"city\":\"New York\",\"state\":\"NY\",\"zip_code\":\"10023\",\"country\":\"US\"}", # rubocop:disable Layout/LineLength + pickup_phone_number: "+15555555555", + dropoff_name: "Gordon Shumway", + dropoff_address: "{\"street_address\":[\"30 Lincoln Center Plaza\"],\"city\":\"New York\",\"state\":\"NY\",\"zip_code\":\"10023\",\"country\":\"US\"}", # rubocop:disable Layout/LineLength + dropoff_phone_number: "+15555555555", + manifest_items: [ + { + name: "Bow tie", + quantity: 1, + size: "small", + dimensions: { + "length": 20, + "height": 20, + "depth": 20 + }, + price: 100, + weight: 300, + vat_percentage: 1_250_000 + } + ] + } + end + + def update_params + { + "dropoff_notes": "Second floor, black door to the right.", + "dropoff_verification": { + "barcodes": [] + }, + "manifest_reference": "REF0000002", + "pickup_notes": "The doorbell is not working. Knock on the door to the rhythm of Duraznito by Damas Gratis.", + "pickup_verification": { + "barcodes": [] + }, + "requires_dropoff_signature": true, + "requires_id": false, + "tip_by_customer": 500, + "dropoff_latitude": 40.7727076, + "dropoff_longitude": -73.9839082, + "pickup_ready_dt": "2024-12-12T14:00:00.000Z", + "pickup_deadline_dt": "2024-12-12T14:30:00.000Z", + "dropoff_ready_dt": "2024-12-12T14:30:00.000Z", + "dropoff_deadline_dt": "2024-12-12T16:00:00.000Z" + } + end end