Add auth
This commit is contained in:
parent
2b1150483e
commit
9a6bbf8c18
|
|
@ -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);
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue