Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Parse & add the missing API details #287

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions duffel_api/models/airline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Airline:
id: str
name: str
iata_code: Optional[str]
logo_lockup_url: Optional[str]
Copy link
Contributor

@jesse-c jesse-c Jun 13, 2023

Choose a reason for hiding this comment

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

test: Could you please add examples of these to the test fixture? [1][2]

[1]

{
"iata_code": "BA",
"id": "aln_00001876aqC8c5umZmrRds",
"name": "British Airways"
}

[2]

    {
      "iata_code": "BA",
      "id": "aln_00001876aqC8c5umZmrRds",
      "name": "British Airways",
      "logo_lockup_url": "https://assets.duffel.com/img/airlines/for-light-background/full-color-lockup/BA.svg",
      "logo_symbol_url": "https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/BA.svg"
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

future: We need to add conditions_of_carriage_url [1] as well.

[1] https://duffel.com/docs/api/v1/airlines/schema#airlines-schema-conditions-of-carriage-url.

logo_symbol_url: Optional[str]

@classmethod
def from_json(cls, json: dict):
Expand All @@ -19,4 +21,6 @@ def from_json(cls, json: dict):
id=json["id"],
name=json["name"],
iata_code=json.get("iata_code"),
logo_lockup_url=json.get("logo_lockup_url"),
logo_symbol_url=json.get("logo_symbol_url"),
)
36 changes: 36 additions & 0 deletions duffel_api/models/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,32 @@ def from_json(cls, json: dict):
)


@dataclass
class OfferSliceSegmentStop:
"""Additional segment-specific information about the stops, if any, included in the segment"""
Copy link
Contributor

@jesse-c jesse-c Jun 13, 2023

Choose a reason for hiding this comment

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

fix: This line is too long [1]. You can fix it by running tox -e linting or flake8 locally.

[1] https://github.com/duffelhq/duffel-api-python/actions/runs/5245627223/jobs/9476358835?pr=287


id: str
ulissesalmeida marked this conversation as resolved.
Show resolved Hide resolved
duration: str
Copy link
Contributor

Choose a reason for hiding this comment

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

test: Similar request here to add some stops to the test fixture [1].

[1]

{
"aircraft": {
"iata_code": "380",
"id": "arc_00009UhD4ongolulWd91Ky",
"name": "Airbus Industries A380"
},
"arriving_at": "2020-06-13T16:38:02",
"departing_at": "2020-06-13T16:38:02",
"destination": {
"city": {
"iata_code": "NYC",
"iata_country_code": "US",
"id": "cit_nyc_us",
"name": "New York"
},
"city_name": "New York",
"iata_code": "JFK",
"iata_country_code": "US",
"icao_code": "KJFK",
"id": "arp_jfk_us",
"latitude": 40.640556,
"longitude": -73.778519,
"name": "John F. Kennedy International Airport",
"time_zone": "America/New_York"
},
"destination_terminal": "5",
"distance": "424.2",
"duration": "PT02H26M",
"id": "seg_00009htYpSCXrwaB9Dn456",
"marketing_carrier": {
"iata_code": "BA",
"id": "aln_00001876aqC8c5umZmrRds",
"name": "British Airways"
},
"marketing_carrier_flight_number": "1234",
"operating_carrier": {
"iata_code": "BA",
"id": "aln_00001876aqC8c5umZmrRds",
"name": "British Airways"
},
"operating_carrier_flight_number": "4321",
"origin": {
"city": {
"iata_code": "LON",
"iata_country_code": "GB",
"id": "cit_lon_gb",
"name": "London"
},
"city_name": "London",
"iata_code": "LHR",
"iata_country_code": "GB",
"icao_code": "EGLL",
"id": "arp_lhr_gb",
"latitude": 64.068865,
"longitude": -141.951519,
"name": "Heathrow",
"time_zone": "Europe/London"
},
"origin_terminal": "B",
"passengers": [
{
"baggages": [
{
"quantity": 1,
"type": "checked"
}
],
"cabin_class": "economy",
"cabin_class_marketing_name": "Economy Basic",
"fare_basis_code": "OXZ0RO",
"passenger_id": "passenger_0"
}
]
}

arriving_at: datetime
departing_at: datetime
airport: Airport

@classmethod
def from_json(cls, json: dict):
"""Construct a class instance from a JSON response."""
return cls(
id=json["id"],
arriving_at=get_and_transform(
json, "arriving_at", parse_datetime
),
departing_at=get_and_transform(
json, "departing_at", parse_datetime
),
Comment on lines +239 to +244
Copy link
Contributor

Choose a reason for hiding this comment

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

fix: The reason for the static analysis (pyright) failures is that this helper function, get_and_transform, is for when values are optional.

Those 2 aren't, so you can parse them directly.

Suggested change
arriving_at=get_and_transform(
json, "arriving_at", parse_datetime
),
departing_at=get_and_transform(
json, "departing_at", parse_datetime
),
arriving_at=parse_datetime(json["arriving_at"]),
departing_at=parse_datetime(json["departing_at"]),

Choose a reason for hiding this comment

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

Ahh sorry, it was my bad

airport=Airport.from_json(json["airport"]),
duration=json.get("duration"),
)


@dataclass
class OfferSliceSegment:
"""The segments - that is, specific flights - that the airline is offering
Expand All @@ -242,6 +268,7 @@ class OfferSliceSegment:
operating_carrier: Airline
operating_carrier_flight_number: Optional[str]
passengers: Sequence[OfferSliceSegmentPassenger]
stops: Sequence[OfferSliceSegmentStop]

@classmethod
def from_json(cls, json: dict):
Expand Down Expand Up @@ -270,6 +297,15 @@ def from_json(cls, json: dict):
],
[],
),
stops=get_and_transform(
json,
"stops",
lambda value: [
OfferSliceSegmentStop.from_json(stop)
for stop in value
],
[],
),
)


Expand Down