diff --git a/src/Clients/CollectionsClient.php b/src/Clients/CollectionsClient.php index 3d8b6a7..6573899 100644 --- a/src/Clients/CollectionsClient.php +++ b/src/Clients/CollectionsClient.php @@ -2,14 +2,11 @@ namespace NStack\Clients; -use NStack\Exceptions\FailedToParseException; -use NStack\Models\IpAddress; - /** * Class CollectionsClient * * @package NStack\Clients - * @author Tiago Araujo + * @author Tiago Araujo */ class CollectionsClient extends NStackClient { @@ -26,22 +23,24 @@ public function view(int $collectionId): array { $response = $this->client->get($this->buildPath($this->path . '/' . $collectionId)); $contents = $response->getBody()->getContents(); + return json_decode($contents, true)['data']; } /** * createItem * - * @param int $collectionId + * @param int $collectionId * @param array $params * @return array */ public function createItem(int $collectionId, array $params): array { $response = $this->client->post($this->buildPath($this->path . '/' . $collectionId . '/items'), [ - 'form_params' => $params + 'form_params' => $params, ]); $contents = $response->getBody()->getContents(); + return json_decode($contents, true)['data']; } @@ -59,17 +58,19 @@ public function deleteItem(int $collectionId, int $itemId) /** * updateItem * - * @param int $collectionId - * @param int $itemId + * @param int $collectionId + * @param int $itemId * @param array $params * @return array */ public function updateItem(int $collectionId, int $itemId, array $params): array { - $response = $this->client->post($this->buildPath($this->path . '/' . $collectionId . '/items/' . $itemId . '/update'), [ - 'form_params' => $params + $response = $this->client->post($this->buildPath($this->path . '/' . $collectionId . '/items/' . $itemId . + '/update'), [ + 'form_params' => $params, ]); $contents = $response->getBody()->getContents(); + return json_decode($contents, true)['data']; } @@ -84,6 +85,7 @@ public function viewItem(int $collectionId, int $itemId): array { $response = $this->client->get($this->buildPath($this->path . '/' . $collectionId . '/items/' . $itemId)); $contents = $response->getBody()->getContents(); + return json_decode($contents, true)['data']; } } \ No newline at end of file diff --git a/src/Clients/FilesClient.php b/src/Clients/FilesClient.php index 84f4b64..d3e03c2 100644 --- a/src/Clients/FilesClient.php +++ b/src/Clients/FilesClient.php @@ -20,24 +20,29 @@ class FilesClient extends NStackClient /** * store * - * @param String $name - * @param array $tagsArray + * @param String $name + * @param array $tagsArray * @param DateTime $goneAt - * @param String $privacy - * @param String $imagePath + * @param String $privacy + * @param String $imagePath * @return File * @throws FailedToParseException */ - public function store(String $name, String $privacy, String $imagePath, array $tagsArray = null, DateTime $goneAt = null) - { + public function store( + String $name, + String $privacy, + String $imagePath, + array $tagsArray = null, + DateTime $goneAt = null + ) { $response = $this->client->post($this->buildPath($this->path), [ 'form_params' => [ - 'name' => $name, - 'tags' => is_null($tagsArray) ? null : implode(",", $tagsArray), - 'gone_at' => $goneAt, - 'privacy' => $privacy, - 'file' => fopen($imagePath, 'r'), - ] + 'name' => $name, + 'tags' => is_null($tagsArray) ? null : implode(",", $tagsArray), + 'gone_at' => $goneAt, + 'privacy' => $privacy, + 'file' => fopen($imagePath, 'r'), + ], ]); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); @@ -48,12 +53,12 @@ public function store(String $name, String $privacy, String $imagePath, array $t /** * storeWithPath * - * @param String $name - * @param String $privacy - * @param String $path - * @param String $mime - * @param int $size - * @param array|null $tagsArray + * @param String $name + * @param String $privacy + * @param String $path + * @param String $mime + * @param int $size + * @param array|null $tagsArray * @param DateTime|null $goneAt * @return File * @throws FailedToParseException @@ -66,23 +71,21 @@ public function storeWithPath( int $size, array $tagsArray = null, DateTime $goneAt = null - ) - { + ) { $response = $this->client->post($this->buildPath($this->path . '/path'), [ 'form_params' => [ - 'name' => $name, - 'tags' => is_null($tagsArray) ? null : implode(",", $tagsArray), - 'gone_at' => $goneAt, - 'privacy' => $privacy, - 'path' => $path, - 'mime' => $mime, - 'size' => $size, - ] + 'name' => $name, + 'tags' => is_null($tagsArray) ? null : implode(",", $tagsArray), + 'gone_at' => $goneAt, + 'privacy' => $privacy, + 'path' => $path, + 'mime' => $mime, + 'size' => $size, + ], ]); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); return new File($data['data']); } - } \ No newline at end of file diff --git a/src/Clients/IpAddressesClient.php b/src/Clients/IpAddressesClient.php index b5fd781..4c1c385 100644 --- a/src/Clients/IpAddressesClient.php +++ b/src/Clients/IpAddressesClient.php @@ -9,7 +9,7 @@ * Class IpAddressesClient * * @package NStack\Clients - * @author Tiago Araujo + * @author Tiago Araujo */ class IpAddressesClient extends NStackClient { @@ -28,13 +28,14 @@ public function index(): IpAddress $response = $this->client->get($this->buildPath($this->path)); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new IpAddress($data['data']); } /** * show * - * @param String $ip + * @param String $ip * @return IpAddress * @throws FailedToParseException * @author Tiago Araujo @@ -44,6 +45,7 @@ public function show(String $ip): IpAddress $response = $this->client->get($this->buildPath($this->path . '?ip=' . $ip)); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new IpAddress($data['data']); } } \ No newline at end of file diff --git a/src/Clients/LanguagesClient.php b/src/Clients/LanguagesClient.php index 42d4b41..014993f 100644 --- a/src/Clients/LanguagesClient.php +++ b/src/Clients/LanguagesClient.php @@ -48,8 +48,8 @@ public function index($page = 1, $limit = 500): array * search * * @param String $term - * @param int $page - * @param int $limit + * @param int $page + * @param int $limit * @return array * @throws FailedToParseException */ diff --git a/src/Clients/LocalizeClient.php b/src/Clients/LocalizeClient.php index 33eeb1b..c8c2b48 100644 --- a/src/Clients/LocalizeClient.php +++ b/src/Clients/LocalizeClient.php @@ -2,7 +2,6 @@ namespace NStack\Clients; -use NStack\Models\Country; use NStack\Models\Resource; /** diff --git a/src/Clients/LocalizeLanguagesClient.php b/src/Clients/LocalizeLanguagesClient.php index d3ba8c7..0829794 100644 --- a/src/Clients/LocalizeLanguagesClient.php +++ b/src/Clients/LocalizeLanguagesClient.php @@ -49,7 +49,7 @@ public function bestFit(string $platform): Language $response = $this->client->get($this->buildPath($this->path . '/' . $platform . '/languages/best_fit')); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new Language($data['data']); } - } \ No newline at end of file diff --git a/src/Clients/NotifyClient.php b/src/Clients/NotifyClient.php index 6a8f7cd..5600be3 100644 --- a/src/Clients/NotifyClient.php +++ b/src/Clients/NotifyClient.php @@ -10,7 +10,7 @@ * Class NotifyClient * * @package NStack\Clients - * @author Tiago Araujo + * @author Tiago Araujo */ class NotifyClient extends NStackClient { @@ -20,7 +20,7 @@ class NotifyClient extends NStackClient /** * versionControlIndex * - * @param String $platform + * @param String $platform * @param String|null $currentVersion * @param String|null $lastVersion * @param String|null $test @@ -33,8 +33,7 @@ public function versionControlIndex( String $currentVersion = null, String $lastVersion = null, String $test = null - ): VersionControlUpdate - { + ): VersionControlUpdate { $path = $this->buildPath($this->path) . "?platform=" . $platform; if ($currentVersion) { $path = $path . '¤t_version=' . $currentVersion; @@ -49,6 +48,7 @@ public function versionControlIndex( $response = $this->client->get($path); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new VersionControlUpdate($data); } @@ -56,7 +56,7 @@ public function versionControlIndex( * markUpdateAsSeen * * @param String $guid - * @param int $updateId + * @param int $updateId * @param String $answer * @param String $type * @return SeenUpdate @@ -70,11 +70,11 @@ public function markUpdateAsSeen(String $guid, int $updateId, String $answer, St 'update_id' => $updateId, 'answer' => $answer, 'type' => $type, - ] + ], ]); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new SeenUpdate($data['data']); } - } \ No newline at end of file diff --git a/src/Clients/ProposalsClient.php b/src/Clients/ProposalsClient.php index f2cd96b..ca0c760 100644 --- a/src/Clients/ProposalsClient.php +++ b/src/Clients/ProposalsClient.php @@ -3,7 +3,6 @@ namespace NStack\Clients; use NStack\Exceptions\FailedToParseException; -use NStack\Models\IpAddress; use NStack\Models\Proposal; use NStack\Models\ProposalDeleted; @@ -43,11 +42,11 @@ public function index(String $guid = null): array * store * * @param String|null $guid - * @param String $key - * @param String $value - * @param String $platform - * @param String $locale - * @param String $section + * @param String $key + * @param String $value + * @param String $platform + * @param String $locale + * @param String $section * @return Proposal * @throws FailedToParseException */ @@ -58,32 +57,31 @@ public function store( String $platform, String $locale, String $section - ) - { + ) { $response = $this->client->post($this->buildPath($this->path), [ 'form_params' => [ - 'key' => $key, - 'value' => $value, - 'locale' => $locale, - 'platform' => $platform, - 'guid' => $guid, - 'section' => $section, - ] + 'key' => $key, + 'value' => $value, + 'locale' => $locale, + 'platform' => $platform, + 'guid' => $guid, + 'section' => $section, + ], ]); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new Proposal($data['data']); } /** * delete * - * @param int $id + * @param int $id * @param String $guid */ public function delete(int $id, String $guid) { $this->client->delete($this->buildPath($this->path . '/' . $id . '?guid=' . $guid)); } - } \ No newline at end of file diff --git a/src/Clients/TimezoneClient.php b/src/Clients/TimezoneClient.php index 0d6e758..aca0a03 100644 --- a/src/Clients/TimezoneClient.php +++ b/src/Clients/TimezoneClient.php @@ -48,6 +48,7 @@ public function show($id): Timezone $response = $this->client->get($this->buildPath($this->path . '/' . $id)); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new Timezone($data['data']); } @@ -64,7 +65,7 @@ public function showByLatLng(float $lat, float $lng): Timezone $response = $this->client->get($this->buildPath($this->path . '/by_lat_lng?lat_lng=' . $lat . ',' . $lng)); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new Timezone($data['data']); } - } \ No newline at end of file diff --git a/src/Clients/UgcClient.php b/src/Clients/UgcClient.php index 07c9ec7..8bfcc31 100644 --- a/src/Clients/UgcClient.php +++ b/src/Clients/UgcClient.php @@ -2,12 +2,6 @@ namespace NStack\Clients; -use NStack\Exceptions\FailedToParseException; -use NStack\Models\File; -use NStack\Models\IpAddress; -use NStack\Models\Proposal; -use NStack\Models\ProposalDeleted; - /** * Class UgcClient * @@ -22,15 +16,15 @@ class UgcClient extends NStackClient /** * storePushLog * - * @param String $provider - * @param String $key - * @param String $type - * @param bool $succeeded + * @param String $provider + * @param String $key + * @param String $type + * @param bool $succeeded * @param String|null $request * @param String|null $response - * @param int|null $userId + * @param int|null $userId * @param String|null $relationType - * @param int|null $relationId + * @param int|null $relationId */ public function storePushLog( String $provider, @@ -42,8 +36,7 @@ public function storePushLog( int $userId = null, String $relationType = null, int $relationId = null - ) - { + ) { $this->client->post($this->buildPath($this->path), [ 'body' => '{ "provider": "' . $provider . '", @@ -55,8 +48,7 @@ public function storePushLog( "user_id": ' . $userId . ' "relation_type": "' . $relationType . '", "relation_id": ' . $relationId . ' - }' + }', ]); } - } \ No newline at end of file diff --git a/src/Clients/ValidatorsClient.php b/src/Clients/ValidatorsClient.php index b66b7af..1a75bc0 100644 --- a/src/Clients/ValidatorsClient.php +++ b/src/Clients/ValidatorsClient.php @@ -4,14 +4,13 @@ use NStack\Exceptions\FailedToParseException; use NStack\Models\EmailValidation; -use NStack\Models\IpAddress; use NStack\Models\PhoneValidation; /** * Class ValidatorsClient * * @package NStack\Clients - * @author Tiago Araujo + * @author Tiago Araujo */ class ValidatorsClient extends NStackClient { @@ -31,16 +30,17 @@ public function email(String $email): EmailValidation $response = $this->client->get($this->buildPath($this->path . '/email?email=' . $email)); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new EmailValidation($data); } /** * phone * - * @param String $phone - * @param String|null $fallbackCountryCode + * @param String $phone + * @param String|null $fallbackCountryCode * @param Boolean|null $validateWithTwilio - * @param String|null $twilioType + * @param String|null $twilioType * @return PhoneValidation * @throws FailedToParseException * @author Tiago Araujo @@ -50,8 +50,7 @@ public function phone( String $fallbackCountryCode = null, bool $validateWithTwilio = null, String $twilioType = null - ): PhoneValidation - { + ): PhoneValidation { $path = $this->buildPath($this->path . '/phone?phone=' . $phone); if ($fallbackCountryCode) { @@ -67,6 +66,7 @@ public function phone( $response = $this->client->get($path); $contents = $response->getBody()->getContents(); $data = json_decode($contents, true); + return new PhoneValidation($data); } } \ No newline at end of file diff --git a/src/Models/EmailValidation.php b/src/Models/EmailValidation.php index 0795fbb..182c17e 100644 --- a/src/Models/EmailValidation.php +++ b/src/Models/EmailValidation.php @@ -6,7 +6,7 @@ * Class EmailValidation * * @package NStack\Models - * @author Tiago Araujo + * @author Tiago Araujo */ class EmailValidation extends Model { @@ -42,5 +42,4 @@ public function isOk(): bool { return $this->ok; } - } \ No newline at end of file diff --git a/src/Models/File.php b/src/Models/File.php index 77c38b8..e091a56 100644 --- a/src/Models/File.php +++ b/src/Models/File.php @@ -53,18 +53,18 @@ class File extends Model */ public function parse(array $data) { - $this->id = (int)$data['id']; - $this->name = (string)$data['name']; - $this->tags = (string)$data['tags']; - $this->privacy = (string)$data['privacy']; - $this->goneAt = (string)$data['gone_at']; - $this->size = (string)$data['size']; - $this->mime = (string)$data['mime']; - $this->password = (string)$data['password']; - $this->url = (string)$data['url']; - $this->cdnUrl = (string)$data['cdn_url']; - $this->showUrl = (string)$data['show_url']; - $this->downloadUrl = (string)$data['download_url']; + $this->id = (int)$data['id']; + $this->name = (string)$data['name']; + $this->tags = (string)$data['tags']; + $this->privacy = (string)$data['privacy']; + $this->goneAt = (string)$data['gone_at']; + $this->size = (string)$data['size']; + $this->mime = (string)$data['mime']; + $this->password = (string)$data['password']; + $this->url = (string)$data['url']; + $this->cdnUrl = (string)$data['cdn_url']; + $this->showUrl = (string)$data['show_url']; + $this->downloadUrl = (string)$data['download_url']; } /** @@ -75,19 +75,18 @@ public function parse(array $data) public function toArray(): array { return [ - 'id' => $this->id, - 'name' => $this->name, - 'tags' => $this->tags, - 'privacy' => $this->privacy, - 'gone_at' => $this->goneAt, - 'size' => $this->size, - 'password' => $this->password, - 'url' => $this->url, - 'cdn_url' => $this->cdnUrl, - 'show_url' => $this->showUrl, - 'download_url' => $this->downloadUrl, - 'mime' => $this->mime, + 'id' => $this->id, + 'name' => $this->name, + 'tags' => $this->tags, + 'privacy' => $this->privacy, + 'gone_at' => $this->goneAt, + 'size' => $this->size, + 'password' => $this->password, + 'url' => $this->url, + 'cdn_url' => $this->cdnUrl, + 'show_url' => $this->showUrl, + 'download_url' => $this->downloadUrl, + 'mime' => $this->mime, ]; } - } \ No newline at end of file diff --git a/src/Models/IpAddress.php b/src/Models/IpAddress.php index e839fc0..3ddfb58 100644 --- a/src/Models/IpAddress.php +++ b/src/Models/IpAddress.php @@ -6,7 +6,7 @@ * Class IpAddress * * @package NStack\Models - * @author Tiago Araujo + * @author Tiago Araujo */ class IpAddress extends Model { @@ -85,20 +85,20 @@ public function parse(array $data) public function toArray(): array { return [ - 'id' => $this->id, - 'ip_start' => $this->ipStart, - 'ip_end' => $this->ipEnd, - 'country' => $this->country, - 'state_prov' => $this->stateProv, - 'city' => $this->city, - 'lat' => $this->lat, - 'lng' => $this->lng, + 'id' => $this->id, + 'ip_start' => $this->ipStart, + 'ip_end' => $this->ipEnd, + 'country' => $this->country, + 'state_prov' => $this->stateProv, + 'city' => $this->city, + 'lat' => $this->lat, + 'lng' => $this->lng, 'time_zone_offset' => $this->timeZoneOffset, - 'time_zone_name' => $this->timeZoneName, - 'isp_name' => $this->ispName, - 'connection_type' => $this->connectionType, - 'type' => $this->type, - 'required_ip' => $this->requiredIp, + 'time_zone_name' => $this->timeZoneName, + 'isp_name' => $this->ispName, + 'connection_type' => $this->connectionType, + 'type' => $this->type, + 'required_ip' => $this->requiredIp, ]; } @@ -213,5 +213,4 @@ public function getRequiredIp(): string { return $this->requiredIp; } - } \ No newline at end of file diff --git a/src/Models/Model.php b/src/Models/Model.php index 1193c0c..a194645 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -20,7 +20,7 @@ public function __construct(array $data) } catch (\Throwable $e) { $message = sprintf('Failed to parse %s: %s', get_called_class(), $e->getMessage()); - if(!empty($data['id'])) { + if (!empty($data['id'])) { $message .= ' ID: ' . $data['id']; } diff --git a/src/Models/PhoneValidation.php b/src/Models/PhoneValidation.php index 8f7c471..b7a27bb 100644 --- a/src/Models/PhoneValidation.php +++ b/src/Models/PhoneValidation.php @@ -6,7 +6,7 @@ * Class PhoneValidation * * @package NStack\Models - * @author Tiago Araujo + * @author Tiago Araujo */ class PhoneValidation extends Model { @@ -27,9 +27,9 @@ class PhoneValidation extends Model */ public function parse(array $data) { - $this->ok = (String)$data['ok']; - $this->countryCode = (String)$data['country_code']; - $this->nationalNumber = (String)$data['national_number']; + $this->ok = (String)$data['ok']; + $this->countryCode = (String)$data['country_code']; + $this->nationalNumber = (String)$data['national_number']; } /** @@ -41,9 +41,9 @@ public function parse(array $data) public function toArray(): array { return [ - 'ok' => $this->ok, - 'country_code' => $this->countryCode, - 'national_number' => $this->nationalNumber, + 'ok' => $this->ok, + 'country_code' => $this->countryCode, + 'national_number' => $this->nationalNumber, ]; } @@ -70,5 +70,4 @@ public function getNationalNumber(): String { return $this->nationalNumber; } - } \ No newline at end of file diff --git a/src/Models/Proposal.php b/src/Models/Proposal.php index 8a60dc9..54bd858 100644 --- a/src/Models/Proposal.php +++ b/src/Models/Proposal.php @@ -38,13 +38,13 @@ class Proposal extends Model */ public function parse(array $data) { - $this->id = (int)$data['id']; - $this->applicationId = (int)$data['application_id']; - $this->key = (string)$data['key']; - $this->section = (string)$data['section']; - $this->locale = (string)$data['locale']; - $this->value = (string)$data['value']; - $this->canDelete = (string)$data['can_delete']; + $this->id = (int)$data['id']; + $this->applicationId = (int)$data['application_id']; + $this->key = (string)$data['key']; + $this->section = (string)$data['section']; + $this->locale = (string)$data['locale']; + $this->value = (string)$data['value']; + $this->canDelete = (string)$data['can_delete']; } /** @@ -55,14 +55,13 @@ public function parse(array $data) public function toArray(): array { return [ - 'id' => $this->id, - 'application_id' => $this->applicationId, - 'key' => $this->key, - 'section' => $this->section, - 'locale' => $this->locale, - 'value' => $this->value, - 'can_delete' => $this->canDelete, + 'id' => $this->id, + 'application_id' => $this->applicationId, + 'key' => $this->key, + 'section' => $this->section, + 'locale' => $this->locale, + 'value' => $this->value, + 'can_delete' => $this->canDelete, ]; } - } \ No newline at end of file diff --git a/src/Models/SeenUpdate.php b/src/Models/SeenUpdate.php index 99b3844..4d148d8 100644 --- a/src/Models/SeenUpdate.php +++ b/src/Models/SeenUpdate.php @@ -36,11 +36,11 @@ class SeenUpdate extends Model */ 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']); + $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']); } /** @@ -98,5 +98,4 @@ public function getCreated(): DateTime { return $this->created; } - } \ No newline at end of file diff --git a/src/Models/VersionControlUpdate.php b/src/Models/VersionControlUpdate.php index 91df120..1e402d1 100644 --- a/src/Models/VersionControlUpdate.php +++ b/src/Models/VersionControlUpdate.php @@ -44,9 +44,9 @@ public function parse(array $data) public function toArray(): array { return [ - 'update' => $this->update, + 'update' => $this->update, 'update_versions' => $this->updateVersions, - 'new_in_version' => $this->newInVersion, + 'new_in_version' => $this->newInVersion, 'new_in_versions' => $this->newInVersions, ]; } @@ -82,5 +82,4 @@ public function getNewInVersions(): array { return $this->newInVersions; } - } \ No newline at end of file diff --git a/src/Models/VersionUpdate.php b/src/Models/VersionUpdate.php index d243320..8f04f9c 100644 --- a/src/Models/VersionUpdate.php +++ b/src/Models/VersionUpdate.php @@ -52,14 +52,12 @@ public function parse(array $data) public function toArray(): array { return [ - 'id' => $this->id, - 'version' => $this->version, - 'update' => $this->update, + 'id' => $this->id, + 'version' => $this->version, + 'update' => $this->update, 'new_in_version' => $this->newInVersion, - 'change_log' => $this->changeLog, - 'file_url' => $this->fileUrl, + 'change_log' => $this->changeLog, + 'file_url' => $this->fileUrl, ]; } - - } \ No newline at end of file