GithubHelp home page GithubHelp logo

smithlamar / route_tracker_api Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 111 KB

The RouteTracker API's purpose is to encapsulate calls to the Chicago Transit Authority's bus and train APIs. It creates objects that are more easily consumable for a mobile app. Additionally, it helps cache results to minimize exhausting the limit of calls per day set by the CTA. Deployable format is a fat jar with embedded Tomcat server.

License: GNU General Public License v3.0

Java 100.00%
api cta-api cta-buses chicago-transit-authority bus-tracker-api

route_tracker_api's People

Watchers

 avatar  avatar  avatar

route_tracker_api's Issues

Refactor BustimeAPIRequest class to take advantage of Spring Boot and Jackson automatic deserialization features.

As it stands, all parsing of CTA requests and desirialization of the objects contained within each payload is handled manually (albeit using Jackson core elements). The general goal is to see how far we can get with annotations and either RestTemplate and/or ObjectMapper to handle the deserialization and possibly the calls to the CTA for us.

This would make BustimeAPIRequest more lightweight and easier to reason with overall. The examples I've seen so far of this sort of implementation involve very pretty pojos that get deserialized from the Json response. It seems to get trickier when collections that use generics are the destination for the deserialized response. It gets trickier more so because some of these generic collections are contained within properties of the BusLine objects. A BusLine's directions is a list of Direction objects. Each Direction within BusLine.directions contains a List of Stop objects.

CTA response example:

`	"bustime-response": {
		"routes": [
			{
				"rt": "1",
				"rtnm": "Bronzeville/Union Station",
				"rtclr": "#336633",
				"rtdd": "1"
			},
			{
				"rt": "2",
				"rtnm": "Hyde Park Express",
				"rtclr": "#993366",
				"rtdd": "2"
			},
			{
				"rt": "3",
				"rtnm": "King Drive",
				"rtclr": "#009900",
				"rtdd": "3"
			},
                        ... # more and more routes
                    ]
      }
`

This response ties to what is essentially a List object, but only part of the data required for a complete BusLine object as we've defined it is here. The data for the directions property is retrieved from a different endpoint of the CTA API but we are treating it as just another component of a BusLine. We can probably use @JsonIgnoreProperties(ignoreUnknown=true) to keep the parser from failing where it doesn't find matching properties. We can also set unwrapwroot for deserialization in application.properties to deal with the wrapping "bustime-response" root that is a part of every response.

RestTemplate can theoretically take our class and map the Json response to it in addition to making the request with a supplied URL. The issue is when the class in this case is a generic collection. RestTemplate needs the type information but type erasure gets in the way when generics are involved. This seemed to be an issue that required some inelegant solutions in previous versions of Spring. I need to experiment a bit to figure out how to get this to work well without dirtying up the BusLine class with a ton of Json focused annotations or logic that ultimately is harder to reason with than manually deserializing the response to begin with.

Another concern is that we still need to be able to differentiate payloads from the CTA that contain error messages from those that have payloads that we actually want to build objects from and I haven't seen any indication that we can dig through the response returned from RestTemplate any easier than the way it currently is just by manually sending the request and checking the keys that are present.

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.