The API is broken down into a few objects:
  • GwApi - The public static class that exposes methods to obtain GW2 API Objects
  • ResponseObject - The Base class for all GW2 API Objects. This provides specific functions used for caching and identifying different api responses.
  • IApiRequest - This provides a way to build the appropriate url for a given GW2 API. There are currently 2 implementations
    • ApiRequest - builds all basic .json object urls
    • RenderServiceRequest - builds Render Service urls to image files (currently .jpeg or .png)
  • INetworkHandler - This handles network resources that retrieves raw GW2 api responses (.json, .jpg, .png etc...). There are currently 2 implementations:
    • NetworkHandler - Handles most basic json responses.
    • RenderServicesNetworkHandler - Handles the render services GW2 api responses.
  • ResponseCache - Caches a ResponseObject for later retrieval.
  • ICacheStrategy - This is the interface that a ResponseObject will use to determine if it has expired. There are currently 4 implementations:
    • AgeCacheStrategy - A maximum age is set when this object is created. When a ResponseObject.Age is greater than the set maximum age, this strategy will expire the ResponseObject.
    • BuildVersionCacheStrategy - This is especially useful for static data responses such as maps.json, eventnames.json, mapnames.json etc... This will expire a cached object if the current build version is different than the build version at the time the ResponseObject was created. Each time a ResponseObject is created, the current build version is set for that ResponseObject and cached along with the object in ResponseCache. If there is another request for the same ResponseObject, and the build version for the cached object is different than the current, it will be considered expired and a new ResponseObject is be retrived.
    • DayOfWeekStrategy - This will expire an object if the last retrieval occurred before the given day of the week. For example if the DayOfWeek is set to Tuesday, then any cached object with a date older than the most recent Tuesday will be considered expired.
    • NullCacheStrategy - Used to ensure a ICacheStrategy always exists and never throws an exception. Currently NullCacheStrategy assumes the object has not expired. This may change in future updates.
  • IApiResponseParser - Every ResponseObject would have a corresponding parser. The parser is used to parse the particular GW2 api response into a ResponseObject.
  • IApiResponseHandler - This is where everything is glued together. All GwApi calls will use a response handler except for 1, GetBuildNumber(). This brings everything together: using the ResponseCache to determine if a valid ResponseObject is available; using the INetworkHandler and IApiRequest to obtain the raw GW2 API json object if cached object is not available or has expired; using the specified IApiResponseParser to parse the response from INetworkHandler to create a ResponseObject; then caching the object in the ResponseCache and returning the requested object to the GwApi caller. There is currently 1 implementation:
    • ApiResponseHandler - currently handles all GwApi responses except GetBuildNumber(...). This is a great place for debugging as it is the focal point where just about everything is happening.

Last edited Aug 20, 2013 at 5:14 AM by prbarcelon, version 2

Comments

No comments yet.