Skip to content

Commit b808300

Browse files
Version Bump v3.0.0: Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.body
1 parent 988698f commit b808300

File tree

9 files changed

+49
-116
lines changed

9 files changed

+49
-116
lines changed

.env_sample

-4
This file was deleted.

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [3.0.0] - 2016-06-06
7+
### Changed
8+
- Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.body
9+
610
## [2.0.2] - 2016-02-29
711
### Fixed
812
- Renaming files to conform to PSR-0, git ignored the case in 2.0.1

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ $global_headers = array(Authorization: Basic XXXXXXX);
4242
$client = SendGrid\Client('base_url', 'global_headers');
4343
$response = $client->your()->api()->_($param)->call()->get();
4444
print $response->statusCode();
45-
print $response->responseHeaders();
46-
print $response->responseBody();
45+
print $response->headers();
46+
print $response->body();
4747
```
4848

4949
`POST /your/api/{param}/call` with headers, query parameters and a request body with versioning.
@@ -59,8 +59,8 @@ $response = $client->your()->api()->_($param)->call()->post('data',
5959
'query_params',
6060
'request_headers');
6161
print $response->statusCode();
62-
print $response->responseHeaders();
63-
print $response->responseBody();
62+
print $response->headers();
63+
print $response->body();
6464
```
6565

6666
# Usage

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sendgrid/php-http-client",
33
"description": "HTTP REST client, simplified for PHP",
44
"type": "library",
5-
"version": "2.0.2",
5+
"version": "3.0.0",
66
"require-dev": {
77
"phpunit/phpunit": "~4.4",
88
"squizlabs/php_codesniffer": "2.*"

examples/example.php

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
// comment out the two includes below
44
// require __DIR__ . '/vendor/autoload.php';
55
include(dirname(__DIR__).'/lib/SendGrid/client.php');
6-
include(dirname(__DIR__).'/lib/SendGrid/config.php');
76
// This gets the parent directory, for your current directory use getcwd()
87
$path_to_config = dirname(__DIR__);
9-
$config = new SendGrid\Config($path_to_config, '.env');
108
$api_key = getenv('SENDGRID_API_KEY');
119
$headers = array(
1210
'Content-Type: application/json',
@@ -19,8 +17,8 @@
1917
$request_headers = array('X-Mock: 200');
2018
$response = $client->api_keys()->get(null, $query_params, $request_headers);
2119
echo $response->statusCode();
22-
echo $response->responseBody();
23-
echo $response->responseHeaders();
20+
echo $response->body();
21+
echo $response->headers();
2422

2523
// POST
2624
$request_body = array(
@@ -33,25 +31,25 @@
3331
);
3432
$response = $client->api_keys()->post($request_body);
3533
echo $response->statusCode();
36-
echo $response->responseBody();
37-
echo $response->responseHeaders();
38-
$response_body = json_decode($response->responseBody());
34+
echo $response->body();
35+
echo $response->headers();
36+
$response_body = json_decode($response->body());
3937
$api_key_id = $response_body->api_key_id;
4038

4139
// GET Single
4240
$response = $client->version('/v3')->api_keys()->_($api_key_id)->get();
4341
echo $response->statusCode();
44-
echo $response->responseBody();
45-
echo $response->responseHeaders();
42+
echo $response->body();
43+
echo $response->headers();
4644

4745
// PATCH
4846
$request_body = array(
4947
'name' => 'A New Hope'
5048
);
5149
$response = $client->api_keys()->_($api_key_id)->patch($request_body);
5250
echo $response->statusCode();
53-
echo $response->responseBody();
54-
echo $response->responseHeaders();
51+
echo $response->body();
52+
echo $response->headers();
5553

5654
// PUT
5755
$request_body = array(
@@ -63,13 +61,13 @@
6361
);
6462
$response = $client->api_keys()->_($api_key_id)->put($request_body);
6563
echo $response->statusCode();
66-
echo $response->responseBody();
67-
echo $response->responseHeaders();
64+
echo $response->body();
65+
echo $response->headers();
6866

6967
// DELETE
7068
$response = $client->api_keys()->_($api_key_id)->delete();
7169
echo $response->statusCode();
72-
echo $response->responseBody();
73-
echo $response->responseHeaders();
70+
echo $response->body();
71+
echo $response->headers();
7472

7573
?>

lib/SendGrid/Client.php

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**
2+
/**
33
* HTTP Client library
44
*
55
* PHP version 5.2
@@ -28,10 +28,10 @@ class Response
2828
function __construct($status_code = null, $response_body = null, $response_headers = null)
2929
{
3030
$this->_status_code = $status_code;
31-
$this->_response_body = $response_body;
32-
$this->_response_headers = $response_headers;
31+
$this->_body = $response_body;
32+
$this->_headers = $response_headers;
3333
}
34-
34+
3535
/**
3636
* The status code
3737
*
@@ -47,19 +47,19 @@ public function statusCode()
4747
*
4848
* @return array
4949
*/
50-
public function responseBody()
50+
public function body()
5151
{
52-
return $this->_response_body;
52+
return $this->_body;
5353
}
5454

5555
/**
5656
* The response headers
5757
*
5858
* @return array
5959
*/
60-
public function responseHeaders()
60+
public function headers()
6161
{
62-
return $this->_response_headers;
62+
return $this->_headers;
6363
}
6464
}
6565

@@ -68,22 +68,22 @@ public function responseHeaders()
6868
*/
6969
class Client
7070
{
71-
72-
public
71+
72+
public
7373
$host,
7474
$request_headers,
7575
$version,
7676
$url_path,
77-
$methods;
78-
77+
$methods;
78+
7979
/**
8080
* Initialize the client
8181
*
8282
* @param string $host the base url (e.g. https://api.sendgrid.com)
8383
* @param array $request_headers global request headers
8484
* @param string $version api version (configurable)
8585
* @param array $url_path holds the segments of the url path
86-
*/
86+
*/
8787
function __construct($host, $request_headers = null, $version = null, $url_path = null)
8888
{
8989
$this->host = $host;
@@ -110,7 +110,7 @@ private function _buildClient($name = null)
110110
$this->url_path = [];
111111
return new Client($this->host, $this->request_headers, $this->version, $url_path);
112112
}
113-
113+
114114
/**
115115
* Subclass this function for your own needs.
116116
* Or just pass the version as part of the URL
@@ -120,7 +120,7 @@ private function _buildClient($name = null)
120120
*
121121
* @return string
122122
*/
123-
private function _buildVersionedUrl($url)
123+
private function _buildVersionedUrl($url)
124124
{
125125
return sprintf("%s%s%s", $this->host, $this->version, $url);
126126
}
@@ -129,10 +129,10 @@ private function _buildVersionedUrl($url)
129129
* Build the final URL to be passed
130130
*
131131
* @param array $query_params an array of all the query parameters
132-
*
132+
*
133133
* @return string
134134
*/
135-
private function _buildUrl($query_params = null)
135+
private function _buildUrl($query_params = null)
136136
{
137137
$url = '/'.implode('/', $this->url_path);
138138
if (isset($query_params)) {
@@ -155,10 +155,10 @@ private function _buildUrl($query_params = null)
155155
* @param string $url the final url to call
156156
* @param array $request_body request body
157157
* @param array $request_headers any additional request headers
158-
*
158+
*
159159
* @return Response object
160160
*/
161-
public function makeRequest($method, $url, $request_body = null, $request_headers = null)
161+
public function makeRequest($method, $url, $request_body = null, $request_headers = null)
162162
{
163163
$curl = curl_init($url);
164164
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
@@ -179,9 +179,9 @@ public function makeRequest($method, $url, $request_body = null, $request_header
179179
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
180180
$response_body = substr($curl_response, $header_size);
181181
$response_header = substr($curl_response, 0, $header_size);
182-
182+
183183
curl_close($curl);
184-
184+
185185
return new Response($status_code, $response_body, $response_header);
186186
}
187187

@@ -192,10 +192,10 @@ public function makeRequest($method, $url, $request_body = null, $request_header
192192
* in your url, you must use this method.
193193
*
194194
* @param string $name name of the url segment
195-
*
195+
*
196196
* @return Client object
197197
*/
198-
public function _($name = null)
198+
public function _($name = null)
199199
{
200200
return $this->_buildClient($name);
201201
}
@@ -206,24 +206,24 @@ public function _($name = null)
206206
*
207207
* @param string $name name of the dynamic method call or HTTP verb
208208
* @param array $args parameters passed with the method call
209-
*
209+
*
210210
* @return Client or Response object
211211
*/
212212
public function __call($name, $args)
213-
{
213+
{
214214
if($name == 'version') {
215215
$this->version = $args[0];
216216
return $this->_();
217217
}
218-
218+
219219
if (in_array($name, $this->methods)) {
220220
$query_params = ((count($args) >= 2) ? $args[1] : null);
221221
$url = $this->_buildUrl($query_params);
222222
$request_body = ($args ? $args[0] : null);
223223
$request_headers = ((count($args) == 3) ? $args[2] : null);
224224
return $this->makeRequest($name, $url, $request_body, $request_headers);
225225
}
226-
226+
227227
return $this->_($name);
228228
}
229229
}

lib/SendGrid/Config.php

-36
This file was deleted.

test/unit/ConfigTest.php

-28
This file was deleted.

test/unit/bootstrap.php

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
include(dirname(dirname(__FILE__)) . '/../lib/SendGrid/client.php');
3-
include(dirname(dirname(__FILE__)) . '/../lib/SendGrid/config.php');
43
require __DIR__ . '/../../vendor/autoload.php';
54
function autoload_tests($class)
65
{

0 commit comments

Comments
 (0)