summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2016-06-06 19:02:46 -0700
committerElmer Thomas <elmer@thinkingserious.com>2016-06-06 19:02:46 -0700
commitb808300d9b9e79234565be52a8cce5bdc458f8ea (patch)
tree2d667baa7f09305da914ffdfbd6359ab020079a9 /lib
parent988698f5b2f114d0a62472b1012edac20e37eca1 (diff)
downloadphp-http-client-b808300d9b9e79234565be52a8cce5bdc458f8ea.zip
php-http-client-b808300d9b9e79234565be52a8cce5bdc458f8ea.tar.gz
php-http-client-b808300d9b9e79234565be52a8cce5bdc458f8ea.tar.bz2
Version Bump v3.0.0: Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.bodyv3.0.0
Diffstat (limited to 'lib')
-rw-r--r--lib/SendGrid/Client.php54
-rw-r--r--lib/SendGrid/Config.php36
2 files changed, 27 insertions, 63 deletions
diff --git a/lib/SendGrid/Client.php b/lib/SendGrid/Client.php
index 805ff45..860501c 100644
--- a/lib/SendGrid/Client.php
+++ b/lib/SendGrid/Client.php
@@ -1,5 +1,5 @@
<?php
-/**
+/**
* HTTP Client library
*
* PHP version 5.2
@@ -28,10 +28,10 @@ class Response
function __construct($status_code = null, $response_body = null, $response_headers = null)
{
$this->_status_code = $status_code;
- $this->_response_body = $response_body;
- $this->_response_headers = $response_headers;
+ $this->_body = $response_body;
+ $this->_headers = $response_headers;
}
-
+
/**
* The status code
*
@@ -47,9 +47,9 @@ class Response
*
* @return array
*/
- public function responseBody()
+ public function body()
{
- return $this->_response_body;
+ return $this->_body;
}
/**
@@ -57,9 +57,9 @@ class Response
*
* @return array
*/
- public function responseHeaders()
+ public function headers()
{
- return $this->_response_headers;
+ return $this->_headers;
}
}
@@ -68,14 +68,14 @@ class Response
*/
class Client
{
-
- public
+
+ public
$host,
$request_headers,
$version,
$url_path,
- $methods;
-
+ $methods;
+
/**
* Initialize the client
*
@@ -83,7 +83,7 @@ class Client
* @param array $request_headers global request headers
* @param string $version api version (configurable)
* @param array $url_path holds the segments of the url path
- */
+ */
function __construct($host, $request_headers = null, $version = null, $url_path = null)
{
$this->host = $host;
@@ -110,7 +110,7 @@ class Client
$this->url_path = [];
return new Client($this->host, $this->request_headers, $this->version, $url_path);
}
-
+
/**
* Subclass this function for your own needs.
* Or just pass the version as part of the URL
@@ -120,7 +120,7 @@ class Client
*
* @return string
*/
- private function _buildVersionedUrl($url)
+ private function _buildVersionedUrl($url)
{
return sprintf("%s%s%s", $this->host, $this->version, $url);
}
@@ -129,10 +129,10 @@ class Client
* Build the final URL to be passed
*
* @param array $query_params an array of all the query parameters
- *
+ *
* @return string
*/
- private function _buildUrl($query_params = null)
+ private function _buildUrl($query_params = null)
{
$url = '/'.implode('/', $this->url_path);
if (isset($query_params)) {
@@ -155,10 +155,10 @@ class Client
* @param string $url the final url to call
* @param array $request_body request body
* @param array $request_headers any additional request headers
- *
+ *
* @return Response object
*/
- public function makeRequest($method, $url, $request_body = null, $request_headers = null)
+ public function makeRequest($method, $url, $request_body = null, $request_headers = null)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
@@ -179,9 +179,9 @@ class Client
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$response_body = substr($curl_response, $header_size);
$response_header = substr($curl_response, 0, $header_size);
-
+
curl_close($curl);
-
+
return new Response($status_code, $response_body, $response_header);
}
@@ -192,10 +192,10 @@ class Client
* in your url, you must use this method.
*
* @param string $name name of the url segment
- *
+ *
* @return Client object
*/
- public function _($name = null)
+ public function _($name = null)
{
return $this->_buildClient($name);
}
@@ -206,16 +206,16 @@ class Client
*
* @param string $name name of the dynamic method call or HTTP verb
* @param array $args parameters passed with the method call
- *
+ *
* @return Client or Response object
*/
public function __call($name, $args)
- {
+ {
if($name == 'version') {
$this->version = $args[0];
return $this->_();
}
-
+
if (in_array($name, $this->methods)) {
$query_params = ((count($args) >= 2) ? $args[1] : null);
$url = $this->_buildUrl($query_params);
@@ -223,7 +223,7 @@ class Client
$request_headers = ((count($args) == 3) ? $args[2] : null);
return $this->makeRequest($name, $url, $request_body, $request_headers);
}
-
+
return $this->_($name);
}
}
diff --git a/lib/SendGrid/Config.php b/lib/SendGrid/Config.php
deleted file mode 100644
index 5c4383e..0000000
--- a/lib/SendGrid/Config.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/**
- * Environment Variable Configuration
- *
- * PHP version 5.2
- *
- * @author Matt Bernier <dx@sendgrid.com>
- * @author Elmer Thomas <dx@sendgrid.com>
- * @copyright 2016 SendGrid
- * @license https://opensource.org/licenses/MIT The MIT License
- * @version GIT: <git_id>
- * @link http://packagist.org/packages/sendgrid/php-http-client
- */
-namespace SendGrid;
-
-/**
- * Sets environment variables.
- */
-class Config
-{
- /**
- * Setup the environment variables
- *
- * @param string $base_path path to your config file.
- * @param string $config_filename name of the config file.
- */
- function __construct($base_path, $config_filename)
- {
- $handle = fopen($base_path.'/'.$config_filename, "r");
- while (($line = fgets($handle)) !== false) {
- putenv(trim(preg_replace('/\s+/', ' ', $line)));
- }
- fclose($handle);
- }
-}
-?>