Module: SpreeUberDirect::AddressPayload
- Defined in:
- app/services/spree_uber_direct/address_payload.rb
Overview
Shared address/phone formatting between Quote (create_quote) and DeliveryDispatcher (create_delivery) — both build a payload from the same order + fulfilling StockLocation shape, and Uber's schema uses the identical JSON-string-address / E.164-phone conventions on both endpoints (confirmed directly against the real openapi.yaml).
Class Method Summary collapse
-
.format_address(record) ⇒ Object
Uber wants a JSON string per address field — structured, not DoorDash's flat comma-joined string.
-
.format_phone(raw) ⇒ Object
Same E.164 normalization as SpreeDoordash::Quote#format_phone (Uber's own schema pattern,
^\+[0-9]+$, is the same shape DoorDash rejects anything else against) — US-only, matching the rest of this demo.
Class Method Details
.format_address(record) ⇒ Object
Uber wants a JSON string per address field — structured, not DoorDash's flat comma-joined string. Spree::StockLocation and Spree::Address share the same field shape (address1/address2/city/ state/zipcode/country) even though they're unrelated classes.
24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/spree_uber_direct/address_payload.rb', line 24 def format_address(record) street = [record.address1, record.try(:address2)].compact_blank { street_address: street, city: record.city, state: record.state&.abbr || record.state_name, zip_code: record.zipcode, country: record.country&.iso }.compact.to_json end |
.format_phone(raw) ⇒ Object
Same E.164 normalization as SpreeDoordash::Quote#format_phone
(Uber's own schema pattern, ^\+[0-9]+$, is the same shape DoorDash
rejects anything else against) — US-only, matching the rest of this
demo.
14 15 16 17 18 |
# File 'app/services/spree_uber_direct/address_payload.rb', line 14 def format_phone(raw) digits = raw.to_s.gsub(/\D/, '') digits = "1#{digits}" if digits.length == 10 "+#{digits}" end |