Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Structure

Marco Siccardi edited this page Mar 17, 2018 · 11 revisions

Even though the structure is not that complicated and all methods are fully commented, it is quite helpful to understand it before using it.

Handler interfaces

The library uses handlers for getting the different entitiy types from the WordPress API. All handlers are derived from the BaseHandler class, which provides two methods:

public HttpClient SetupClient(DateTime? modifiedSince = null, string userAgent = null, string version = null)
public void SetUserAgent(HttpClient client, string userAgent, string version)

All derived handlers call into the SetupClient method to set up the HttpClient with the "If-Modified-Since"-Header and the "User-Agent"-Header, if values are provided. The SetUserAgent method allows you to modify the "User-Agent"-Header of an existing HttpClient.

Usage

In our MVVM-driven world, we often use Locators. You can either create new instances directly or register the interface with your Locator:

//example: MVVMLight SimpleIoc registration:
SimpleIoc.Default.Register<IPostsHandler>(()=> new PostsHandler(null, "MyAwesomeApp", "1.0.0"));

//example: direct instance creation:
var postsHandler = new PostsHandler(null, "MyAwesomeApp", "1.0.0")

Entity models

WordPressReader Standard converts the raw json-responses into WordPressEntity-Models. There are two types:

  • WordPressEntity<TWordPressEntity>: used for single WordPressEntities, e.g. a single post
  • WordPressEntitySet<TWordPressEntity>: used for lists of WordPressEntities, e.g. a list of posts

Both Model types also provide the raw json string as well as an Error property. Use the Raw property to create your own models or for caching purposes.

Extensibility

Because of their generic implementation, WordPressEntities can easily be used to match your WordPress models (which may differ from the standard implementation this library provides). If you need a Handler for different endpoint, you can easily create one by deriving from the BaseHandler class.

Clone this wiki locally