-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HttpClient für GuzzleHttp geschrieben
- Loading branch information
Showing
3 changed files
with
64 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Youthweb\Api; | ||
|
||
use GuzzleHttp; | ||
|
||
/** | ||
* Http client based on GuzzleHttp | ||
*/ | ||
class HttpClient implements HttpClientInterface | ||
{ | ||
protected $http_client = null; | ||
|
||
/** | ||
* Creates the http client | ||
* | ||
* @return HttpClient The Http client | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->http_client = new GuzzleHttp\Client(); | ||
} | ||
|
||
/** | ||
* Send a GET request | ||
* | ||
* @param string|array $url URL | ||
* @param array $options Array of request options to apply. | ||
* | ||
* @return mixed | ||
*/ | ||
public function get($url = null, array $options = array()) | ||
{ | ||
$response = $this->http_client->get($url, $options); | ||
|
||
return $response->json(array('object' => true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Youthweb\Api; | ||
|
||
/** | ||
* Http client interface | ||
*/ | ||
interface HttpClientInterface | ||
{ | ||
/** | ||
* Send a GET request | ||
* | ||
* @param string|array $url URL | ||
* @param array $options Array of request options to apply. | ||
* | ||
* @return mixed | ||
*/ | ||
public function get($url = null, array $options = array()); | ||
} |