Skip to content

Commit 60ac415

Browse files
author
Chris Sachs
committed
query client for querying data at pda
1 parent 46ba9ff commit 60ac415

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

lib/Productsup/Http/Request.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ public function getHeaders() {
8484
return $headers;
8585
}
8686

87+
public function getUrl() {
88+
$url = $this->url;
89+
if($this->queryParams) {
90+
$url .= '?'.http_build_query($this->queryParams);
91+
}
92+
return $url;
93+
}
94+
8795
public function verboseOutput() {
88-
echo "Request:\n\n".$this->method.": ".$this->url." \nHeaders:".join("\n",$this->getHeaders())."\nBody:".$this->getBody();
96+
echo "Request:\n\n".$this->method.": ".$this->getUrl()." \nHeaders:".join("\n",$this->getHeaders())."\nBody:".$this->getBody();
8997
}
9098
}

lib/Productsup/IO/Curl.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ private function prepareRequest(Request $request) {
2828
$request->queryParams['debug'] = '1';
2929
}
3030

31-
if(!empty($request->queryParams)) {
32-
$request->url .= '?'.http_build_query($request->queryParams);
33-
}
34-
curl_setopt($this->curl, CURLOPT_URL, $request->url);
31+
curl_setopt($this->curl, CURLOPT_URL, $request->getUrl());
3532
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $request->method);
3633
curl_setopt($this->curl, CURLOPT_USERAGENT, $request->getUserAgent());
3734
}

lib/Productsup/Query.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
namespace Productsup;
3+
4+
5+
class Query {
6+
/** @var string query conditions */
7+
public $filter = '';
8+
/** @var int limit for returned entries */
9+
public $limit = 5000;
10+
/** @var int offset for returned entries */
11+
public $offset = 0;
12+
/** @var array fields returned, if empty all fields are returned */
13+
public $fields = array();
14+
/** @var int should also hidden fields be included? */
15+
public $hidden = 0;
16+
17+
}

lib/Productsup/Service/ProductData.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class ProductData extends Service {
4141
protected $serviceName = 'products';
4242

4343

44+
45+
/** names for the different stages for querying */
46+
const STAGE_IMPORT = 'import';
47+
const STAGE_INTERMEDIATE = 'intermediate';
48+
const STAGE_EXPORT = 'export';
49+
const STAGE_CHANNEL = 'channel';
50+
4451
/**
4552
* @param Client $Client
4653
* @param bool $useShutdownHandler set to false to disable shutdown handler
@@ -290,8 +297,7 @@ private function getPdaRequest($stage,$id) {
290297
$request = $this->getRequest();
291298
$request->method = Request::METHOD_GET;
292299
$request->url = $this->scheme.'://'.$this->host.'/product/'.$this->version.'/site/'.$this->_parentIdentifier;
293-
$request->url .= '/stage/intermediate/properties/';
294-
$request->url .= '/'.$stage;
300+
$request->url .= '/stage/'.$stage;
295301
if($id) {
296302
$request->url .= '/'.$id;
297303
}
@@ -305,24 +311,29 @@ private function getPdaRequest($stage,$id) {
305311
* @param array $params
306312
* @return array
307313
*/
308-
public function get($stage, $id,array $params) {
309-
$this->verbose =1;
310-
$this->debug = 1;
314+
public function get($stage, $id,$params) {
311315
$request = $this->getPdaRequest($stage,$id);
312316

313317
$request->url .= '/';
314-
$request->queryParams = $params;
315-
return $this->executeRequest($request);
318+
$request->queryParams = (array)$params;
319+
$data = $this->executeRequest($request);
320+
return isset($data['products']) ? $data['products'] : array();
316321
}
317322

318323
/**
319324
* @param string $stage source|intermediate|channel
320325
* @param int|null $id id of the stage (or null for source)
321326
* @return array
322327
*/
323-
public function getProperties($stage,$id) {
328+
public function getProperties($stage,$id, $params = null) {
324329
$request = $this->getPdaRequest($stage,$id);
330+
if(!$id) {
331+
$request->url .= '/0';
332+
}
325333
$request->url .= '/properties/';
334+
if($params) {
335+
$request->queryParams = (array)$params;
336+
}
326337
return $this->executeRequest($request);
327338
}
328339
}

0 commit comments

Comments
 (0)