1
- # Prepr PHP SDK
1
+ # Getting started with PHP
2
2
3
3
This package is a wrapper for the <a href =" https://prepr.dev " >Prepr</a > REST API.
4
4
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 `
6
9
7
- You can install the package via composer:
10
+ ## Installation
11
+
12
+ You can install the SDK as a composer package.
8
13
9
14
``` bash
10
15
composer require preprio/php-sdk
11
16
```
12
17
13
- #### Config variables
18
+ ## Making your first request
14
19
15
- ``` text
16
- $apiRequest = new Prepr('token','userId','baseUrl');
17
- ```
20
+ Let's start with getting all publications from your Prepr Environment.
18
21
19
- #### Override variables
22
+ ``` php
23
+ <?php
20
24
21
- The authorization can also be set for one specific request ` ->url('url')->authorization('token') ` .
25
+ use Preprio\Prepr;
22
26
23
- #### Examples
27
+ $apiRequest = new Prepr('{ACCESS_TOKEN}');
24
28
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
+ }
27
40
```
28
41
29
- ##### Get All
42
+
43
+ To get a single publication, pass the Id to the request.
30
44
31
45
``` php
46
+ <?php
47
+
48
+ use Preprio\Prepr;
49
+
50
+ $apiRequest = new Prepr('{ACCESS_TOKEN}');
51
+
32
52
$apiRequest
33
- ->path('tags')
53
+ ->path('publications/{id}', [
54
+ 'id' => '1236f0b1-b26d-4dde-b835-9e4e441a6d09'
55
+ ])
34
56
->query([
35
- 'fields' => 'example '
57
+ 'fields' => 'items '
36
58
])
37
59
->get();
38
60
39
61
if($apiRequest->getStatusCode() == 200) {
62
+
40
63
print_r($apiRequest->getResponse());
41
64
}
42
65
```
43
66
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
45
80
46
81
``` php
47
82
$apiRequest
48
- ->path('tags /{id}',[
83
+ ->path('publications /{id}',[
49
84
'id' => 1
50
85
]),
51
86
->query([
52
87
'fields' => 'example'
53
88
])
89
+ ->userId(
90
+ '{{YourCustomUserId}}'
91
+ )
54
92
->get();
55
93
56
94
if($apiRequest->getStatusCode() == 200) {
95
+
57
96
print_r($apiRequest->getResponse());
58
97
}
59
98
```
60
99
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
62
138
63
139
``` php
64
140
$apiRequest
@@ -69,11 +145,12 @@ $apiRequest
69
145
->post();
70
146
71
147
if($apiRequest->getStatusCode() == 201) {
148
+
72
149
print_r($apiRequest->getResponse());
73
150
}
74
151
```
75
152
76
- ##### Put
153
+ ### Put
77
154
78
155
``` php
79
156
$apiRequest
@@ -84,11 +161,12 @@ $apiRequest
84
161
->put();
85
162
86
163
if($apiRequest->getStatusCode() == 200) {
164
+
87
165
print_r($apiRequest->getResponse());
88
166
}
89
167
```
90
168
91
- ##### Delete
169
+ ### Delete
92
170
93
171
``` php
94
172
$apiRequest
@@ -98,31 +176,12 @@ $apiRequest
98
176
->delete();
99
177
100
178
if($apiRequest->getStatusCode() == 204) {
101
- // Deleted.
102
- }
103
- ```
104
-
105
- ##### A/B testing custom userId
106
179
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.
122
181
}
123
182
```
124
183
125
- ##### Multipart/Chunk upload
184
+ ### Multipart/Chunk asset upload
126
185
127
186
``` php
128
187
$apiRequest
@@ -134,31 +193,11 @@ $apiRequest
134
193
->post();
135
194
136
195
if($apiRequest->getStatusCode() == 200) {
137
- print_r($apiRequest->getResponse());
138
- }
139
- ```
140
-
141
- ##### Autopaging
142
196
143
- ``` php
144
- $apiRequest
145
- ->path('publications')
146
- ->query([
147
- 'limit' => 200 // optional
148
- ])
149
- ->autoPaging();
150
-
151
- if($apiRequest->getStatusCode() == 200) {
152
197
print_r($apiRequest->getResponse());
153
198
}
154
199
```
155
200
201
+ ### Debug Errors
156
202
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