Skip to content

Commit d350c2a

Browse files
Merge branch 'master' into refactor-make-request-method
2 parents d42ae6a + 0d23d92 commit d350c2a

16 files changed

+555
-175
lines changed

.codeclimate.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
engines:
2+
duplication:
3+
enabled: true
4+
config:
5+
languages:
6+
- "php"
7+
phpcodesniffer:
8+
enabled: true
9+
config:
10+
file_extensions: "php"
11+
standard: "PSR1,PSR2"
12+
ratings:
13+
paths:
14+
- "**.php"
15+
exclude_paths:
16+
- "examples/**/*"
17+
- "test/**/*"
18+
- "vendor/**/*"

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ before_script:
33
- composer install --dev --no-interaction
44
- cd test/unit
55
script:
6-
- ../../vendor/bin/phpunit . --bootstrap bootstrap.php --filter test* --coverage-clover clover.xml
6+
- ../../vendor/bin/phpunit . --bootstrap bootstrap.php --filter test* --coverage-clover=coverage.xml
7+
after_success:
8+
- bash <(curl -s https://codecov.io/bash)
79
php:
810
- 5.6
911
- 7.0
@@ -22,4 +24,4 @@ notifications:
2224
Build %{build_number}</a> on branch <i>%{branch}</i> by %{author}: <strong>%{message}</strong>
2325
<a href="https://github.com/%{repository}/commits/%{commit}">View on GitHub</a>'
2426
format: html
25-
notify: true
27+
notify: true

CONTRIBUTING.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Hello! Thank you for choosing to help contribute to one of the SendGrid open sou
99
- [Testing](#testing)
1010
- [Style Guidelines & Naming Conventions](#style-guidelines-and-naming-conventions)
1111
- [Creating a Pull Request](#creating-a-pull-request)
12+
- [Code Reviews](#code-reviews)
1213

1314
<a name="roadmap"></a>
1415
We use [Milestones](https://github.com/sendgrid/php-http-client/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community review, comments, suggestions and additional PRs are welcomed and encouraged.
@@ -74,7 +75,7 @@ git clone https://github.com/sendgrid/php-http-client.git
7475
cd php-http-client
7576
```
7677

77-
## Environment Variables
78+
### Environment Variables
7879

7980
First, get your free SendGrid account [here](https://sendgrid.com/free?source=php-http-client).
8081

@@ -88,7 +89,8 @@ source ./sendgrid.env
8889

8990
##### Execute: #####
9091

91-
See the [examples folder](https://github.com/sendgrid/php-http-client/tree/master/examples
92+
See the [examples folder](https://github.com/sendgrid/php-http-client/tree/master/examples).
93+
9294
<a name="understanding-the-codebase"></a>
9395
## Understanding the Code Base
9496

@@ -138,7 +140,8 @@ Please run your code through:
138140

139141
- [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer)
140142

141-
## Creating a Pull Request<a name="creating-a-pull-request"></a>
143+
<a name="creating-a-pull-request"></a>
144+
## Creating a Pull Request
142145

143146
1. [Fork](https://help.github.com/fork-a-repo/) the project, clone your fork,
144147
and configure the remotes:
@@ -191,4 +194,8 @@ Please run your code through:
191194
7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
192195
with a clear title and description against the `master` branch. All tests must be passing before we will review the PR.
193196

197+
<a name="code-reviews"></a>
198+
## Code Reviews
199+
If you can, please look at open PRs and review them. Give feedback and help us merge these PRs much faster! If you don't know how, Github has some great [information on how to review a Pull Request](https://help.github.com/articles/about-pull-request-reviews/).
200+
194201
If you have any additional questions, please feel free to [email](mailto:[email protected]) us or create an issue in this repo.

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM php:7.1-apache
2+
3+
ARG sendgrid_apikey
4+
ENV SENDGRID_API_KEY=$sendgrid_apikey
5+
6+
COPY . /var/www/client
7+
WORKDIR /var/www/client
8+
9+
RUN apt-get update && \
10+
apt-get install -y git zip zlib1g-dev && docker-php-ext-install zip
11+
RUN curl --silent --show-error https://getcomposer.org/installer | php
12+
13+
RUN php composer.phar install

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 SendGrid, Inc.
3+
Copyright (c) 2012-2018 SendGrid, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Travis Badge](https://travis-ci.org/sendgrid/php-http-client.svg?branch=master)](https://travis-ci.org/sendgrid/php-http-client)
44
[![Latest Version on Packagist](https://img.shields.io/packagist/v/sendgrid/php-http-client.svg?style=flat-square)](https://packagist.org/packages/sendgrid/php-http-client)
5-
[![BuildStatus](https://travis-ci.org/sendgrid/php-http-client.svg?branch=master)](https://travis-ci.org/sendgrid/php-http-client)
65
[![Email Notifications Badge](https://dx.sendgrid.com/badge/php)](https://dx.sendgrid.com/newsletter/php)
76
[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
87
[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/php-http-client.svg)](https://github.com/sendgrid/php-http-client/graphs/contributors)
@@ -66,7 +65,6 @@ $ cd /path/to/your/app
6665
$ mkdir lib
6766
$ cd lib
6867
$ git clone https://github.com/sendgrid/php-http-client.git
69-
$ git clone https://github.com/sendgrid/sendgrid-php.git
7068
```
7169

7270
In the next step you should create `loader.php`:
@@ -83,8 +81,6 @@ And add to `loader.php` code below:
8381

8482
require_once __DIR__ . '/lib/php-http-client/lib/Client.php';
8583
require_once __DIR__ . '/lib/php-http-client/lib/Response.php';
86-
require_once __DIR__ . '/lib/sendgrid-php/lib/SendGrid.php';
87-
8884
```
8985

9086
After it you can use `php-http-client` library in your project:
@@ -107,36 +103,54 @@ Here is a quick example:
107103
```php
108104
// include __DIR__ . '/loader.php';
109105
require 'vendor/autoload.php';
110-
$global_headers = array('Authorization: Basic XXXXXXX');
111-
$client = new SendGrid\Client('base_url', $global_headers);
106+
$apiKey = YOUR_SENDGRID_API_KEY;
107+
$authHeaders = [
108+
'Authorization: Bearer ' . $apiKey
109+
];
110+
$client = new SendGrid\Client('https://api.sendgrid.com', $authHeaders);
111+
$param = 'foo';
112112
$response = $client->your()->api()->_($param)->call()->get();
113-
print $response->statusCode();
114-
print $response->headers();
115-
print $response->body();
113+
114+
var_dump(
115+
$response->statusCode(),
116+
$response->headers(),
117+
$response->body()
118+
);
116119
```
117120

118121
`POST /your/api/{param}/call` with headers, query parameters and a request body with versioning.
119122

120123
```php
121124
// include __DIR__ . '/loader.php';
122125
require 'vendor/autoload.php';
123-
$global_headers = array('Authorization: Basic XXXXXXX');
124-
$client = new SendGrid\Client('base_url', $global_headers);
125-
$query_params = array('hello' => 0, 'world' => 1);
126-
$request_headers = array('X-Test' => 'test');
127-
$data = array('some' => 1, 'awesome' => 2, 'data' => 3);
128-
$response = $client->your()->api()->_($param)->call()->post('data',
129-
'query_params',
130-
'request_headers');
131-
print $response->statusCode();
132-
print $response->headers();
133-
print $response->body();
126+
$apiKey = YOUR_SENDGRID_API_KEY;
127+
$authHeaders = [
128+
'Authorization: Bearer ' . $apiKey
129+
];
130+
$client = new SendGrid\Client('https://api.sendgrid.com', $authHeaders);
131+
$queryParams = [
132+
'hello' => 0, 'world' => 1
133+
];
134+
$requestHeaders = [
135+
'X-Test' => 'test'
136+
];
137+
$data = [
138+
'some' => 1, 'awesome' => 2, 'data' => 3
139+
];
140+
$param = 'bar';
141+
$response = $client->your()->api()->_($param)->call()->post($data, $queryParams, $requestHeaders);
142+
143+
var_dump(
144+
$response->statusCode(),
145+
$response->headers(),
146+
$response->body()
147+
);
134148
```
135149

136150
<a name="usage"></a>
137151
# Usage
138152

139-
- [Example Code](https://github.com/sendgrid/php-http-client/tree/master/examples)
153+
- [Usage Examples](USAGE.md)
140154

141155
## Environment Variables
142156

@@ -154,14 +168,15 @@ If you are interested in the future direction of this project, please take a loo
154168
<a name="contribute"></a>
155169
# How to Contribute
156170

157-
We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md)) guide for details.
171+
We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md) guide for details.
158172

159173
Quick links:
160174

161175
- [Feature Request](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#feature-request)
162176
- [Bug Reports](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#submit-a-bug-report)
163177
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#cla)
164178
- [Improvements to the Codebase](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#improvements-to-the-codebase)
179+
- [Review Pull Requests](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#code-reviews)
165180

166181
<a name="thanks"></a>
167182
# Thanks

USAGE.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Usage
2+
3+
Usage examples for SendGrid php-http-client
4+
5+
## Initialization
6+
7+
```
8+
// If running this outside of this context, use the following include and
9+
// comment out the two includes below
10+
// require __DIR__ . '/vendor/autoload.php';
11+
include(dirname(__DIR__) . '/lib/Client.php');
12+
// This gets the parent directory, for your current directory use getcwd()
13+
$path_to_config = dirname(__DIR__);
14+
$apiKey = getenv('SENDGRID_API_KEY');
15+
$headers = ['Authorization: Bearer ' . $apiKey];
16+
$client = new SendGrid\Client('https://api.sendgrid.com', $headers, '/v3');
17+
```
18+
19+
## Table of Contents
20+
21+
- [GET](#get)
22+
- [DELETE](#delete)
23+
- [POST](#post)
24+
- [PUT](#put)
25+
- [PATCH](#patch)
26+
27+
<a name="get"></a>
28+
## GET
29+
30+
#### GET Collection
31+
32+
```
33+
$query_params = ['limit' => 100, 'offset' => 0];
34+
$request_headers = ['X-Mock: 200'];
35+
$response = $client->api_keys()->get(null, $query_params, $request_headers);
36+
echo $response->statusCode();
37+
echo $response->body();
38+
echo $response->headers();
39+
```
40+
41+
#### GET with auto retry on rate limit
42+
43+
```
44+
$query_params = ['limit' => 100, 'offset' => 0];
45+
$request_headers = ['X-Mock: 200'];
46+
$retryOnLimit = true;
47+
$response = $client->api_keys()->get(null, $query_params, $request_headers, $retryOnLimit);
48+
echo $response->statusCode();
49+
echo $response->body();
50+
echo $response->headers();
51+
```
52+
53+
<a name="delete"></a>
54+
## DELETE
55+
56+
```
57+
$response = $client->api_keys()->_($api_key_id)->delete();
58+
echo $response->statusCode();
59+
echo $response->body();
60+
echo $response->headers();
61+
```
62+
63+
<a name="post"></a>
64+
## POST
65+
66+
```
67+
$request_body = [
68+
'name' => 'My PHP API Key',
69+
'scopes' => [
70+
'mail.send',
71+
'alerts.create',
72+
'alerts.read'
73+
]
74+
];
75+
$response = $client->api_keys()->post($request_body);
76+
echo $response->statusCode();
77+
echo $response->body();
78+
echo $response->headers();
79+
$response_body = json_decode($response->body());
80+
$api_key_id = $response_body->api_key_id;
81+
```
82+
<a name="put"></a>
83+
## PUT
84+
85+
```
86+
$request_body = [
87+
'name' => 'A New Hope',
88+
'scopes' => [
89+
'user.profile.read',
90+
'user.profile.update'
91+
]
92+
];
93+
$response = $client->api_keys()->_($api_key_id)->put($request_body);
94+
echo $response->statusCode();
95+
echo $response->body();
96+
echo $response->headers();
97+
```
98+
<a name="patch"></a>
99+
## PATCH
100+
101+
```
102+
$request_body = [
103+
'name' => 'A New Hope'
104+
];
105+
$response = $client->api_keys()->_($api_key_id)->patch($request_body);
106+
echo $response->statusCode();
107+
echo $response->body();
108+
echo $response->headers();
109+
```

USE_CASES.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This documentation provides examples for specific use cases. Please [open an issue](https://github.com/sendgrid/php-http-client/issues) or make a pull request for any use cases you would like us to document here. Thank you!
2+
3+
# Table of Contents
4+
* [Docker](#docker)
5+
6+
<a name="docker"></a>
7+
# Docker
8+
9+
You can run the example code at `examples/example.php` in a Docker container.
10+
11+
From the root directory:
12+
13+
```bash
14+
cp examples/.env_sample .env
15+
```
16+
17+
Update the `.env` file with your SendGrid API Key. If you don't have one, you can get one [here](https://sendgrid.com/free?source=php-http-client).
18+
19+
Add the `.env` file to your `.gitignore` file if you are publishing your code publically.
20+
21+
```
22+
source .env
23+
docker build --build-arg sendgrid_apikey=$SENDGRID_API_KEY -t client .
24+
docker run client php examples/example.php
25+
```
26+
27+
You should see a list of your SendGrid API Keys.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
"description": "HTTP REST client, simplified for PHP",
44
"type": "library",
55
"version": "3.8.0",
6-
"require-dev": {
7-
"phpunit/phpunit": "~4.4",
8-
"squizlabs/php_codesniffer": "~2.0"
9-
},
106
"homepage": "http://github.com/sendgrid/php-http-client",
117
"keywords": ["SendGrid", "HTTP", "REST", "API", "Fluent"],
128
"license": "MIT",
@@ -23,6 +19,10 @@
2319
"require": {
2420
"php": ">=5.6"
2521
},
22+
"require-dev": {
23+
"phpunit/phpunit": "~4.4",
24+
"squizlabs/php_codesniffer": "~2.0"
25+
},
2626
"autoload": {
2727
"psr-4": {
2828
"SendGrid\\": "lib/"

0 commit comments

Comments
 (0)