websharks/wp-kb-articles — pull request #11 by brucewsinc (2014-12-29 18:02:24+00:00)
Title: Class for GitHub API

Referencing #2

## Checklist

The class leverages the [GitHub REST API](https://developer.github.com/v3/) via [WP_Http](http://codex.wordpress.org/HTTP_API). The class only uses 3 endpoints and therefore the use of one of the (unofficial) GitHub SDK libraries has been skipped.

- [ ] Ability to get a recursive list of `.md` files from a GitHub Repo
- [x] Via the `?recursive=1` parameter in the `api.github.com` endpoint
- [ ] Manually by recursively querying trees
- [x] Authentication
- [x] Organization/Owner & Repo Selection
- [x] Ability to download file data
- [x] Via SHA key from tree query
- [x] Via `path` relative to repository root
- [x] YAML header parsing
- [ ] Status Code checking
- [x] `return FALSE;` on error
- [ ] Logging and/or debugging

## Info

This class is reusable and can be used for multiple queries to the same, or different repositories using the same authentication method.

### Usage

```php
$git_api = new \wp_kb_articles\github_api;
$git_api->set_owner('repo_owner');
$git_api->set_repo('repo');
// $git_api->set_branch('000000-dev'); // (optional, defaults to the repo's default branch)
// $git_api->authenticate('user', 'password_or_api_key'); // (optional, will allow for up to 5000 requests, hourly, instead of 60)

// $posts = $git_api->retrieve_posts(); // To retrieve all Markdown file info without Post body or content
$posts = $git_api->retrieve_posts(true); // To retrieve all Markdown files with YAML headers and content

// $post = $git_api->retrieve_post('/path/to/file'); // To retrieve a single Post
```