This commit is contained in:
Ben Speakman 2015-04-14 17:42:33 +01:00
parent 2b1150483e
commit 9a6bbf8c18
2 changed files with 11 additions and 3 deletions

View file

@ -34,9 +34,10 @@ class LaravelWpApiServiceProvider extends ServiceProvider {
$this->app->bindShared('wp-api', function ($app) {
$endpoint = $this->app['config']->get('wp-api.endpoint');
$auth = $this->app['config']->get('wp-api.auth');
$client = new Client();
return new WpApi($endpoint, $client);
return new WpApi($endpoint, $client, $auth);
});

View file

@ -7,10 +7,11 @@ class WpApi
protected $client;
public function __construct($endpoint, Client $client)
public function __construct($endpoint, Client $client, $auth = null)
{
$this->endpoint = $endpoint;
$this->client = $client;
$this->auth = $auth;
}
public function posts($page = null)
@ -73,7 +74,13 @@ class WpApi
try {
$response = $this->client->get($this->endpoint . '/wp-json/' . $method, ['query' => $query]);
$query = ['query' => $query];
if($this->auth) {
$query['auth'] = $this->auth;
}
$response = $this->client->get($this->endpoint . '/wp-json/' . $method, $query);
$return = [
'results' => $response->json(),