Skip to content

Commit 0e73486

Browse files
Merge pull request #20 from productsupcom/feature/DEV-19634-implement-site-stream-ds-endpoint
DEV-19634: Add site stream datasource endpoint
2 parents 5c70da4 + 714d3a1 commit 0e73486

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

examples/Service/Streams.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
include __DIR__.'/../../vendor/autoload.php';
4+
5+
/**
6+
* Authentication
7+
*
8+
* You'll get the client id and secret at the plaform (API Access)
9+
**/
10+
$Client = new Productsup\Client();
11+
$Client->id = 1234;
12+
$Client->secret = 'simsalabim';
13+
14+
$StreamService = new Productsup\Service\Streams($Client);
15+
$Reference = new Productsup\Platform\Site\Reference();
16+
17+
/**
18+
* You have to specify the site the streams belong to.
19+
* This is done by references to the site.
20+
*
21+
* In case you have a productsup site id, you can pass it like this:
22+
**/
23+
$Reference->setKey($Reference::REFERENCE_SITE);
24+
$Reference->setValue(1); // Site ID
25+
$StreamService->setReference($Reference);
26+
27+
$Streams = $StreamService->get();
28+
echo 'Get one site-stream by its id: '.PHP_EOL;
29+
print_r($Streams);

lib/Productsup/Platform/Stream.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Productsup\Platform;
4+
5+
class Stream extends DataModel {
6+
public $id;
7+
public $site_id;
8+
public $description;
9+
public $source;
10+
public $import_type;
11+
public $import_id;
12+
public $status;
13+
public $settings;
14+
public $stream;
15+
}

lib/Productsup/Service/Streams.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Productsup\Service;
4+
use Productsup\Platform\DataModel;
5+
use Productsup\Platform\Site;
6+
use Productsup\Platform\Site\Reference;
7+
use Productsup\Platform\Stream;
8+
use Productsup\Http\Request;
9+
10+
class Streams extends Service {
11+
protected $serviceName = 'streams';
12+
protected $parent = 'sites';
13+
14+
public function setSite(Site $site) {
15+
$this->_parentIdentifier = $site->id;
16+
}
17+
18+
/**
19+
* @return DataModel|Stream
20+
*/
21+
protected function getDataModel() {
22+
return new Stream();
23+
}
24+
25+
public function get($id = null,$action = null) {
26+
$request = $this->getRequest();
27+
$request->method = Request::METHOD_GET;
28+
if(!empty($this->params)) {
29+
$request->queryParams = $this->params;
30+
}
31+
32+
if($id) {
33+
$request->url .= '/'.$id;
34+
if($action) {
35+
$request->url .= '/'.$action;
36+
}
37+
}
38+
39+
$data = $this->executeRequest($request);
40+
41+
if (isset($data['success']) && array_key_exists('Sources', $data)) {
42+
$data['Streams'] = $data['Sources'];
43+
unset($data['Sources']);
44+
return $data;
45+
}
46+
47+
return false;
48+
}
49+
50+
51+
public function setReference(Reference $reference) {
52+
$this->_parentIdentifier = (string)$reference;
53+
}
54+
}

0 commit comments

Comments
 (0)