-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBasebuyAutoApi.php
229 lines (177 loc) · 5.82 KB
/
BasebuyAutoApi.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
<?php
namespace basebuy\basebuyAutoApi;
use \basebuy\basebuyAutoApi\exceptions\EmptyResponseException;
use \basebuy\basebuyAutoApi\exceptions\Exception;
class BasebuyAutoApi
{
/** @var IConnector */
private $_connector;
const FORMAT_CSV = 'csv';
const FORMAT_XML = 'xml';
const FORMAT_JSON = 'json';
const FORMAT_TIMESTAMP = 'timestamp';
const FORMAT_STRING = 'string';
/**
* BasebuyAutoApi constructor.
*
* @param IConnector $connector
*/
public function __construct(IConnector $connector)
{
$this->_connector = $connector;
}
/* Type */
public function typeGetAll($format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('type.getAll', $format, [], $is_download);
return $data;
}
public function typeGetDateUpdate($format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('type.getDateUpdate', $format, []);
return $data;
}
/* Mark */
public function markGetAll($id_type, $format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('mark.getAll', $format, [
'id_type' => $id_type,
], $is_download);
return $data;
}
public function markGetDateUpdate($id_type, $format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('mark.getDateUpdate', $format, [
'id_type' => $id_type,
]);
return $data;
}
/* Model */
public function modelGetAll($id_type, $format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('model.getAll', $format, [
'id_type' => $id_type,
], $is_download);
return $data;
}
public function modelGetDateUpdate($id_type, $format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('model.getDateUpdate', $format, [
'id_type' => $id_type,
]);
return $data;
}
/* Generation */
public function generationGetAll($id_type, $format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('generation.getAll', $format, [
'id_type' => $id_type,
], $is_download);
return $data;
}
public function generationGetDateUpdate($id_type, $format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('generation.getDateUpdate', $format, [
'id_type' => $id_type,
]);
return $data;
}
/* Serie */
public function serieGetAll($id_type, $format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('serie.getAll', $format, [
'id_type' => $id_type,
], $is_download);
return $data;
}
public function serieGetDateUpdate($id_type, $format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('serie.getDateUpdate', $format, [
'id_type' => $id_type,
]);
return $data;
}
/* Modification */
public function modificationGetAll($id_type, $format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('modification.getAll', $format, [
'id_type' => $id_type,
], $is_download);
return $data;
}
public function modificationGetDateUpdate($id_type, $format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('modification.getDateUpdate', $format, [
'id_type' => $id_type,
]);
return $data;
}
/* Characteristic */
public function characteristicGetAll($id_type, $format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('characteristic.getAll', $format, [
'id_type' => $id_type,
], $is_download);
return $data;
}
public function characteristicGetDateUpdate($id_type, $format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('characteristic.getDateUpdate', $format, [
'id_type' => $id_type,
]);
return $data;
}
/* Characteristic */
public function characteristicValueGetAll($id_type, $format = self::FORMAT_CSV, $is_download = true)
{
$data = $this->get('characteristicValue.getAll', $format, [
'id_type' => $id_type,
], $is_download);
return $data;
}
public function characteristicValueGetDateUpdate($id_type, $format = self::FORMAT_TIMESTAMP)
{
$data = $this->get('characteristicValue.getDateUpdate', $format, [
'id_type' => $id_type,
]);
return $data;
}
/**
* @param string $method
* @param string $format
* @param array $data
* @param boolean $is_download
*
* @return array
*
* @throws Exception
*/
private function get($method, $format, array $data, $is_download = false)
{
$requestResult = null;
if ($is_download) {
$downloadedFilePath = $this->_connector->download($method, $format, $data);
$requestResult = $downloadedFilePath;
} else {
$fileData = $this->_connector->get($method, $format, $data);
$requestResult = $fileData;
}
//$data = $parser->parse($requestResult);
/*
if(!isset($data['status'])) {
throw new EmptyResponseException();
}
if($data['status'] === 'fail') {
// Specific error codes may be processed with special exception for better error handling
throw new Exception(
isset($data['error']['description']) ? $data['error']['description'] : null,
isset($data['error']['code']) ? $data['error']['code'] : null
);
}
if($data['status'] !== 'ok') {
throw new Exception('Unknown response status');
}
*/
return $requestResult;
}
}