Skip to content

Commit 17aca6c

Browse files
authored
Updated readme to be inline with prepr docs.
1 parent 241589e commit 17aca6c

File tree

1 file changed

+102
-63
lines changed

1 file changed

+102
-63
lines changed

README.md

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,140 @@
1-
# Prepr PHP SDK
1+
# Getting started with PHP
22

33
This package is a wrapper for the <a href="https://prepr.dev">Prepr</a> REST API.
44

5-
#### Installation
5+
## Basics
6+
The SDK on [GitHub](https://github.com/preprio/php-sdk)
7+
Minimal PHP version: `> 5.6.4`
8+
Requires `GuzzleHttp 7.0.X`, `Murmurhash 2.0.X`
69

7-
You can install the package via composer:
10+
## Installation
11+
12+
You can install the SDK as a composer package.
813

914
```bash
1015
composer require preprio/php-sdk
1116
```
1217

13-
#### Config variables
18+
## Making your first request
1419

15-
```text
16-
$apiRequest = new Prepr('token','userId','baseUrl');
17-
```
20+
Let's start with getting all publications from your Prepr Environment.
1821

19-
#### Override variables
22+
```php
23+
<?php
2024

21-
The authorization can also be set for one specific request `->url('url')->authorization('token')`.
25+
use Preprio\Prepr;
2226

23-
#### Examples
27+
$apiRequest = new Prepr('{ACCESS_TOKEN}');
2428

25-
```php
26-
use Preprio\Prepr;
29+
$apiRequest
30+
->path('publications')
31+
->query([
32+
'fields' => 'items'
33+
])
34+
->get();
35+
36+
if($apiRequest->getStatusCode() == 200) {
37+
38+
print_r($apiRequest->getResponse());
39+
}
2740
```
2841

29-
##### Get All
42+
43+
To get a single publication, pass the Id to the request.
3044

3145
```php
46+
<?php
47+
48+
use Preprio\Prepr;
49+
50+
$apiRequest = new Prepr('{ACCESS_TOKEN}');
51+
3252
$apiRequest
33-
->path('tags')
53+
->path('publications/{id}', [
54+
'id' => '1236f0b1-b26d-4dde-b835-9e4e441a6d09'
55+
])
3456
->query([
35-
'fields' => 'example'
57+
'fields' => 'items'
3658
])
3759
->get();
3860

3961
if($apiRequest->getStatusCode() == 200) {
62+
4063
print_r($apiRequest->getResponse());
4164
}
4265
```
4366

44-
##### Get Single
67+
68+
## A/B testing with Optimize
69+
70+
To enable A/B testing you can pass a User ID to provide a consistent result.
71+
The A/B testing feature requires the use of the cached CDN API.
72+
73+
To switch off A/B testing, pass NULL to the UserId param.
74+
75+
```php
76+
$apiRequest = new Prepr('{ACCESS_TOKEN}', '{{YourCustomUserId}}');
77+
```
78+
79+
or per request
4580

4681
```php
4782
$apiRequest
48-
->path('tags/{id}',[
83+
->path('publications/{id}',[
4984
'id' => 1
5085
]),
5186
->query([
5287
'fields' => 'example'
5388
])
89+
->userId(
90+
'{{YourCustomUserId}}'
91+
)
5492
->get();
5593

5694
if($apiRequest->getStatusCode() == 200) {
95+
5796
print_r($apiRequest->getResponse());
5897
}
5998
```
6099

61-
##### Post
100+
For more information check the [Optimize documentation](/docs/optimize/v1/introduction).
101+
102+
## Using the CDN
103+
104+
To use Prepr in production we advise you to use the API CDN for a fast response.
105+
Add the API CDN Url to the init of the SDK.
106+
107+
```php
108+
<?php
109+
110+
use Preprio\Prepr;
111+
112+
$apiRequest = new Prepr('{ACCESS_TOKEN}', null, 'https://cdn.prepr.io/');
113+
```
114+
115+
### Auto paging results
116+
117+
To get all resources for an endpoint, you can use the auto paging feature.
118+
119+
```php
120+
$apiRequest
121+
->path('publications')
122+
->query([
123+
'limit' => 200 // optional
124+
])
125+
->autoPaging();
126+
127+
if($apiRequest->getStatusCode() == 200) {
128+
129+
print_r($apiRequest->getResponse());
130+
}
131+
```
132+
133+
### Override the AccessToken in a request
134+
135+
The authorization can also be set for one specific request `->url('url')->authorization('token')`.
136+
137+
### Post
62138

63139
```php
64140
$apiRequest
@@ -69,11 +145,12 @@ $apiRequest
69145
->post();
70146

71147
if($apiRequest->getStatusCode() == 201) {
148+
72149
print_r($apiRequest->getResponse());
73150
}
74151
```
75152

76-
##### Put
153+
### Put
77154

78155
```php
79156
$apiRequest
@@ -84,11 +161,12 @@ $apiRequest
84161
->put();
85162

86163
if($apiRequest->getStatusCode() == 200) {
164+
87165
print_r($apiRequest->getResponse());
88166
}
89167
```
90168

91-
##### Delete
169+
### Delete
92170

93171
```php
94172
$apiRequest
@@ -98,31 +176,12 @@ $apiRequest
98176
->delete();
99177

100178
if($apiRequest->getStatusCode() == 204) {
101-
// Deleted.
102-
}
103-
```
104-
105-
##### A/B testing custom userId
106179

107-
```php
108-
$apiRequest
109-
->path('tags/{id}',[
110-
'id' => 1
111-
]),
112-
->query([
113-
'fields' => 'example'
114-
])
115-
->userId(
116-
'testUser'
117-
)
118-
->get();
119-
120-
if($apiRequest->getStatusCode() == 200) {
121-
print_r($apiRequest->getResponse());
180+
// Deleted.
122181
}
123182
```
124183

125-
##### Multipart/Chunk upload
184+
### Multipart/Chunk asset upload
126185

127186
```php
128187
$apiRequest
@@ -134,31 +193,11 @@ $apiRequest
134193
->post();
135194

136195
if($apiRequest->getStatusCode() == 200) {
137-
print_r($apiRequest->getResponse());
138-
}
139-
```
140-
141-
##### Autopaging
142196

143-
```php
144-
$apiRequest
145-
->path('publications')
146-
->query([
147-
'limit' => 200 // optional
148-
])
149-
->autoPaging();
150-
151-
if($apiRequest->getStatusCode() == 200) {
152197
print_r($apiRequest->getResponse());
153198
}
154199
```
155200

201+
### Debug Errors
156202

157-
#### Debug
158-
159-
For debug you can use `getRawResponse()`
160-
161-
162-
#### Documentation
163-
164-
<a href="https://developers.prepr.io/docs">For all the details and full documentation check out the Prepr Developer docs</a>
203+
With `$apiRequest->getRawResponse()` you can get the raw response from the Prepr API.

0 commit comments

Comments
 (0)