Git Product home page Git Product logo

ljsyournextbus's Introduction

LJSYourNextBus

Objective-C wrapper for the "Get There Sooner" live departure information service from from Travel South Yorkshire Transport. Scrapes data from http://gettheresooner.travelsouthyorkshire.com/MobileNaptan.aspx

(NOTE: Previously the data was obtained by scraping the YourNextBus service, however this no longer works. This cocoapod gets it's name from that.)

NaPTAN Code

In the UK every public transport stop (Bus, Tram, Train etc) is a known as a "National Public Transport Access Node". Each of these nodes is given a unique identifier: an 8 digit number called a NaPTANCode. More information here: https://www.gov.uk/government/publications/national-public-transport-access-node-schema

Usage

To obtain live data for a stop, the NaPTAN code is specified to a LJSYourNextBusClient object for either South or West Yorkshire. South Yorkshire codes begin with "310" and West Yorkshire code being with "450". Use the correct subclass for your needs: either LJSSouthYorkshireClient or LJSWestYorkshireClient. These subclasses construct a URL to the live data for a specific region. This URL is used by the base LJSYourNextBusClient to get live data.

Note: do not create and use instances of LJSYourNextBusClient directly. Either use a LJSSouthYorkshireClient or LJSWestYorkshireClient instance or create a custom subclass yourself, overriding the method to construct the URL to the live data.

// LJSSouthYorkshireClient or LJSWestYorkshireClient
LJSYourNextBusClient *client = [LJSSouthYorkshireClient new];
client.clientDelegate = self;

[client getLiveDataForNaPTANCode:@"37010200"];

#pragma mark - LJSYourNextBusStopDelegate

- (void)client:(LJSYourNextBusClient *)client failedWithError:(NSError *)error NaPTANCode:(NSString *)NaPTANCode {
	NSLog(@"Failed to get live data for NaPTAN: %@ with error: %@", NaPTANCode, error);
}

- (void)client:(LJSYourNextBusClient *)client returnedLiveDataResult:(LJSLiveDataResult *)result {
	LJSStop *stop = result.stop;
	NSLog(@"Live Data for: %@ %@", stop.NaPTANCode, stop.title);
	for (LJSDeparture *departure in [stop sortedDepartures]) {
		NSLog(@"\t%@ at %@", departure.service.title, departure.countdownString);
	}
	
	/*
	 *	Prints:
	 *	37010200 Meadowhall Intc at 2015-08-01 6:15:00 PM +0000
	 *		X78 at Due → Sheffield Intc
	 *		76 at Due → Low Edges
	 *		X78 at 3 Mins → Sheffield Intc
	 *		38 at 5 Mins → Jordanthorpe
	 *		38 at 18 Mins → Sheffield Intc
	 *		X78 at 6:40 PM → Sheffield Intc
	 *		35 at 6:40 PM → Hillsborough Intc
	 */
}


Object Graph

Data model.

┌───────────────┐                                                       ┌───────────────────────────┐
│Stop           │                 ┌───────────────┐                     │Departure                  │
│ - NaPTANCode  │                 │Service        │                     │ - destination             │
│ - title       │                 │ - title       │                     │ - expectedDepartureDate   │
│ - liveDate    │────services────▶│ - stop        │──────departures────▶│ - countdownString         │
│ - laterURL    │                 │ - departures  │                     │ - minutesUntilDeparture   │
│ - earlierURL  │                 └───────────────┘                     │ - hasLowFloorAccess       │
│ - services    │                                                       │ - service                 │
└───────────────┘                                                       └───────────────────────────┘

Example of the instantiated objects from the above example for Meadowhall Intc.

                                                                 ┌─────────────────────┐
┌──────────────────────┐                                         │Departure            │
│Stop                  │        ┌───────────────────┐            │ - Sheffield Intc    │
│ - 37010200           │        │Service            │            │ - 6:15 PM           │
│ - Meadowhall Intc    │───┬───▶│ - X78             ├─────┬─────▶│ - Due               │
│ - 31/07/14 6:00 PM   │   │    │ - Meadowhall Intc │     │      │ - 0                 │
└──────────────────────┘   │    └───────────────────┘     │      │ - X78               │
                           │                              │      └─────────────────────┘
                           │                              │      ┌─────────────────────┐
                           │                              │      │Departure            │
                           │                              │      │ - Sheffield Intc    │
                           │                              │      │ - 6:18 PM           │
                           │                              ├─────▶│ - 3 Mins            │
                           │                              │      │ - 3                 │
                           │                              │      │ - X78               │
                           │                              │      └─────────────────────┘
                           │                              │      ┌─────────────────────┐
                           │                              │      │Departure            │
                           │                              │      │ - Sheffield Intc    │
                           │                              │      │ - 6:40 PM           │
                           │                              └─────▶│ - 6:40 PM           │
                           │                                     │ - 25                │
                           │                                     │ - X78               │
                           │                                     └─────────────────────┘
                           │                                     ┌─────────────────────┐
                           │                                     │Departure            │
                           │   ┌───────────────────┐             │ - Low Edges         │
                           │   │Service            │             │ - 6:15 PM           │
                           ├──▶│ - 76              │────────────▶│ - Due               │
                           │   │ - Meadowhall Intc │             │ - 0                 │
                           │   └───────────────────┘             │ - 76                │
                           │                                     └─────────────────────┘
                           │                                     ┌─────────────────────┐
                           │                                     │Departure            │
                           │   ┌───────────────────┐             │ - Jordanthorpe      │
                           │   │Service            │             │ - 6:20 PM           │
                           ├──▶│ - 38              │──────┬─────▶│ - 5 Mins            │
                           │   │ - Meadowhall Intc │      │      │ - 5                 │
                           │   └───────────────────┘      │      │ - 38                │
                           │                              │      └─────────────────────┘
                           │                              │      ┌─────────────────────┐
                           │                              │      │Departure            │
                           │                              │      │ - Sheffield Intc    │
                           │                              │      │ - 6:33 PM           │
                           │                              └─────▶│ - 18 Mins           │
                           │                                     │ - 18                │
                           │                                     │ - 38                │
                           │                                     └─────────────────────┘
                           │                                     ┌─────────────────────┐
                           │                                     │Departure            │
                           │    ┌───────────────────┐            │ - Hillsborough Intc │
                           │    │Service            │            │ - 6:40 PM           │
                           └───▶│ - 35              │───────────▶│ - 25 Mins           │
                                │ - Meadowhall Intc │            │ - 25                │
                                └───────────────────┘            │ - 35                │
                                                                 └─────────────────────┘

ljsyournextbus's People

Contributors

lukestringer90 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.