Skip to content

Commit 65e2ee0

Browse files
Preparing for public release
1 parent 87cf790 commit 65e2ee0

File tree

4 files changed

+211
-74
lines changed

4 files changed

+211
-74
lines changed

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
language: php
2+
before_script:
3+
- phpenv local 5.4
4+
- composer install --dev --no-interaction
5+
- phpenv local --unset
6+
- cd test/unit
7+
script:
8+
- ../../vendor/bin/phpunit . --bootstrap bootstrap.php --filter test* --coverage-clover clover.xml
9+
after_script:
10+
- cd ..
11+
- phpenv local 5.4
12+
- phpenv local --unset
13+
php:
14+
- 5.2
15+
- 5.3
16+
- 5.4
17+
- 5.5
18+
- 5.6
19+
env:
20+
global:
21+
- secure: eUN0huKA436uIkISu6V3yW01/gZHC6slBvlnprMPEhzclU2szH6qhWEXWS5CcOG6EEDBReqLZdNAwu+FC69KGFO9+6oW2GQQLSsfEViqFi/Ig2N0r4EBO4jLRebgq0GOfetPwQvJH27d8BCiloPy8rXBb5pskxSNw4B4bRyXHz4=
22+
- secure: j38xzMNmzYXR/JJdVumPmDoDVxb6FUDF497AuVPHowGh0egFW8XHWCOMeQWqWZI4Gg17pViQNIJ3xC6WBvob70AF8fsNm0+vxF2s7abXDMcbq5flLTS6ydKLgNu+na/RAkOBbTwxJAGIH/fQh8BH8iGKerCwoqf8sDErAge4NMw=
23+
- secure: h3HlxBOsNXBDrIJ0yl467ST6Q8R2TmbL7PltlPcRoHy5gAxn5UiDv5W2+6DSXrwQrTjOUunZ+O9ckcaQGQy1JNhGMwgIkJpyWAHDIHhTYGU289uUIDTHQW/soX0qHJSHSx3iMgDOIc7XnfTz6W7Nv1gYKZFedOMsZ5uBMeGyiXE=
24+
- secure: SKSl/RHFQNhGT7OUj7E0AbrQnuDhhCRI/4jC76mmzvy8EJBDgUNevAKJGtug+LVilHrlbk9fLC8rayPW6SGv0s3PowTGm8NMOc48aRBLOr7QRo/sMikJCmRuU6HWptr0NKuf2fq6lV94WDm/pDdyOSNyLga9/eaIDs/Sacp78sw=
25+
notifications:
26+
hipchat:
27+
rooms:
28+
secure: l4RUOBY44kVhSxx54NU3cmvn598rRMB7Y272Ct/W0fBm1tdGncp42A/rwg7JkiZH9EWXs3tKtoSjqw5xT6QeScUGQDdykS5QVO8lEIkDRGD4WwQ3VDJmRy1+04WtgqFEK8SyYTCcCl4ZJ0rtOcJZgDMvigkOJuLxwGXTDuvfu1k=
29+
template:
30+
- '<a href="https://travis-ci.org/%{repository}/builds/%{build_id}">%{repository}
31+
Build %{build_number}</a> on branch <i>%{branch}</i> by %{author}: <strong>%{message}</strong>
32+
<a href="https://github.com/%{repository}/commits/%{commit}">View on GitHub</a>'
33+
format: html
34+
notify: true

CONTRIBUTING.md

Lines changed: 25 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
Hello! Thank you for choosing to help contribute to the python-http-client. There are many ways you can contribute and help is always welcome.
1+
Hello! Thank you for choosing to help contribute to the php-http-client. There are many ways you can contribute and help is always welcome.
22

3-
We use [Milestones](https://github.com/sendgrid/python-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.
3+
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.
44

55
* [Feature Request](#feature_request)
66
* [Submit a Bug Report](#submit_a_bug_report)
77
* [Improvements to the Codebase](#improvements_to_the_codebase)
88
* [Understanding the Code Base](#understanding_the_codebase)
99
* [Testing](#testing)
10-
* [Testing Multiple Versions of Python](#testing_multiple_versoins_of_python)
1110
* [Style Guidelines & Naming Conventions](#style_guidelines_and_naming_conventions)
1211
* [Creating a Pull Request](#creating_a_pull_request)
1312

@@ -58,37 +57,37 @@ Any other information you want to share that is relevant to the issue being repo
5857
5958
#### Technical details:
6059
61-
* python-http-client Version: master (latest commit: 2cb34372ef0f31352f7c90015a45e1200cb849da)
62-
* Python Version: 2.7
60+
* php-http-client Version: master (latest commit: 2cb34372ef0f31352f7c90015a45e1200cb849da)
61+
* PHP Version: 5.6
6362
```
6463

6564
<a name="improvements_to_the_codebase"></a>
6665
## Improvements to the Codebase
6766

68-
We welcome direct contributions to the python-http-client code base. Thank you!
67+
We welcome direct contributions to the php-http-client code base. Thank you!
6968

7069
### Development Environment ###
7170

7271
#### Install and run locally ####
7372

7473
##### Prerequisites #####
7574

76-
* Python 2.6 through 3.5
77-
* There are no external dependencies
75+
* PHP 5.2 through 5.6
76+
* [Composer](https://getcomposer.org/)
7877

7978
##### Initial setup: #####
8079

8180
```
82-
git clone https://github.com/sendgrid/python-http-client.git
83-
cd python-http-client
81+
git clone https://github.com/sendgrid/php-http-client.git
82+
cd php-http-client
8483
cp .env_sample .env
8584
```
8685

8786
Update your settings in `.env`
8887

8988
##### Execute: #####
9089

91-
See the [examples folder](https://github.com/sendgrid/python-http-client/tree/master/examples) to get started quickly.
90+
See the [examples folder](https://github.com/sendgrid/php-http-client/tree/master/examples) to get started quickly.
9291

9392
<a name="understanding_the_codebase"></a>
9493
## Understanding the Code Base
@@ -97,15 +96,15 @@ See the [examples folder](https://github.com/sendgrid/python-http-client/tree/ma
9796

9897
Working examples that demonstrate usage.
9998

100-
**client.py**
99+
**client.php**
101100

102-
An HTTP client with a fluent interface using method chaining and reflection. By returning self on [__getattr__](https://github.com/sendgrid/python-http-client/blob/master/client.py#L74) and [_()](https://github.com/sendgrid/python-http-client/blob/master/client.py#L70), we can dynamically build the URL using method chaining and [__getattr__](https://github.com/sendgrid/python-http-client/blob/master/client.py#L74) allows us to dynamically receive the method calls to achieve reflection.
101+
An HTTP client with a fluent interface using method chaining and reflection. By returning self on [__call](https://github.com/sendgrid/php-http-client/blob/master/lib/client.php#L212) and [_()](https://github.com/sendgrid/php-http-client/blob/master/lib/client.pph#L198), we can dynamically build the URL using method chaining and [__call](https://github.com/sendgrid/php-http-client/blob/master/lib/client.php#L212) allows us to dynamically receive the method calls to achieve reflection.
103102

104103
This allows for the following mapping from a URL to a method chain:
105104

106-
`/api_client/{api_key_id}/version` maps to `client.api_client._(api_key_id).version.<method>()` where <method> is a [HTTP verb](https://github.com/sendgrid/python-http-client/blob/master/client.py#L24).
105+
`/api_client/{api_key_id}/version` maps to `client->api_client().->_($api_key_id)->version-><method>()` where <method> is a [HTTP verb](https://github.com/sendgrid/php-http-client/blob/master/lib/client.php#L94).
107106

108-
**congfig.py**
107+
**congfig.php**
109108

110109
Loads the environment variables.
111110

@@ -114,66 +113,26 @@ Loads the environment variables.
114113

115114
All PRs require passing tests before the PR will be reviewed.
116115

117-
All test files are in the `[tests](https://github.com/sendgrid/python-http-client/tree/master/tests)` directory.
116+
All test files are in the `[test/unit](https://github.com/sendgrid/php-http-client/tree/master/test/unit)` directory.
118117

119-
For the purposes of contributing to this repo, please update the [`test_unit.py`](https://github.com/sendgrid/python-http-client/blob/master/tests/test_unit.py) file with unit tests as you modify the code.
118+
For the purposes of contributing to this repo, please update the [`ClientTest.php`](https://github.com/sendgrid/php-http-client/blob/master/test/unit/ClientTest.php) file with unit tests as you modify the code.
120119

121-
For Python 2.6.*:
122-
123-
`unit2 discover -v`
124-
125-
For Python 2.7.* and up:
126-
127-
`python -m unittest discover -v`
128-
129-
<a name="testing_multiple_versoins_of_python"></a>
130-
## Testing Multiple Versions of Python
131-
132-
All PRs require passing tests before the PR will be reviewed.
133-
134-
### Prequisites: ###
135-
136-
The above local "Initial setup" is complete
137-
138-
* [pyenv](https://github.com/yyuu/pyenv)
139-
* [tox](https://pypi.python.org/pypi/tox)
140-
141-
### Initial setup: ###
142-
143-
Add ```eval "$(pyenv init -)"``` to your shell environment (.profile, .bashrc, etc) after installing tox, you only need to do this once.
144-
145-
```
146-
pyenv install 2.6.9
147-
pyenv install 2.7.11
148-
pyenv install 3.2.6
149-
pyenv install 3.3.6
150-
pyenv install 3.4.3
151-
pyenv install 3.5.0
152-
python setup.py install
153-
pyenv local 3.5.0 3.4.3 3.3.6 3.2.6 2.7.8 2.6.9
154-
pyenv rehash
155-
````
156-
157-
### Execute: ###
158-
159-
```
160-
source venv/bin/activate
161-
tox
162-
```
120+
`phpunit --bootstrap test/unit/bootstrap.php --filter test* test/unit`
163121

164122
<a name="style_guidelines_and_naming_conventions"></a>
165123
## Style Guidelines & Naming Conventions
166124

167125
Generally, we follow the style guidelines as suggested by the official language. However, we ask that you conform to the styles that already exist in the library. If you wish to deviate, please explain your reasoning.
168126

169-
* [PEP8](https://www.python.org/dev/peps/pep-0008/)
127+
* [pear coding standards](https://pear.php.net/manual/en/standards.php)
170128

171-
Please run your code through [pyflakes](https://pypi.python.org/pypi/pyflakes), [pylint](https://www.pylint.org/) and [pep8](https://pypi.python.org/pypi/pep8)
129+
Please run your code through [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer)
172130

173131
### Directory Structure
174132

175-
* `examples` for example calls
176-
* `tests`, for all tests
133+
* `examples`, for example calls
134+
* `test\unit`, for all tests
135+
* 'lib`, for source code
177136

178137
## Creating a Pull Request<a name="creating_a_pull_request"></a>
179138

@@ -182,11 +141,11 @@ Please run your code through [pyflakes](https://pypi.python.org/pypi/pyflakes),
182141

183142
```bash
184143
# Clone your fork of the repo into the current directory
185-
git clone https://github.com/sendgrid/python-http-client
144+
git clone https://github.com/sendgrid/php-http-client
186145
# Navigate to the newly cloned directory
187-
cd python-http-client
146+
cd php-http-client
188147
# Assign the original repo to a remote called "upstream"
189-
git remote add upstream https://github.com/sendgrid/python-http-client
148+
git remote add upstream https://github.com/sendgrid/php-http-client
190149
```
191150

192151
2. If you cloned a while ago, get the latest changes from upstream:

README.md

Lines changed: 146 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,146 @@
1-
# php-http-client
2-
HTTP REST client, simplified for PHP
1+
[![Travis Badge](https://travis-ci.org/sendgrid/php-http-client.svg?branch=master)](https://travis-ci.org/sendgrid/php-http-client)
2+
3+
**Quickly and easily access any REST or REST-like API.**
4+
5+
Here is a quick example:
6+
7+
`GET /your/api/{param}/call`
8+
9+
```php
10+
require 'vendor/autoload.php';
11+
$global_headers = array(Authorization: Basic XXXXXXX);
12+
$client = SendGrid\Client('base_url', 'global_headers');
13+
$response = $client->your()->api()->_($param)->call()->get();
14+
print $response->statusCode();
15+
print $response->responseHeaders();
16+
print $response->responseBody();
17+
```
18+
19+
`POST /your/api/{param}/call` with headers, query parameters and a request body with versioning.
20+
21+
```php
22+
require 'vendor/autoload.php';
23+
$global_headers = array(Authorization: Basic XXXXXXX);
24+
$client = SendGrid\Client('base_url', 'global_headers');
25+
$query_params = array('hello' => 0, 'world' => 1);
26+
$request_headers = array('X-Test' => 'test');
27+
$data = array('some' => 1, 'awesome' => 2, 'data' => 3);
28+
$response = $client->your()->api()->_($param)->call()->post('data',
29+
'query_params',
30+
'request_headers');
31+
print $response->statusCode();
32+
print $response->responseHeaders();
33+
print $response->responseBody();
34+
```
35+
36+
# Installation
37+
38+
Add php-http-client to your `composer.json` file. If you are not using [Composer](http://getcomposer.org), you should be. It's an excellent way to manage dependencies in your PHP application.
39+
40+
```json
41+
{
42+
"require": {
43+
"sendgrid/php-http-client": "~1"
44+
}
45+
}
46+
```
47+
48+
Then at the top of your PHP script require the autoloader:
49+
50+
```bash
51+
require 'vendor/autoload.php';
52+
```
53+
54+
or
55+
56+
`pear install php-http-client`
57+
58+
## Usage ##
59+
60+
Following is an example using SendGrid. You can get your free account [here](https://sendgrid.com/free?source=php-http-client).
61+
62+
First, update your .env with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys) and HOST. For this example HOST=https://api.sendgrid.com.
63+
64+
Following is an abridged example, here is the [full working code](https://github.com/sendgrid/php-http-client/tree/master/examples).
65+
66+
```php
67+
<?php
68+
include 'php-http-client';
69+
$config = new SendGrid\Config(dirname(__DIR__), '.env');
70+
$api_key = getenv('SENDGRID_API_KEY');
71+
$headers = array(
72+
'Content-Type: application/json',
73+
'Authorization: Bearer '.$api_key
74+
);
75+
$client = new SendGrid\Client('https://e9sk3d3bfaikbpdq7.stoplight-proxy.io', $headers, '/v3', null);
76+
77+
// GET Collection
78+
$query_params = array('limit' => 100, 'offset' => 0);
79+
$request_headers = array('X-Mock: 200');
80+
$response = $client->api_keys()->get(null, $query_params, $request_headers);
81+
82+
// POST
83+
$request_body = array(
84+
'name' => 'My PHP API Key',
85+
'scopes' => array(
86+
'mail.send',
87+
'alerts.create',
88+
'alerts.read'
89+
)
90+
);
91+
$response = $client->api_keys()->post($request_body);
92+
$response_body = json_decode($response->responseBody());
93+
$api_key_id = $response_body->api_key_id;
94+
95+
// GET Single
96+
$response = $client->version('/v3')->api_keys()->_($api_key_id)->get();
97+
98+
// PATCH
99+
$request_body = array(
100+
'name' => 'A New Hope'
101+
);
102+
$response = $client->api_keys()->_($api_key_id)->patch($request_body);
103+
104+
// PUT
105+
$request_body = array(
106+
'name' => 'A New Hope',
107+
'scopes' => array(
108+
'user.profile.read',
109+
'user.profile.update'
110+
)
111+
);
112+
$response = $client->api_keys()->_($api_key_id)->put($request_body);
113+
114+
// DELETE
115+
$response = $client->api_keys()->_($api_key_id)->delete();
116+
?>
117+
```
118+
119+
# Announcements
120+
121+
[2016.03.28] - We hit version 1!
122+
123+
# Roadmap
124+
125+
[Milestones](https://github.com/sendgrid/php-http-client/milestones)
126+
127+
# How to Contribute
128+
129+
We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md) guide for details.
130+
131+
* [Feature Request](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#feature_request)
132+
* [Bug Reports](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#submit_a_bug_report)
133+
* [Improvements to the Codebase](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#improvements_to_the_codebase)
134+
135+
# Thanks
136+
137+
We were inspired by the work done on [birdy](https://github.com/inueni/birdy) and [universalclient](https://github.com/dgreisen/universalclient).
138+
139+
# About
140+
141+
![SendGrid Logo]
142+
(https://assets3.sendgrid.com/mkt/assets/logos_brands/small/sglogo_2015_blue-9c87423c2ff2ff393ebce1ab3bd018a4.png)
143+
144+
php-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]).
145+
146+
php-http-client is maintained and funded by SendGrid, Inc. The names and logos for python-http-client are trademarks of SendGrid, Inc.

0 commit comments

Comments
 (0)