Last active
August 29, 2015 13:57
-
-
Save kimpepper/9756473 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* @file | |
* Contains lib\Drupal\guzzle_example\GuzzleExample | |
*/ | |
namespace Drupal\guzzle_example; | |
use GuzzleHttp\Client; | |
/** | |
* My GuzzleExample | |
*/ | |
class GuzzleExample { | |
/** | |
* @var \GuzzleHttp\Client | |
* The Guzzle HTTP client. | |
*/ | |
var $client; | |
/** | |
* Creates a new GuzzleExample. | |
* | |
* @param \GuzzleHttp\Client $client | |
* The Guzzle client. | |
*/ | |
public function __construct(Client $client) { | |
$this->client = $client; | |
} | |
/** | |
* Factory method. | |
* @return $this | |
*/ | |
public static function create() { | |
return new static(new Client()); | |
} | |
/** | |
* Finds the host IP address by calling the httpbin web service. | |
* | |
* @return string | |
* The current hosts IP address. | |
*/ | |
public function getHostIP() { | |
$response = $this->client->get('http://httpbin.org/get'); | |
$json = $response->json(); | |
return $json['origin']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment