Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
],
"support": {
"email": "hello@feedlabs.io",
"issues": "https://github.com/feedlabs/sdk-php/issues",
"source": "https://github.com/feedlabs/sdk-php"
"source": "https://github.com/feedlabs/sdk-php",
"issues": "https://github.com/feedlabs/sdk-php/issues"
},
"require-dev": {
"phpunit/phpunit": "~4.1.3",
Expand Down
105 changes: 26 additions & 79 deletions source/Feedlabs/Feedify/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Feedlabs\Feedify;

use Feedlabs\Feedify\Resource\Feed;
use Feedlabs\Feedify\Client\AdminUserClient;
use Feedlabs\Feedify\Client\ApplicationClient;
use Feedlabs\Feedify\Client\EntryClient;
use Feedlabs\Feedify\Client\FeedClient;
use Feedlabs\Feedify\Client\TokenClient;

/**
* Class Client
Expand All @@ -12,8 +16,20 @@ class Client {

CONST API_VERSION = 1;

/** @var string */
private static $_apiId;
/** @var ApplicationClient */
public $application;

/** @var FeedClient */
public $feed;

/** @var EntryClient */
public $entry;

/** @var AdminUserClient */
public $adminUser;

/** @var TokenClient */
public $token;

/** @var string */
private static $_apiToken;
Expand All @@ -22,93 +38,24 @@ class Client {
private static $_request;

/**
* @param string $apiId
* @param string $apiToken
*/
public function __construct($apiId, $apiToken) {
static::$_apiId = (string) $apiId;
public function __construct($apiToken) {
static::$_apiToken = (string) $apiToken;
}

/**
* @param string $id
* @return Feed
*/
public function getFeed($id) {
$id = (string) $id;
$data = static::getRequest()->get('/feed/' . $id);
return new Feed($id, $data);
}

/**
* @return Feed[]
*/
public function getFeedList() {
$feedList = array();
$result = static::getRequest()->get('/feed');
foreach ($result as $feedData) {
$feedList[] = new Feed($feedData['Id'], array('Data' => $feedData['Data']));
}
return $feedList;
}

/**
* @param array $data
* @return string
*/
public function createFeed(array $data) {
$result = static::getRequest()->post('/feed', $data);
return $result['id'];
}

/**
* @param string $id
* @param array $data
*/
public function updateFeed($id, array $data) {
static::getRequest()->put('/feed/' . $id, $data);
}

/**
* @param string $id
*/
public function deleteFeed($id) {
static::getRequest()->delete('/feed/' . $id);
}

/**
* @param string $feedId
* @param array $data
* @return string
*/
public function createEntry($feedId, array $data) {
$result = static::getRequest()->post('/feed/' . $feedId . '/entry', $data);
return $result['id'];
}

/**
* @param string $feedId
* @param string $entryId
* @param array $data
*/
public function updateEntry($feedId, $entryId, array $data) {
static::getRequest()->put('/feed/' . $feedId . '/entry/' . $entryId, $data);
}

/**
* @param string $feedId
* @param string $entryId
*/
public function deleteEntry($feedId, $entryId) {
static::getRequest()->delete('/feed/' . $feedId . '/entry/' . $entryId);
$this->application = new ApplicationClient();
$this->feed = new FeedClient();
$this->entry = new EntryClient();
$this->adminUser = new AdminUserClient();
$this->token = new TokenClient();
}

/**
* @return Request
*/
public static function getRequest() {
if (!static::$_request) {
static::$_request = new Request(static::$_apiId, static::$_apiToken);
static::$_request = new Request(static::$_apiToken);
}
return static::$_request;
}
Expand Down
95 changes: 95 additions & 0 deletions source/Feedlabs/Feedify/Client/AdminUserClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Feedlabs\Feedify\Client;

use Feedlabs\Feedify\Params;
use Feedlabs\Feedify\Resource\AdminUser;
use Feedlabs\Feedify\Resource\AdminUserList;

/**
* Class AdminUserClient
* @package Feedlabs\Feedify\Client
*/
class AdminUserClient {

/**
* @return AdminUserList
*/
public function getList() {
// todo: load over API
$adminUserList = [];
for ($i = 0; $i < 5; $i++) {
$adminUserList[] = [
'id' => 'adminUserId-' . $i,
'email' => 'test' . $i . '@example.com',
'roleList' => [['id' => 1, 'name' => 'superAdmin']],
'createStamp' => time(),
];
}

return new AdminUserList($adminUserList);
}

/**
* @param string $adminUserId
* @return AdminUser
*/
public function get($adminUserId) {
$adminUserId = (string) $adminUserId;
// todo: load over API
$data = [
'id' => $adminUserId,
'email' => 'test@example.com',
'roleList' => [['id' => 1, 'name' => 'superAdmin']],
'createStamp' => time(),
];

return new AdminUser(new Params($data));
}

/**
* @param string $email
* @param array|null $roleList
* @return AdminUser
*/
public function create($email, array $roleList = null) {
$email = (string) $email;
$roleList = (array) $roleList;
// todo: load over API
$data = [
'id' => 'ID1234',
'email' => $email,
'roleList' => [['id' => 1, 'name' => 'superAdmin']],
'createStamp' => time(),
];

return new AdminUser(new Params($data));
}

/**
* @param string $adminUserId
* @param string $email
* @param array|null $roleList
* @return AdminUser
*/
public function update($adminUserId, $email, array $roleList = null) {
$adminUserId = (string) $adminUserId;
$email = (string) $email;
$roleList = (array) $roleList;
// todo: load over API
$data = [
'id' => 'ID1234',
'email' => $email,
'roleList' => [['id' => 1, 'name' => 'superAdmin']],
'createStamp' => time(),
];

return new AdminUser(new Params($data));
}

public function delete($adminUserId) {
$adminUserId = (string) $adminUserId;
// todo: load over API
// todo: what to return???
}
}
102 changes: 102 additions & 0 deletions source/Feedlabs/Feedify/Client/ApplicationClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace Feedlabs\Feedify\Client;

use Feedlabs\Feedify\Params;
use Feedlabs\Feedify\Resource\Application;
use Feedlabs\Feedify\Resource\ApplicationList;

/**
* Class ApplicationClient
* @package Feedlabs\Feedify\Client
*/
class ApplicationClient {

/**
* @return ApplicationList
*/
public function getList() {
// todo: load over API

$applicationList = [];
for ($i = 0; $i < 5; $i++) {
$applicationList[] = [
'id' => 'id' . $i,
'name' => 'Name-' . $i,
'createStamp' => time(),
];
}

return new ApplicationList($applicationList);
}

/**
* @param string $applicationId
* @return Application
*/
public function get($applicationId) {
$applicationId = (string) $applicationId;

// todo: load over API

$data = new Params([
'id' => $applicationId,
'name' => 'Name-' . $applicationId,
'description' => 'description' . $applicationId,
'createStamp' => time(),
]);
return new Application($data);
}

/**
* @param string $name
* @param string|null $description
* @return Application
*/
public function create($name, $description = null) {
$name = (string) $name;
$description = (string) $description;

// todo: send / load over API

$data = new Params([
'id' => 'ABC123',
'name' => 'Name-ABC123',
'description' => 'description-ABC123',
'createStamp' => time(),
]);
return new Application($data);
}

/**
* @param string $applicationId
* @param string $name
* @param string|null $description
* @return Application
*/
public function update($applicationId, $name, $description = null) {
$applicationId = (string) $applicationId;
$name = (string) $name;
$description = (string) $description;

// todo: send / load over API

$data = new Params([
'id' => $applicationId,
'name' => 'Name-' . $applicationId,
'description' => 'description' . $applicationId,
'createStamp' => time(),
]);
return new Application($data);
}

/**
* @param string $applicationId
*/
public function delete($applicationId) {
$applicationId = (string) $applicationId;

// todo: send / load over API
// todo: think about what to return
}
}
30 changes: 30 additions & 0 deletions source/Feedlabs/Feedify/Client/EntryClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Feedlabs\Feedify\Client;

/**
* Class EntryClient
* @package Feedlabs\Feedify\Client
*/
class EntryClient {

public function getList($applicationId, $feedId) {
// todo: add
}

public function get($applicationId, $feedId, $entryId) {
// todo: add
}

public function create($applicationId, $feedId, $data) {
// todo: add
}

public function update($applicationId, $feedId, $entryId, $data) {
// todo: add
}

public function delete($applicationId, $feedId, $entryId) {
// todo: add
}
}
Loading