Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ruber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Ruber

autoload :DeliveryResource, "ruber/resources/delivery_resource"

autoload :Collection, "ruber/collection"
autoload :Delivery, "ruber/objects/delivery"

DEFAULT_API_BASE = "https://api.uber.com/v1"
Expand Down
21 changes: 21 additions & 0 deletions lib/ruber/collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Ruber
class Collection
attr_reader :data, :next_href

def self.from_response(response, type:)
body = response.body

new(
data: body[:data].map { |attrs| type.new(attrs) },
next_href: body[:next_href]
)
end

def initialize(data:, next_href:)
@data = data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tengo nada contra que se llame data, pero por ahí podría llamarse list o objects

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Los nombres son los que usa la API de Uber. Me pareció mejor mantenerlos.

@next_href = next_href
end
end
end
6 changes: 6 additions & 0 deletions lib/ruber/resources/delivery_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
module Ruber
class DeliveryResource
class << self
def all
response = Request.new("customers/#{Ruber.customer_id}/deliveries").get

Collection.from_response(response, type: Delivery)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No convendría directamente pasar el response.body dado que es lo único que se usa?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo pensé y no veo razón para no hacerlo. Lo cambio.

end

def find(id)
response = Request.new("customers/#{Ruber.customer_id}/deliveries/#{id}").get

Expand Down
301 changes: 301 additions & 0 deletions test/fixtures/deliveries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
{
"data": [
{
"id": "del_gDcyfRgyQcyN0obpqqS_1B",
"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"
}
}
],
"next_href": "api.uber.com/v1/customers/d553004e-a505-4c48-8887-194e57769172/deliveries?offset=30",
"total_count": -1
}
20 changes: 20 additions & 0 deletions test/ruber/resources/delivery_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
require File.expand_path("../../test_helper", __dir__)

class DelvieryResourceTest < Minitest::Test
def test_all
stub_deliveries_request
deliveries = Ruber::DeliveryResource.all

assert_instance_of Ruber::Collection, deliveries
assert_instance_of Ruber::Delivery, deliveries.data.first
assert_equal "quote_id", deliveries.data.first.quote_id
end

def test_find
stub_delivery_request
delivery = Ruber::DeliveryResource.find("del_some_id")
Expand All @@ -23,4 +32,15 @@ def stub_delivery_request
body: File.new("test/fixtures/delivery.json").read
)
end

def stub_deliveries_request
stub_token_request
stub_request(:get, %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/deliveries.json").read
)
end
end