Compare commits

..

1 commit
master ... 2.0

Author SHA1 Message Date
Ben Speakman 747dd85e70 Rename vendor, update guzzle and add test 2016-01-22 12:56:58 +00:00
6 changed files with 15 additions and 97 deletions

View file

@ -1,6 +1,7 @@
language: php language: php
php: php:
- 5.4
- 5.5 - 5.5
- 5.6 - 5.6
- hhvm - hhvm

View file

@ -1,6 +1,6 @@
# laravel-wp-api # laravel-wp-api
[![Build Status](https://travis-ci.org/threesquared/laravel-wp-api.svg?branch=master)](https://travis-ci.org/threesquared/laravel-wp-api) [![Latest Stable Version](https://poser.pugx.org/threesquared/laravel-wp-api/v/stable)](https://packagist.org/packages/threesquared/laravel-wp-api) [![Build Status](https://travis-ci.org/threesquared/laravel-wp-api.svg?branch=master)](https://travis-ci.org/threesquared/laravel-wp-api) [![Latest Stable Version](https://poser.pugx.org/threesquared/laravel-wp-api/version)](https://packagist.org/packages/threesquared/laravel-wp-api)
Laravel 5 package for the [Wordpress JSON REST API](https://github.com/WP-API/WP-API) Laravel 5 package for the [Wordpress JSON REST API](https://github.com/WP-API/WP-API)
@ -12,7 +12,11 @@ Simply add the following line to your `composer.json` and run install/update:
## Configuration ## Configuration
You will need to add the service provider and optionally the facade alias to your `config/app.php`: Publish the package config files to configure the location of your Wordpress install:
php artisan vendor:publish
You will also need to add the service provider and optionally the facade alias to your `app/config/app.php`:
```php ```php
'providers' => array( 'providers' => array(
@ -24,10 +28,6 @@ You will need to add the service provider and optionally the facade alias to you
), ),
``` ```
And publish the package config files to configure the location of your Wordpress install:
php artisan vendor:publish
### Usage ### Usage
The package provides a simplified interface to some of the existing api methods documented [here](http://wp-api.org/). The package provides a simplified interface to some of the existing api methods documented [here](http://wp-api.org/).
@ -51,11 +51,6 @@ WpApi::post($slug);
``` ```
```php
WpApi::postId($id);
```
#### Categories #### Categories
```php ```php
WpApi::categories(); WpApi::categories();

View file

@ -10,8 +10,8 @@
} }
], ],
"require": { "require": {
"php": ">=5.5.0", "php": ">=5.4.0",
"illuminate/support": "~5.2", "illuminate/support": "~5.0",
"guzzlehttp/guzzle": "~6.0" "guzzlehttp/guzzle": "~6.0"
}, },
"require-dev": { "require-dev": {

View file

@ -1,10 +1,9 @@
<?php namespace Threesquared\LaravelWpApi\Facades; <?php namespace Threesquared\LaravelWpApi\Facades;
use Illuminate\Support\Facades\Facade; use Illuminate\Support\Facades\Facade;
use Threesquared\LaravelWpApi\WpApi as WordpressApi;
class WpApi extends Facade { class WpApi extends Facade {
protected static function getFacadeAccessor() { return WordpressApi::class; } protected static function getFacadeAccessor() { return 'wp-api'; }
} }

View file

@ -31,7 +31,7 @@ class LaravelWpApiServiceProvider extends ServiceProvider
*/ */
public function register() public function register()
{ {
$this->app->singleton(WpApi::class, function ($app) { $this->app->bindShared('wp-api', function ($app) {
$endpoint = $this->app['config']->get('wp-api.endpoint'); $endpoint = $this->app['config']->get('wp-api.endpoint');
$auth = $this->app['config']->get('wp-api.auth'); $auth = $this->app['config']->get('wp-api.auth');
@ -40,6 +40,10 @@ class LaravelWpApiServiceProvider extends ServiceProvider
return new WpApi($endpoint, $client, $auth); return new WpApi($endpoint, $client, $auth);
}); });
$this->app->bind('Threesquared\LaravelWpApi\WpApi', function ($app) {
return $app['wp-api'];
});
} }
/** /**

View file

@ -38,137 +38,56 @@ class WpApi
$this->auth = $auth; $this->auth = $auth;
} }
/**
* Get all posts
*
* @param int $page
* @return array
*/
public function posts($page = null) public function posts($page = null)
{ {
return $this->get('posts', ['page' => $page]); return $this->get('posts', ['page' => $page]);
} }
/**
* Get all pages
*
* @param int $page
* @return array
*/
public function pages($page = null) public function pages($page = null)
{ {
return $this->get('posts', ['type' => 'page', 'page' => $page]); return $this->get('posts', ['type' => 'page', 'page' => $page]);
} }
/**
* Get post by id
*
* @param int $id
* @return array
*/
public function postId($id)
{
return $this->get("posts/$id");
}
/**
* Get post by slug
*
* @param string $slug
* @return array
*/
public function post($slug) public function post($slug)
{ {
return $this->get('posts', ['filter' => ['name' => $slug]]); return $this->get('posts', ['filter' => ['name' => $slug]]);
} }
/**
* Get page by slug
*
* @param string $slug
* @return array
*/
public function page($slug) public function page($slug)
{ {
return $this->get('posts', ['type' => 'page', 'filter' => ['name' => $slug]]); return $this->get('posts', ['type' => 'page', 'filter' => ['name' => $slug]]);
} }
/**
* Get all categories
*
* @return array
*/
public function categories() public function categories()
{ {
return $this->get('taxonomies/category/terms'); return $this->get('taxonomies/category/terms');
} }
/**
* Get all tags
*
* @return array
*/
public function tags() public function tags()
{ {
return $this->get('taxonomies/post_tag/terms'); return $this->get('taxonomies/post_tag/terms');
} }
/**
* Get posts from category
*
* @param string $slug
* @param int $page
* @return array
*/
public function categoryPosts($slug, $page = null) public function categoryPosts($slug, $page = null)
{ {
return $this->get('posts', ['page' => $page, 'filter' => ['category_name' => $slug]]); return $this->get('posts', ['page' => $page, 'filter' => ['category_name' => $slug]]);
} }
/**
* Get posts by author
*
* @param string $name
* @param int $page
* @return array
*/
public function authorPosts($name, $page = null) public function authorPosts($name, $page = null)
{ {
return $this->get('posts', ['page' => $page, 'filter' => ['author_name' => $name]]); return $this->get('posts', ['page' => $page, 'filter' => ['author_name' => $name]]);
} }
/**
* Get posts tagged with tag
*
* @param string $tags
* @param int $page
* @return array
*/
public function tagPosts($tags, $page = null) public function tagPosts($tags, $page = null)
{ {
return $this->get('posts', ['page' => $page, 'filter' => ['tag' => $tags]]); return $this->get('posts', ['page' => $page, 'filter' => ['tag' => $tags]]);
} }
/**
* Search posts
*
* @param string $query
* @param int $page
* @return array
*/
public function search($query, $page = null) public function search($query, $page = null)
{ {
return $this->get('posts', ['page' => $page, 'filter' => ['s' => $query]]); return $this->get('posts', ['page' => $page, 'filter' => ['s' => $query]]);
} }
/**
* Get posts by date
*
* @param int $year
* @param int $month
* @param int $page
* @return array
*/
public function archive($year, $month, $page = null) public function archive($year, $month, $page = null)
{ {
return $this->get('posts', ['page' => $page, 'filter' => ['year' => $year, 'monthnum' => $month]]); return $this->get('posts', ['page' => $page, 'filter' => ['year' => $year, 'monthnum' => $month]]);