close
The Wayback Machine - https://web.archive.org/web/20221226000039/https://github.com/automattic/grasshopper
Skip to content

Automattic/grasshopper

gh-pages
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

grasshopper

A WordPress.com REST API + D3.js example

This is a simple demo app that uses the WordPress.com REST API to graph a site's recent views using D3.js / C3.js.

See it in action here!

Screenshot

Authentication

The app uses implicit oAuth to retrieve a token via the oAuth flow without having to store a secret.

This token is returned in the URL when the oAuth flow redirects back to our app. Since we've requested scope for a single site, the Site ID is also returned as a URL parameter.

Loading Data

Using the d3.json() function, we can use the token to make an authenticated request to the /stats endpoint of the REST API.

The token is passed in an Authorization header:

.header( 'Authorization', 'BEARER ' + decodeURIComponent( token ) )

Graphing The Data

Once the API call returns, we simply pass the returned data to c3.generate() to plot it on a graph.

About

A WordPress.com REST API + D3.js example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages