Skip to content

Commit

Permalink
Merge pull request #38 from jpsingleton/darwin-3-6
Browse files Browse the repository at this point in the history
Darwin 3.6
  • Loading branch information
jpsingleton committed Jul 27, 2015
2 parents 33e3e91 + 0f320c0 commit c385fd3
Show file tree
Hide file tree
Showing 28 changed files with 2,639 additions and 782 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ You can set `DarwinAccessToken` to your NRE access token. If you leave `ClientAc

### URL Format

The URL format is `{board}/{CRS|StationName}/{filterType}/{filterCRS|StationName}/{numRows}` or `{board}/{CRS|StationName}/{numRows}` where only board and CRS (or a station name) are required. The filter type can be either `to` or `from` (case is not important).
The URL format is `{board}/{CRS|StationName}/{filterType}/{filterCRS|StationName}/{numRows}` or `{board}/{CRS|StationName}/{numRows}` (arrivals/departures only) where only board and CRS (or a station name) are required. The filter type can be either `to` or `from` (case is not important).

A station name can be used in place of CRS codes if the name matches only one station (or matches one exactly) but case is not important. See the [CRS section](#crs-station-codes) below for more information.

For all boards you can add an `expand=true` parameter to embed all service details into the board response.

[`/all/{CRS|StationName}?accessToken={token}&expand=true`](https://huxley.apphb.com/all/crs?accessToken=DA1C7740-9DA0-11E4-80E6-A920340000B1&expand=true)

Examples:

* 10 (default value) Arrivals and Departures at Clapham Junction: `/all/clj`
Expand All @@ -81,15 +85,27 @@ Examples:

### Departures

[`/departures/{Three letter CRS station code}?accessToken={Your GUID token}`](https://huxley.apphb.com/departures/crs?accessToken=)
[`/departures/{CRS|StationName}/{filterType}/{filterCRS|StationName}`](https://huxley.apphb.com/departures/crs?accessToken=DA1C7740-9DA0-11E4-80E6-A920340000B1)

### Arrivals

[`/arrivals/{Three letter CRS station code}?accessToken={Your GUID token}`](https://huxley.apphb.com/arrivals/crs?accessToken=)
[`/arrivals/{CRS|StationName}/{filterType}/{filterCRS|StationName}`](https://huxley.apphb.com/arrivals/crs?accessToken=DA1C7740-9DA0-11E4-80E6-A920340000B1)

### Departures and Arrivals

[`/all/{Three letter CRS station code}?accessToken={Your GUID token}`](https://huxley.apphb.com/all/crs?accessToken=)
[`/all/{CRS|StationName}/{filterType}/{filterCRS|StationName}`](https://huxley.apphb.com/all/crs?accessToken=DA1C7740-9DA0-11E4-80E6-A920340000B1)

### Next

[`/next/{CRS|StationName}/{filterType}/{filterCRSs|StationNames}`](https://huxley.apphb.com/next/crs/to/edb?accessToken=DA1C7740-9DA0-11E4-80E6-A920340000B1)

Filter stations can be a comma separated list. Filter type and number of rows are ignored.

### Fastest

[`/fastest/{CRS|StationName}/{filterType}/{filterCRSs|StationNames}`](https://huxley.apphb.com/fastest/crs/to/edb?accessToken=DA1C7740-9DA0-11E4-80E6-A920340000B1)

Filter stations can be a comma separated list. Filter type and number of rows are ignored.

### Service

Expand Down
48 changes: 41 additions & 7 deletions src/Huxley/Controllers/StationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using Huxley.Models;
Expand All @@ -31,26 +32,59 @@ public StationController(ILdbClient client)
}

// GET /{board}/CRS?accessToken=[your token]
public async Task<StationBoard> Get([FromUri] StationBoardRequest request) {
public async Task<BaseStationBoard> Get([FromUri] StationBoardRequest request) {

// Process CRS codes
request.Crs = MakeCrsCode(request.Crs);
request.FilterCrs = MakeCrsCode(request.FilterCrs);
// Lookup CRS codes from station names
var crs = MakeCrsCode(request.Crs);
var filterList = new[] { "" };
if (!string.IsNullOrWhiteSpace(request.FilterCrs)) {
filterList = request.FilterCrs.Split(',').Select(MakeCrsCode).ToArray();
}

var token = MakeAccessToken(request.AccessToken);

if (Board.Departures == request.Board) {
var departures = await Client.GetDepartureBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0);
if (request.Expand) {
var departuresWithDetails = await Client.GetDepBoardWithDetailsAsync(token, request.NumRows, crs, filterList[0], request.FilterType, 0, 0);
return departuresWithDetails.GetStationBoardResult;
}
var departures = await Client.GetDepartureBoardAsync(token, request.NumRows, crs, filterList[0], request.FilterType, 0, 0);
return departures.GetStationBoardResult;
}

if (Board.Arrivals == request.Board) {
var arrivals = await Client.GetArrivalBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0);
if (request.Expand) {
var arrivalsWithDetails = await Client.GetArrBoardWithDetailsAsync(token, request.NumRows, crs, filterList[0], request.FilterType, 0, 0);
return arrivalsWithDetails.GetStationBoardResult;
}
var arrivals = await Client.GetArrivalBoardAsync(token, request.NumRows, crs, filterList[0], request.FilterType, 0, 0);
return arrivals.GetStationBoardResult;
}

if (Board.Next == request.Board) {
if (request.Expand) {
var nextWithDetails = await Client.GetNextDeparturesWithDetailsAsync(token, crs, filterList, 0, 0);
return nextWithDetails.DeparturesBoard;
}
var next = await Client.GetNextDeparturesAsync(token, crs, filterList, 0, 0);
return next.DeparturesBoard;
}

if (Board.Fastest == request.Board) {
if (request.Expand) {
var nextWithDetails = await Client.GetFastestDeparturesWithDetailsAsync(token, crs, filterList, 0, 0);
return nextWithDetails.DeparturesBoard;
}
var next = await Client.GetFastestDeparturesAsync(token, crs, filterList, 0, 0);
return next.DeparturesBoard;
}

// Default all (departures and arrivals board)
var board = await Client.GetArrivalDepartureBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0);
if (request.Expand) {
var boardWithDetails = await Client.GetArrDepBoardWithDetailsAsync(token, request.NumRows, crs, filterList[0], request.FilterType, 0, 0);
return boardWithDetails.GetStationBoardResult;
}
var board = await Client.GetArrivalDepartureBoardAsync(token, request.NumRows, crs, filterList[0], request.FilterType, 0, 0);
return board.GetStationBoardResult;
}
}
Expand Down
47 changes: 40 additions & 7 deletions src/Huxley/Huxley.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
<Content Include="ms-icon-310x310.png" />
<Content Include="ms-icon-70x70.png" />
<Content Include="NRE_Powered_logo.png" />
<Content Include="Service References\ldbServiceReference\configuration91.svcinfo" />
<Content Include="Service References\ldbServiceReference\configuration.svcinfo" />
<None Include="Service References\ldbServiceReference\configuration91.svcinfo" />
<None Include="Service References\ldbServiceReference\configuration.svcinfo" />
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetArrivalBoardResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
Expand All @@ -191,14 +191,44 @@
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.StationBoard.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Reference.svcmap">
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.DeparturesBoard.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.DeparturesBoardWithDetails.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetArrBoardWithDetailsResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetArrDepBoardWithDetailsResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetDepBoardWithDetailsResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetFastestDeparturesResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetFastestDeparturesWithDetailsResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetNextDeparturesResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.GetNextDeparturesWithDetailsResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<Content Include="Service References\ldbServiceReference\Huxley.ldbServiceReference.StationBoardWithDetails.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</Content>
<None Include="Service References\ldbServiceReference\Reference.svcmap">
<Generator>WCF Proxy Generator</Generator>
<LastGenOutput>Reference.cs</LastGenOutput>
</Content>
</None>
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
<Content Include="Service References\ldbServiceReference\darwin_token_types_2013-11-28.wsdl" />
<None Include="Service References\ldbServiceReference\darwin_token_types_2013-11-28.wsdl" />
<Content Include="RailReferences.csv" />
<Content Include="manifest.json" />
<None Include="Service References\ldbServiceReference\darwin_token_types_2013-11-28.xsd">
Expand All @@ -210,11 +240,14 @@
<None Include="Service References\ldbServiceReference\RTTI_2012-01-13_ldb_types.xsd">
<SubType>Designer</SubType>
</None>
<Content Include="Service References\ldbServiceReference\rtti_2014-02-20_ldb.wsdl" />
<None Include="Service References\ldbServiceReference\RTTI_2014-02-20_ldb_types.xsd">
<SubType>Designer</SubType>
</None>
<Content Include="Service References\ldbServiceReference\wsdl.wsdl" />
<None Include="Service References\ldbServiceReference\rtti_2015-05-14_ldb.wsdl" />
<None Include="Service References\ldbServiceReference\RTTI_2015-05-15_ldb_types.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Service References\ldbServiceReference\wsdl1.wsdl" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand Down
48 changes: 45 additions & 3 deletions src/Huxley/ILdbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,51 @@ You should have received a copy of the GNU Affero General Public License

namespace Huxley {
public interface ILdbClient {
Task<GetDepartureBoardResponse> GetDepartureBoardAsync(AccessToken accessToken, ushort numRows, string crs, string filterCrs, FilterType filterType, int timeOffset, int timeWindow);
Task<GetArrivalBoardResponse> GetArrivalBoardAsync(AccessToken accessToken, ushort numRows, string crs, string filterCrs, FilterType filterType, int timeOffset, int timeWindow);
Task<GetArrivalDepartureBoardResponse> GetArrivalDepartureBoardAsync(AccessToken accessToken, ushort numRows, string crs, string filterCrs, FilterType filterType, int timeOffset, int timeWindow);
Task<GetDepartureBoardResponse> GetDepartureBoardAsync(AccessToken accessToken, ushort numRows, string crs,
string filterCrs, FilterType filterType, int timeOffset,
int timeWindow);

Task<GetDepBoardWithDetailsResponse> GetDepBoardWithDetailsAsync(AccessToken accessToken, ushort numRows,
string crs, string filterCrs,
FilterType filterType, int timeOffset,
int timeWindow);

Task<GetArrivalBoardResponse> GetArrivalBoardAsync(AccessToken accessToken, ushort numRows, string crs,
string filterCrs, FilterType filterType, int timeOffset,
int timeWindow);

Task<GetArrBoardWithDetailsResponse> GetArrBoardWithDetailsAsync(AccessToken accessToken, ushort numRows,
string crs, string filterCrs,
FilterType filterType, int timeOffset,
int timeWindow);

Task<GetArrivalDepartureBoardResponse> GetArrivalDepartureBoardAsync(AccessToken accessToken, ushort numRows,
string crs, string filterCrs,
FilterType filterType, int timeOffset,
int timeWindow);

Task<GetArrDepBoardWithDetailsResponse> GetArrDepBoardWithDetailsAsync(AccessToken accessToken, ushort numRows,
string crs, string filterCrs,
FilterType filterType, int timeOffset,
int timeWindow);

Task<GetNextDeparturesResponse> GetNextDeparturesAsync(AccessToken accessToken, string crs, string[] filterList,
int timeOffset, int timeWindow);

Task<GetNextDeparturesWithDetailsResponse> GetNextDeparturesWithDetailsAsync(AccessToken accessToken, string crs,
string[] filterList, int timeOffset,
int timeWindow);

Task<GetFastestDeparturesResponse> GetFastestDeparturesAsync(AccessToken accessToken, string crs,
string[] filterList, int timeOffset,
int timeWindow);

Task<GetFastestDeparturesWithDetailsResponse> GetFastestDeparturesWithDetailsAsync(AccessToken accessToken,
string crs, string[] filterList,
int timeOffset,
int timeWindow);


Task<GetServiceDetailsResponse> GetServiceDetailsAsync(AccessToken accessToken, string serviceId);
}
}
Loading

0 comments on commit c385fd3

Please sign in to comment.