blob: 60c262037e1c16b099ebb072725d6abcbc4e89d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# php.curl
**PCurl** is a PHP client library for [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer)
web services.
PCurl supports GET/POST/PUT/DELETE request methods. Unlike other similar libaries supports also HTTPS certificates verification.
Composer Installation
------------
To install PCurl, use the following composer `require` statement:
```
{
"require": {
"purplecode/pcurl": "dev-master"
}
}
```
or just copy-paste content of `src/` to your `libs`.
Usage
------------
### PCurl.php
Simple GET
```
$pcurl = new PCurl('http://www.google.pl');
$response = $pcurl->get('/')->getBody();
```
Simple GET via HTTPS with certificate verification (more examples in test package)
```
$pcurl = new PCurl('https://www.google.pl');
$pcurl->useSSLCertificate(<path to crt/pem file>);
$response = $pcurl->get('/')->getBody();
```
and a similar example without it
```
$pcurl = new PCurl('https://www.google.pl');
$pcurl->ignoreSSLCertificate();
$response = $pcurl->get('/')->getBody();
```
Sample POST
```
$pcurl = new PCurl('http://some.fancy.page');
$pcurl->proxy(host, port);
$pcurl->auth(user, pass);
$pcurl->header('Cache-Control: no-cache');
$pcurl->contentType('application/xml');
$response = $pcurl->post('/igipigiel/xml', '<a>makapaka</a>')->getBody();
```
### PJsonCurl.php
Class similar to PCurl, the only difference is that the input/output is passed through json_encode/json_decode.
```
$pcurl = new PJsonCurl('http://www.app.com/json');
$response = $pcurl->put('/', array('a' => 'b'));
echo $response->getBody()['c'];
```
### PObjectCurl.php
Class similar to PJsonCurl, the difference is that the input/output is passed through serialize/deserialize methods. Requires [JMS\Serializer](https://github.com/schmittjoh/serializer) library or [JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle) Symfony2 bundle.
```
$pcurl = new PObjectCurl('http://www.prettifier.com/json', JMS\Serializer\SerializerInterface $serializer);
$pcurl->responseClass('My\App\Preety');
$uglyObject = new My\App\Ugly();
$preetyObject = $pcurl->put('/', $uglyObject)->getBody();
```
Enjoy!
|