forked from extraplus/api_client_php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiClient.php
287 lines (263 loc) · 7.21 KB
/
ApiClient.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
require_once 'includes/ApiConst.php';
require_once 'includes/ApiError.php';
/* Test Comment for myfix branch */
/**
* zanox Api Client (ConnectId Version)
*
* Publisher api client library for accessing zanox affiliate
* network services.
*
* Supported Version: PHP >= 5.1.0
*
* The zanox API client contains methods and routines to access all publisher
* Web Services functionalities via a common abstract interface. This includes
* the hash-signed SOAP and REST request authentication of client messages
* as well as the encapsulation of all by zanox provided API methods.
*
* ---
*
* Usage Example: Restful XML API
* <code>
*
* require_once 'client/ApiClient.php';
*
* $api = ApiClient::factory(PROTOCOL_XML, VERSION_DEFAULT);
*
* $connectId = '__your_connect_id__';
* $secretKey = '__your_secrect_key__';
* $publicKey = '__your_public_key__';
*
* $api->setConnectId($connectId);
* $api->setSecretKey($secretKey);
* $api->setPublicKey($publicKey);
*
* $xml = $api->getPrograms();
*
* </code>
*
* ---
*
* Usage Example: Restful JSON API
* <code>
*
* require_once 'client/ApiClient.php';
*
* $api = ApiClient::factory(PROTOCOL_JSON, VERSION_DEFAULT);
*
* $connectId = '__your_connect_id__';
* $secretKey = '__your_secrect_key__';
* $publicKey = '__your_public_key__';
*
* $api->setConnectId($connectId);
* $api->setSecretKey($secretKey);
* $api->setPublicKey($publicKey);
*
* $xml = $api->searchProducts('iphone');
*
* </code>
*
* ---
*
* Usage Example: SOAP API
* <code>
*
* require_once 'client/ApiClient.php';
*
* $api = ApiClient::factory(PROTOCOL_SOAP, VERSION_DEFAULT);
*
* $connectId = '__your_connect_id__';
* $secretKey = '__your_secrect_key__';
* $publicKey = '__your_public_key__';
*
* $api->setConnectId($connectId);
* $api->setSecretKey($secretKey);
* $api->setPublicKey($publicKey);
*
* $xml = $api->getAdspaces();
*
* </code>
*
* ---
*
* Usage Example: Using API via Proxy Server
* <code>
*
* require_once 'client/ApiClient.php';
*
* $api = ApiClient::factory(PROTOCOL_SOAP, VERSION_DEFAULT);
*
* $api->setProxy("example.org", 8080, "login", "password");
*
* </code>
*
* ---
*
* Usage Example: Using API via HTTPS
* <code>
*
* require_once 'client/ApiClient.php';
*
* $api = ApiClient::factory(PROTOCOL_SOAP, VERSION_DEFAULT);
*
* $api->setHttpProtocol(HTTPS);
*
* </code>
*
* ---
*
* Usage Example: Using the Build-In Xml/Json Parser
* <code>
*
* require_once 'client/ApiClient.php';
*
* $api = ApiClient::factory(PROTOCOL_JSON, VERSION_DEFAULT);
*
* $xml = $api->getProduct('31f3bf210db1883e6bc3f7ab5dd096c7');
*
* $array = $api->unserialize($xml);
*
* </code>
*
* ---
*
* @author Thomas Nicolai ([email protected])
* @author Lars Kirchhoff ([email protected])
*
* @see http://wiki.zanox.com/en/Web_Services
* @see http://apps.zanox.com
*
* @category Web Services
* @package ApiClient
* @version 2009-09-01
* @copyright Copyright 2007-2009 zanox.de AG
*
* @uses PEAR Crypt_HMAC (required for PHP < 5.1.2)
*/
/**
* Base Directory Path
*/
define("DIR", dirname(__FILE__));
/**
* ApiClient
*/
final class ApiClient
{
/**
* Protocol instances.
*
* @static
* @var static instances of ApiClient
* @access private
*/
private static $instance = array();
/**
* Make the constructor private to prevent the class being instantiated
* directly.
*
* @return void
* @access privat
*/
private function __construct() { }
/**
* Factory function returns a static instance of the ApiClient.
*
* You can choose between three different api protocols. JSON, XML and
* SOAP are supported by the zanox api. If no version is given the latest
* version is always used.
*
* ---
*
* Usage example: creating api instance
* <code>
* // use soap api interface and the latest version
* $api = ApiClient::factory(PROTOCOL_SOAP, VERSION_DEFAULT);
*
* // use xml api interface and the latest vesion
* $api = ApiClient::factory(PROTOCOL_XML, VERSION_DEFAULT);
*
* // use json api interface and latest version
* $api = ApiClient::factory(PROTOCOL_JSON);
* </code>
*
* ---
*
* @param string $protocol api protocol type (XML,JSON or SOAP)
* @param string $version api version is optional
*
* @return mixed object on successful instantiation
* or false
*
* @static
* @access public
*/
public static function factory ( $protocol = PROTOCOL_DEFAULT, $version = VERSION_DEFAULT )
{
$protocol = strtolower($protocol);
if ( empty(self::$instance[$version][$protocol]) )
{
$class = self::getInterface($version, $protocol);
if ( $class )
{
self::$instance[$version][$protocol] = new $class($protocol, $version);
}
else
{
throw new ApiClientException(CLI_ERROR_PROTOCOL_VERSION);
}
}
return self::$instance[$version][$protocol];
}
/**
* Automatically includes the required ApiClient protocol class.
*
* @param string $version api version
* @param string $protocol api protocol
*
* @return mixed class name or false
*
* @access private
*/
private static function getInterface ( $version, $protocol )
{
$path = DIR . '/version/' . $version . '/';
if ( is_dir($path) )
{
if ( $protocol == PROTOCOL_SOAP )
{
$class = SOAP_INTERFACE;
$classfile = $path . $class . '.php';
}
else if ( $protocol == PROTOCOL_XML || $protocol == PROTOCOL_JSON )
{
$class = RESTFUL_INTERFACE;
$classfile = $path . $class . '.php';
}
else
{
throw new ApiClientException(CLI_ERROR_PROTOCOL);
}
if ( is_file($classfile) )
{
require_once $classfile;
if ( class_exists($class) )
{
return $class;
}
else
{
throw new ApiClientException(CLI_ERROR_PROTOCOL_CLASS);
}
}
else
{
throw new ApiClientException(CLI_ERROR_PROTOCOL_CLASSFILE);
}
}
else
{
throw new ApiClientException(CLI_ERROR_VERSION);
}
}
}
?>