Skip to content

Commit

Permalink
make types better
Browse files Browse the repository at this point in the history
  • Loading branch information
auscyber committed Jul 7, 2024
1 parent 7dd18b4 commit 3dcdd22
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 90 deletions.
35 changes: 35 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = "https://github.com/tascord/ptvrs"
anyhow = "1.0.81"
chrono = "0.4.35"
colored = "2.1.0"
derive_more = "0.99.18"
dotenv = "0.15.0"
hex = "0.4.3"
hmac = "0.12.1"
Expand Down
34 changes: 19 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Client {
"?"
} else {
if path.ends_with('?') {
""
""
} else {
"&"
}
Expand Down Expand Up @@ -63,7 +63,7 @@ impl Client {
pub async fn departures_stop(
&self,
route_type: RouteType,
stop_id: i32,
stop_id: StopId,
options: DeparturesStopOpts,
) -> Result<DeparturesResponse> {
self.rq(format!(
Expand All @@ -79,8 +79,8 @@ impl Client {
pub async fn departures_stop_route(
&self,
route_type: RouteType,
route_id: i32,
stop_id: i32,
route_id: RouteId,
stop_id: StopId,
options: DeparturesStopRouteOpts,
) -> Result<DeparturesResponse> {
self.rq(format!(
Expand All @@ -96,19 +96,19 @@ impl Client {
/* > Directions */

/// View all routes for a direction of travel
pub async fn directions_id(&self, direction_id: i32) -> Result<DirectionsResponse> {
pub async fn directions_id(&self, direction_id: DirectionId) -> Result<DirectionsResponse> {
self.rq(format!("v3/directions/{}", direction_id)).await
}

/// View directions that a route travels in
pub async fn directions_route(&self, route_id: i32) -> Result<DirectionsResponse> {
pub async fn directions_route(&self, route_id: RouteId) -> Result<DirectionsResponse> {
self.rq(format!("v3/directions/route/{}", route_id)).await
}

/// View all routes of a particular type for a direction of travel
pub async fn directions_id_route(
&self,
direction_id: i32,
direction_id: DirectionId,
route_type: RouteType,
) -> Result<DirectionsResponse> {
self.rq(format!(
Expand All @@ -129,7 +129,7 @@ impl Client {
/// View all disruptions for a particular route
pub async fn disruptions_route(
&self,
route_id: i32,
route_id: RouteId,
options: DisruptionsSpecificOpts,
) -> Result<DisruptionsResponse> {
self.rq(format!(
Expand All @@ -143,8 +143,8 @@ impl Client {
/// View all disruptions for a particular route and stop
pub async fn disruptions_route_stop(
&self,
route_id: i32,
stop_id: i32,
route_id: RouteId,
stop_id: StopId,
options: DisruptionsSpecificOpts,
) -> Result<DisruptionsResponse> {
self.rq(format!(
Expand All @@ -159,7 +159,7 @@ impl Client {
/// View all disruptions for a particular stop
pub async fn disruptions_stop(
&self,
stop_id: i32,
stop_id: StopId,
options: DisruptionsSpecificOpts,
) -> Result<DisruptionsResponse> {
self.rq(format!(
Expand All @@ -171,7 +171,7 @@ impl Client {
}

/// View a specific disruption
pub async fn disruptions_id(&self, disruption_id: i32) -> Result<Disruption> {
pub async fn disruptions_id(&self, disruption_id: DisruptionId) -> Result<Disruption> {
// TODO: Technically this has Status too but I dont want to
// dupe the struct 17 times
self.rq(format!("v3/disruptions/{}", disruption_id)).await
Expand Down Expand Up @@ -244,7 +244,11 @@ impl Client {
}

// View route name and number for a specific route ID
pub async fn routes_id(&self, route_id: i32, options: RouteIdOpts) -> Result<RoutesIdResponse> {
pub async fn routes_id(
&self,
route_id: RouteId,
options: RouteIdOpts,
) -> Result<RoutesIdResponse> {
self.rq(format!("v3/routes/{}?{}", route_id, to_query(options)))
.await
}
Expand All @@ -258,7 +262,7 @@ impl Client {
}

/// View all trip/service runs for a specific route ID
pub async fn runs_id(&self, run_id: i32, options: RunsIdOpts) -> Result<RunsResponse> {
pub async fn runs_id(&self, run_id: RunId, options: RunsIdOpts) -> Result<RunsResponse> {
self.rq(format!("v3/runs/route/{}?{}", run_id, to_query(options)))
.await
}
Expand All @@ -282,7 +286,7 @@ impl Client {
/// View all trip/service runs for a specific run ID and route type
pub async fn runs_id_type(
&self,
run_id: i32,
run_id: RunId,
route_type: RouteType,
options: RunsIdOpts,
) -> Result<RunsResponse> {
Expand Down
Loading

0 comments on commit 3dcdd22

Please sign in to comment.