Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
(+semver: feature) Add support for getting routes by stop id (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuevaskoch authored Nov 1, 2018
1 parent bdd88a1 commit e851eec
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
Expand Down Expand Up @@ -213,4 +213,4 @@ src/Lasticity.Core/obj/Debug/*
tests/Lasticity.IntegrationTests/bin/*
tests/Lasticity.IntegrationTests/obj/Debug/*


.idea/
2 changes: 0 additions & 2 deletions src/Syncromatics.Clients.HoustonMetro.Api/Arrival.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Syncromatics.Clients.HoustonMetro.Api
{
Expand Down
6 changes: 1 addition & 5 deletions src/Syncromatics.Clients.HoustonMetro.Api/ClientSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Syncromatics.Clients.HoustonMetro.Api
namespace Syncromatics.Clients.HoustonMetro.Api
{
public class ClientSettings
{
Expand Down
11 changes: 5 additions & 6 deletions src/Syncromatics.Clients.HoustonMetro.Api/HoustonMetroClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using RestEase;

Expand All @@ -24,9 +22,10 @@ public HoustonMetroClient(ClientSettings clientSettings)
_client = new RestClient(httpClient).For<IHoustonMetroApi>();
}

public Task<Stop> GetArrivalsAsync(int stopId)
{
return _client.GetArrivalsAsync(_settings.ApiKey, stopId);
}
public Task<Response<Arrival>> GetArrivalsAsync(int stopId) =>
_client.GetArrivalsAsync(_settings.ApiKey, stopId);

public Task<Response<Route>> GetRoutesAsync(int stopId) =>
_client.GetRoutesAsync(_settings.ApiKey, stopId);
}
}
12 changes: 7 additions & 5 deletions src/Syncromatics.Clients.HoustonMetro.Api/IHoustonMetroApi.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using RestEase;

Expand All @@ -13,7 +10,12 @@ namespace Syncromatics.Clients.HoustonMetro.Api
internal interface IHoustonMetroApi
{
[Get("data/Stops('MeTrAuOfHaCo_{stopId}')/Arrivals?$format=json")]
Task<Stop> GetArrivalsAsync(
Task<Response<Arrival>> GetArrivalsAsync(
[Header("Ocp-Apim-Subscription-Key")]string apiKey,
[Path]int stopId);

[Get("data/Stops('MeTrAuOfHaCo_{stopId}')/Routes?$format=json")]
Task<Response<Route>> GetRoutesAsync(
[Header("Ocp-Apim-Subscription-Key")]string apiKey,
[Path]int stopId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using RestEase;
using System.Threading.Tasks;

namespace Syncromatics.Clients.HoustonMetro.Api
{
public interface IHoustonMetroClient
{
Task<Stop> GetArrivalsAsync(int stopId);
Task<Response<Arrival>> GetArrivalsAsync(int stopId);
Task<Response<Route>> GetRoutesAsync(int stopId);
}
}
10 changes: 10 additions & 0 deletions src/Syncromatics.Clients.HoustonMetro.Api/Response.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace Syncromatics.Clients.HoustonMetro.Api
{
public class Response<TResult> where TResult : class
{
[JsonProperty("d")]
public ResultSet<TResult> ResultSet { get; set; }
}
}
8 changes: 3 additions & 5 deletions src/Syncromatics.Clients.HoustonMetro.Api/ResultSet.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Syncromatics.Clients.HoustonMetro.Api
{
public class ResultSet
public class ResultSet<TResult> where TResult : class
{
[JsonProperty("results")]
public List<Arrival> Arrivals { get; set; }
public List<TResult> Results { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/Syncromatics.Clients.HoustonMetro.Api/Route.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Syncromatics.Clients.HoustonMetro.Api
{
public class Route
{
public string AgencyAbbreviation { get; set; }
public string LongName { get; set; }
public string RouteId { get; set; }
public string RouteName { get; set; }
public string RouteType { get; set; }
}
}
13 changes: 0 additions & 13 deletions src/Syncromatics.Clients.HoustonMetro.Api/Stop.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,52 @@ public HoustonMetroClientTests()
[InlineData(10055)]
public async Task ShouldGetArrivals(int stopId)
{
Stop result = null;
Response<Arrival> result = null;
await RetryPolicy().ExecuteAsync(async () =>
{
result = await _client.GetArrivalsAsync(stopId);
});

result.Should().NotBeNull();
result.ResultSet.Should().NotBeNull();
result.ResultSet.Arrivals.Should().NotBeNull();
result.ResultSet.Results.Should().NotBeNull();

foreach (var arrival in result.ResultSet.Arrivals) {
foreach (var arrival in result.ResultSet.Results) {
arrival.RouteName.Should().NotBeNullOrEmpty();
arrival.DestinationName.Should().NotBeNullOrEmpty();
}
}

[Theory]
[InlineData(79)]
[InlineData(244)]
[InlineData(661)]
[InlineData(681)]
[InlineData(9045)]
[InlineData(9953)]
[InlineData(10055)]
public async Task ShouldGetRoutes(int stopId)
{
Response<Route> result = null;
await RetryPolicy().ExecuteAsync(async () =>
{
result = await _client.GetRoutesAsync(stopId);
});

result.Should().NotBeNull();
result.ResultSet.Should().NotBeNull();
result.ResultSet.Results.Should().NotBeNull();

foreach (var route in result.ResultSet.Results)
{
route.AgencyAbbreviation.Should().NotBeNullOrEmpty();
route.LongName.Should().NotBeNullOrEmpty();
route.RouteId.Should().NotBeNullOrEmpty();
route.RouteName.Should().NotBeNullOrEmpty();
route.RouteType.Should().NotBeNullOrEmpty();
}
}

private Policy RetryPolicy() =>
Policy
.Handle<RestEase.ApiException>()
Expand Down

0 comments on commit e851eec

Please sign in to comment.