Skip to content

Instantly share code, notes, and snippets.

@kimpepper
Last active August 29, 2015 13:57
Show Gist options
  • Save kimpepper/9756473 to your computer and use it in GitHub Desktop.
Save kimpepper/9756473 to your computer and use it in GitHub Desktop.
<?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