Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $nstack = new \NStack\NStack($config);
[x] Content Localize proposals
[x] Content Files
[x] Content Collections
[ ] Notify updates
[x] Notify updates
[ ] UGC pushlogs
[x] Validators

Expand Down
80 changes: 80 additions & 0 deletions src/Clients/NotifyClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace NStack\Clients;

use NStack\Exceptions\FailedToParseException;
use NStack\Models\SeenUpdate;
use NStack\Models\VersionControlUpdate;

/**
* Class NotifyClient
*
* @package NStack\Clients
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class NotifyClient extends NStackClient
{
/** @var string */
protected $path = 'notify/updates';

/**
* versionControlIndex
*
* @param String $platform
* @param String|null $currentVersion
* @param String|null $lastVersion
* @param String|null $test
* @return VersionControlUpdate
* @throws FailedToParseException
* @author Tiago Araujo <tiar@nodesagency.com>
*/
public function versionControlIndex(
String $platform,
String $currentVersion = null,
String $lastVersion = null,
String $test = null
): VersionControlUpdate
{
$path = $this->buildPath($this->path) . "?platform=" . $platform;
if ($currentVersion) {
$path = $path . '&current_version=' . $currentVersion;
}
if ($lastVersion) {
$path = $path . '&last_version=' . $lastVersion;
}
if ($test) {
$path = $path . '&test=' . $test;
}

$response = $this->client->get($path);
$contents = $response->getBody()->getContents();
$data = json_decode($contents, true);
return new VersionControlUpdate($data);
}

/**
* markUpdateAsSeen
*
* @param String $guid
* @param int $updateId
* @param String $answer
* @param String $type
* @return SeenUpdate
* @throws FailedToParseException
*/
public function markUpdateAsSeen(String $guid, int $updateId, String $answer, String $type)
{
$response = $this->client->post($this->buildPath($this->path), [
'form_params' => [
'guid' => $guid,
'update_id' => $updateId,
'answer' => $answer,
'type' => $type,
]
]);
$contents = $response->getBody()->getContents();
$data = json_decode($contents, true);
return new SeenUpdate($data['data']);
}

}
102 changes: 102 additions & 0 deletions src/Models/SeenUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace NStack\Models;

use DateTime;
use Exception;

/**
* Class SeenUpdate
*
* @package NStack\Models
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class SeenUpdate extends Model
{
/** @var int */
protected $id;

/** @var String */
protected $guid;

/** @var string */
protected $answer;

/** @var string */
protected $type;

/** @var DateTime */
protected $created;

/**
* parse
*
* @param array $data
* @throws Exception
*/
public function parse(array $data)
{
$this->id = (int)$data['id'];
$this->guid = (int)$data['guid'];
$this->answer = (string)$data['answer'];
$this->type = (string)$data['type'];
$this->created = new DateTime($data['created']);
}

/**
* toArray
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'guid' => $this->guid,
'answer' => $this->answer,
'type' => $this->type,
'created' => $this->created,
];
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @return String
*/
public function getGuid(): String
{
return $this->guid;
}

/**
* @return string
*/
public function getAnswer(): string
{
return $this->answer;
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}

/**
* @return DateTime
*/
public function getCreated(): DateTime
{
return $this->created;
}

}
86 changes: 86 additions & 0 deletions src/Models/VersionControlUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace NStack\Models;

/**
* Class VersionControlUpdate
*
* @package NStack\Models
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class VersionControlUpdate extends Model
{
/** @var String */
protected $update;

/** @var array */
protected $updateVersions;

/** @var bool */
protected $newInVersion;

/** @var array */
protected $newInVersions;

/**
* parse
*
* @param array $data
*/
public function parse(array $data)
{
$this->update = (String)$data['update'];
$this->updateVersions = (array)$data['update_versions'];
$this->newInVersion = (string)$data['new_in_version'];
$this->newInVersions = (array)$data['new_in_versions'];
}

/**
* toArray
*
* @return array
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function toArray(): array
{
return [
'update' => $this->update,
'update_versions' => $this->updateVersions,
'new_in_version' => $this->newInVersion,
'new_in_versions' => $this->newInVersions,
];
}

/**
* @return String
*/
public function getUpdate(): String
{
return $this->update;
}

/**
* @return array
*/
public function getUpdateVersions(): array
{
return $this->updateVersions;
}

/**
* @return bool
*/
public function isNewInVersion(): bool
{
return $this->newInVersion;
}

/**
* @return array
*/
public function getNewInVersions(): array
{
return $this->newInVersions;
}

}
65 changes: 65 additions & 0 deletions src/Models/VersionUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace NStack\Models;

/**
* Class VersionUpdate
*
* @package NStack\Models
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class VersionUpdate extends Model
{
/** @var int */
protected $id;

/** @var String */
protected $version;

/** @var String */
protected $update;

/** @var bool */
protected $newInVersion;

/** @var String */
protected $changeLog;

/** @var String */
protected $fileUrl;

/**
* parse
*
* @param array $data
*/
public function parse(array $data)
{
$this->id = (String)$data['id'];
$this->version = (array)$data['version'];
$this->update = (string)$data['update'];
$this->newInVersion = (array)$data['new_in_version'];
$this->changeLog = (array)$data['change_log'];
$this->fileUrl = (array)$data['file_url'];
}

/**
* toArray
*
* @return array
* @author Casper Rasmussen <cr@nodes.dk>
*/
public function toArray(): array
{
return [
'id' => $this->id,
'version' => $this->version,
'update' => $this->update,
'new_in_version' => $this->newInVersion,
'change_log' => $this->changeLog,
'file_url' => $this->fileUrl,
];
}


}
36 changes: 36 additions & 0 deletions tests/NotifyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace NStack\Tests;

use NStack\Clients\ContinentsClient;
use NStack\Clients\CountriesClient;
use NStack\Clients\IpAddressesClient;
use NStack\Clients\NotifyClient;
use NStack\Models\Continent;
use NStack\Models\Country;
use NStack\Models\IpAddress;
use NStack\Models\SeenUpdate;
use NStack\Models\VersionControlUpdate;

class NotifyTest extends TestCase
{
public function testVersionControlUpdate()
{
$client = $this->getClientWithMockedGet('notify-version-control-update.json');

$client = new NotifyClient($this->getConfig(), $client);
$entry = $client->versionControlIndex("mobile");

$this->assertInstanceOf(VersionControlUpdate::class, $entry);
}

public function testVersionControlSeemUpdate()
{
$client = $this->getClientWithMockedPost('notify-version-control-seen-update.json');

$client = new NotifyClient($this->getConfig(), $client);
$entry = $client->markUpdateAsSeen('test', 689, 'no', 'newer_version');

$this->assertInstanceOf(SeenUpdate::class, $entry);
}
}
9 changes: 9 additions & 0 deletions tests/mocks/notify-version-control-seen-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"data": {
"id": 171992,
"guid": "test",
"answer": "no",
"type": "newer_version",
"created": "2019-09-05T07:57:13+00:00"
}
}
Loading