Skip to content

api_responses

API Response Objects

These are JSON Responses from APIs

AwareDatetime #

Bases: datetime

Datetime Aware Timestamp Parsing

Source code in camply/containers/api_responses.py
class AwareDatetime(datetime.datetime):
    """
    Datetime Aware Timestamp Parsing
    """

    @classmethod
    def __get_validators__(cls) -> Iterator:
        """
        Generate Validators
        """
        yield cls.validate

    @classmethod
    def validate(cls, v: Union[str, datetime.datetime]) -> datetime.datetime:
        """
        Validate Date Strings Into

        Parameters
        ----------
        v: Union[str, datetime.datetime]

        Returns
        -------
        datetime.datetime
        """
        if isinstance(v, str):
            return datetime.datetime.strptime(v, "%Y-%m-%dT%H:%M:%S%z")
        elif isinstance(v, datetime.datetime):
            if v.tzinfo is None:
                raise ValueError(
                    "You Must Provide a Parsable Datetime Object with tzinfo"
                )
            return v
        else:
            raise ValueError("You Must Provide a Parsable Datetime String or Object")

__get_validators__() classmethod #

Generate Validators

Source code in camply/containers/api_responses.py
@classmethod
def __get_validators__(cls) -> Iterator:
    """
    Generate Validators
    """
    yield cls.validate

validate(v) classmethod #

Validate Date Strings Into

Parameters:

Name Type Description Default
v Union[str, datetime]
required

Returns:

Type Description
datetime
Source code in camply/containers/api_responses.py
@classmethod
def validate(cls, v: Union[str, datetime.datetime]) -> datetime.datetime:
    """
    Validate Date Strings Into

    Parameters
    ----------
    v: Union[str, datetime.datetime]

    Returns
    -------
    datetime.datetime
    """
    if isinstance(v, str):
        return datetime.datetime.strptime(v, "%Y-%m-%dT%H:%M:%S%z")
    elif isinstance(v, datetime.datetime):
        if v.tzinfo is None:
            raise ValueError(
                "You Must Provide a Parsable Datetime Object with tzinfo"
            )
        return v
    else:
        raise ValueError("You Must Provide a Parsable Datetime String or Object")

CampsiteAvailabilityResponse #

Bases: CamplyModel

https://ridb.recreation.gov/api/v1/campsites/

Source code in camply/containers/api_responses.py
class CampsiteAvailabilityResponse(CamplyModel):
    """
    https://ridb.recreation.gov/api/v1/campsites/<CAMPSITE ID>
    """

    campsites: Dict[int, _CampsiteAvailabilityCampsiteResponse]

CampsiteResponse #

Bases: CoreRecDotGovResponse

https://ridb.recreation.gov/api/v1/campsites/

Source code in camply/containers/api_responses.py
class CampsiteResponse(CoreRecDotGovResponse):
    """
    https://ridb.recreation.gov/api/v1/campsites/<CAMPSITE ID>
    """

    CampsiteID: int
    FacilityID: int
    CampsiteName: str
    CampsiteType: str
    TypeOfUse: str
    Loop: str
    CampsiteAccessible: bool
    CampsiteReservable: bool
    CampsiteLongitude: float
    CampsiteLatitude: float
    CreatedDate: datetime.date
    LastUpdatedDate: datetime.date
    PERMITTEDEQUIPMENT: List[_CampsiteEquipment]
    ATTRIBUTES: List[_CampsiteAttribute]

    def __str__(self) -> str:
        """
        String Representation
        """
        return f"{self.CampsiteName} (#{self.CampsiteID})"

__str__() #

String Representation

Source code in camply/containers/api_responses.py
def __str__(self) -> str:
    """
    String Representation
    """
    return f"{self.CampsiteName} (#{self.CampsiteID})"

CoreRecDotGovResponse #

Bases: CamplyModel

Core Response from Recreation.gov

Source code in camply/containers/api_responses.py
class CoreRecDotGovResponse(CamplyModel):
    """
    Core Response from Recreation.gov
    """

Date #

Bases: date

Date Parsing

Source code in camply/containers/api_responses.py
class Date(datetime.date):
    """
    Date Parsing
    """

    @classmethod
    def __get_validators__(cls) -> Iterator:
        """
        Generate Validators
        """
        yield cls.validate

    @classmethod
    def validate(cls, v: Union[str, datetime.date]) -> datetime.date:
        """
        Validate Date Strings Into

        Parameters
        ----------
        v: Union[str, datetime.date]

        Returns
        -------
        datetime.date
        """
        if isinstance(v, str):
            return datetime.datetime.strptime(v, "%Y-%m-%d").date()
        elif isinstance(v, datetime.date):
            return v
        else:
            raise ValueError("You Must Provide a Parsable Date String or Object")

__get_validators__() classmethod #

Generate Validators

Source code in camply/containers/api_responses.py
@classmethod
def __get_validators__(cls) -> Iterator:
    """
    Generate Validators
    """
    yield cls.validate

validate(v) classmethod #

Validate Date Strings Into

Parameters:

Name Type Description Default
v Union[str, date]
required

Returns:

Type Description
date
Source code in camply/containers/api_responses.py
@classmethod
def validate(cls, v: Union[str, datetime.date]) -> datetime.date:
    """
    Validate Date Strings Into

    Parameters
    ----------
    v: Union[str, datetime.date]

    Returns
    -------
    datetime.date
    """
    if isinstance(v, str):
        return datetime.datetime.strptime(v, "%Y-%m-%d").date()
    elif isinstance(v, datetime.date):
        return v
    else:
        raise ValueError("You Must Provide a Parsable Date String or Object")

FacilityResponse #

Bases: CamplyModel

/api/v1/facilities/

Source code in camply/containers/api_responses.py
class FacilityResponse(CamplyModel):
    """
    /api/v1/facilities/<Facility ID>
    """

    FacilityID: Union[int, str]
    FacilityName: str
    FacilityTypeDescription: str
    Enabled: bool
    Reservable: bool
    FACILITYADDRESS: Optional[List[_FacilityAddress]]
    RECAREA: Optional[List[_FacilityRecArea]]
    ORGANIZATION: Optional[List[_FacilityOrganization]]
    ParentRecAreaID: Optional[Union[int, str]]

    @validator("ParentRecAreaID", pre=True, always=False)
    def validate_parentrecid(cls, val: Any) -> Optional[int]:
        """
        Validate Empty Strings as Null
        """
        if val == "":
            return None
        return val

validate_parentrecid(val) #

Validate Empty Strings as Null

Source code in camply/containers/api_responses.py
@validator("ParentRecAreaID", pre=True, always=False)
def validate_parentrecid(cls, val: Any) -> Optional[int]:
    """
    Validate Empty Strings as Null
    """
    if val == "":
        return None
    return val

GenericResponse #

Bases: CamplyModel

Generic Response to Be Paginated

Source code in camply/containers/api_responses.py
class GenericResponse(CamplyModel):
    """
    Generic Response to Be Paginated
    """

    RECDATA: Any
    METADATA: _PaginationMetadataResponse

RecDotGovCampsite #

Bases: CamplyModel

Recreation.gov Campsite Object

Source code in camply/containers/api_responses.py
class RecDotGovCampsite(CamplyModel):
    """
    Recreation.gov Campsite Object
    """

    accessible: bool
    asset_id: int
    asset_type = str
    attributes: List[RecDotGovAttribute]
    average_rating: Optional[int]
    campsite_id: int
    campsite_reserve_type: str
    city: Optional[str]
    country_code: Optional[str]
    fee_templates: Dict[str, Any]
    latitude: Optional[float]
    longitude: Optional[float]
    loop: str
    name: str
    number_of_ratings = int
    org_id: int
    org_name: str
    parent_asset_id: int
    parent_asset_name: str
    parent_asset_type: str
    permitted_equipment: List[RecDotGovEquipment]
    preview_image_url: Optional[str]
    reservable: bool
    state_code: Optional[str]
    type: str
    type_of_use: str

RecDotGovCampsiteResponse #

Bases: CamplyModel

Parent Response from Campsite Metadata

Source code in camply/containers/api_responses.py
class RecDotGovCampsiteResponse(CamplyModel):
    """
    Parent Response from Campsite Metadata
    """

    campsites: List[RecDotGovCampsite]
    size: int
    spelling_autocorrected: Any
    start: int
    total: int

RecDotGovSearchResponse #

Bases: CamplyModel

Parent Response from Search Results

Source code in camply/containers/api_responses.py
class RecDotGovSearchResponse(CamplyModel):
    """
    Parent Response from Search Results
    """

    results: List[RecDotGovSearchResult]
    size: int
    spelling_autocorrected: Any
    start: int
    total: int

RecDotGovSearchResult #

Bases: CamplyModel

Recreation.gov Search Result Object

Source code in camply/containers/api_responses.py
class RecDotGovSearchResult(CamplyModel):
    """
    Recreation.gov Search Result Object
    """

    average_rating: Optional[int]
    description: Optional[str]
    entity_id: int
    entity_type: str
    latitude: Optional[float]
    longitude: Optional[float]
    name: str
    number_of_ratings = int
    org_id: int
    parent_id: int
    parent_name: str
    parent_type: str
    preview_image_url: Optional[str]
    reservable: bool
    time_zone: str
    type: str

RecreationAreaResponse #

Bases: CamplyModel

https://ridb.recreation.gov/api/v1/campsites/

Source code in camply/containers/api_responses.py
class RecreationAreaResponse(CamplyModel):
    """
    https://ridb.recreation.gov/api/v1/campsites/<CAMPSITE ID>
    """

    RecAreaID: Union[int, str]
    RecAreaName: str
    RECAREAADDRESS: List[_RecAreaAddress]

TourDailyAvailabilityBookingWindow #

Bases: CamplyModel

https://ridb.recreation.gov/api/v1/tours/

Source code in camply/containers/api_responses.py
class TourDailyAvailabilityBookingWindow(CamplyModel):
    """
    https://ridb.recreation.gov/api/v1/tours/<CAMPSITE ID>
    """

    open_timestamp: AwareDatetime
    close_timestamp: AwareDatetime

TourDailyAvailabilityBookingWindows #

Bases: CamplyModel

https://ridb.recreation.gov/api/v1/tours/

Source code in camply/containers/api_responses.py
class TourDailyAvailabilityBookingWindows(CamplyModel):
    """
    https://ridb.recreation.gov/api/v1/tours/<CAMPSITE ID>
    """

    PRIMARY: Optional[TourDailyAvailabilityBookingWindow]
    SECONDARY: Optional[TourDailyAvailabilityBookingWindow]

TourDailyAvailabilityResponse #

Bases: CamplyModel

https://ridb.recreation.gov/api/v1/tours/

Source code in camply/containers/api_responses.py
class TourDailyAvailabilityResponse(CamplyModel):
    """
    https://ridb.recreation.gov/api/v1/tours/<CAMPSITE ID>
    """

    facility_id: int
    booking_windows: TourDailyAvailabilityBookingWindows
    inventory_count: Dict[str, int]
    reservation_count: Dict[str, int]
    status: str
    tour_date: Date
    tour_id: int
    tour_time: str

TourMonthlyAvailabilityResponse #

Bases: CamplyModel

https://ridb.recreation.gov/api/v1/tours/

Source code in camply/containers/api_responses.py
class TourMonthlyAvailabilityResponse(CamplyModel):
    """
    https://ridb.recreation.gov/api/v1/tours/<CAMPSITE ID>
    """

    facility_availability_summary_view_by_local_date: Dict[
        Date, _TourMonthlyAvailabilityDateResponse
    ]

TourResponse #

Bases: CoreRecDotGovResponse

https://ridb.recreation.gov/api/v1/tours/

Source code in camply/containers/api_responses.py
class TourResponse(CoreRecDotGovResponse):
    """
    https://ridb.recreation.gov/api/v1/tours/<TOUR ID>
    """

    TourID: int
    FacilityID: int
    TourName: str
    TourType: str
    TourDuration: int
    TourDescription: str
    TourAccessible: bool
    CreatedDate: datetime.date
    LastUpdatedDate: datetime.date
    ATTRIBUTES: List[_CampsiteAttribute]

    def __str__(self) -> str:
        """
        String Representation
        """
        return f"{self.TourName} (#{self.TourID})"

__str__() #

String Representation

Source code in camply/containers/api_responses.py
def __str__(self) -> str:
    """
    String Representation
    """
    return f"{self.TourName} (#{self.TourID})"

UnawareDatetime #

Bases: datetime

Datetime Unaware Timestamp Parsing

Source code in camply/containers/api_responses.py
class UnawareDatetime(datetime.datetime):
    """
    Datetime Unaware Timestamp Parsing
    """

    @classmethod
    def __get_validators__(cls) -> Iterator:
        """
        Generate Validators
        """
        yield cls.validate

    @classmethod
    def validate(cls, v: Union[str, datetime.datetime]) -> datetime.datetime:
        """
        Validate Date Strings Into

        Parameters
        ----------
        v: Union[str, datetime.datetime]

        Returns
        -------
        datetime.datetime
        """
        if isinstance(v, str):
            return datetime.datetime.strptime(v, "%Y-%m-%dT%H:%M:%SZ")
        elif isinstance(v, datetime.datetime):
            return v.replace(tzinfo=None)
        else:
            raise ValueError("You Must Provide a Parsable Datetime String or Object")

__get_validators__() classmethod #

Generate Validators

Source code in camply/containers/api_responses.py
@classmethod
def __get_validators__(cls) -> Iterator:
    """
    Generate Validators
    """
    yield cls.validate

validate(v) classmethod #

Validate Date Strings Into

Parameters:

Name Type Description Default
v Union[str, datetime]
required

Returns:

Type Description
datetime
Source code in camply/containers/api_responses.py
@classmethod
def validate(cls, v: Union[str, datetime.datetime]) -> datetime.datetime:
    """
    Validate Date Strings Into

    Parameters
    ----------
    v: Union[str, datetime.datetime]

    Returns
    -------
    datetime.datetime
    """
    if isinstance(v, str):
        return datetime.datetime.strptime(v, "%Y-%m-%dT%H:%M:%SZ")
    elif isinstance(v, datetime.datetime):
        return v.replace(tzinfo=None)
    else:
        raise ValueError("You Must Provide a Parsable Datetime String or Object")

XantCampgroundDetails #

Bases: CamplyModel

Yellowstone Campground Details OBject

Source code in camply/containers/api_responses.py
class XantCampgroundDetails(CamplyModel):
    """
    Yellowstone Campground Details OBject
    """

    hotelCode: str
    status: str
    message: str
    min: str
    max: str
    perGuests: Dict[int, XantPerGuest]
    rates: Dict[str, XantRates]
    rates2: Optional[Dict[str, XantRates]]

XantPerGuest #

Bases: CamplyModel

PerGuest Objects

Source code in camply/containers/api_responses.py
class XantPerGuest(CamplyModel):
    """
    PerGuest Objects
    """

    a2: Optional[Union[int, str]]
    b: Optional[Union[int, str]]
    b2: Optional[Union[int, str]]
    m: Optional[Union[int, str]]
    m2: Optional[Union[int, str]]
    r: Optional[Union[int, str]]
    r2: Optional[Union[int, str]]
    s: Optional[Union[int, str]]

XantRates #

Bases: CamplyModel

Yellowstone Rates Object

Source code in camply/containers/api_responses.py
class XantRates(CamplyModel):
    """
    Yellowstone Rates Object
    """

    code: str
    title: str
    description: str
    category: str
    minstay: int
    start: datetime.date
    available: Dict[int, int]
    mins: Dict[int, int]
    min: int

    @validator("start", pre=True)
    def parse_datetime(cls, value):
        """
        Parse Poorly Formatted Date Strings
        """
        return datetime.datetime.strptime(value, "%m/%d/%Y").date()

parse_datetime(value) #

Parse Poorly Formatted Date Strings

Source code in camply/containers/api_responses.py
@validator("start", pre=True)
def parse_datetime(cls, value):
    """
    Parse Poorly Formatted Date Strings
    """
    return datetime.datetime.strptime(value, "%m/%d/%Y").date()

XantResortData #

Bases: CamplyModel

Main Yellowstone API Response Wrapper

Source code in camply/containers/api_responses.py
class XantResortData(CamplyModel):
    """
    Main Yellowstone API Response Wrapper
    """

    availability: Dict[datetime.date, Dict[str, XantCampgroundDetails]]

    @validator("availability", pre=True)
    def parse_datetime(cls, value):
        """
        Parse Poorly Formatted Date Strings
        """
        return {
            datetime.datetime.strptime(x, "%m/%d/%Y").date(): y
            for x, y in value.items()
        }

parse_datetime(value) #

Parse Poorly Formatted Date Strings

Source code in camply/containers/api_responses.py
@validator("availability", pre=True)
def parse_datetime(cls, value):
    """
    Parse Poorly Formatted Date Strings
    """
    return {
        datetime.datetime.strptime(x, "%m/%d/%Y").date(): y
        for x, y in value.items()
    }