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
22 changes: 12 additions & 10 deletions src/Clients/CollectionsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace NStack\Clients;

use NStack\Exceptions\FailedToParseException;
use NStack\Models\IpAddress;

/**
* Class CollectionsClient
*
* @package NStack\Clients
* @author Tiago Araujo <tiar@nodesagency.com>
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class CollectionsClient extends NStackClient
{
Expand All @@ -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'];
}

Expand All @@ -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'];
}

Expand All @@ -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'];
}
}
61 changes: 32 additions & 29 deletions src/Clients/FilesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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']);
}

}
6 changes: 4 additions & 2 deletions src/Clients/IpAddressesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Class IpAddressesClient
*
* @package NStack\Clients
* @author Tiago Araujo <tiar@nodesagency.com>
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class IpAddressesClient extends NStackClient
{
Expand All @@ -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 <tiar@nodesagency.com>
Expand All @@ -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']);
}
}
4 changes: 2 additions & 2 deletions src/Clients/LanguagesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 0 additions & 1 deletion src/Clients/LocalizeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace NStack\Clients;

use NStack\Models\Country;
use NStack\Models\Resource;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Clients/LocalizeLanguagesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

}
14 changes: 7 additions & 7 deletions src/Clients/NotifyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Class NotifyClient
*
* @package NStack\Clients
* @author Tiago Araujo <tiar@nodesagency.com>
* @author Tiago Araujo <tiar@nodesagency.com>
*/
class NotifyClient extends NStackClient
{
Expand All @@ -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
Expand All @@ -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 . '&current_version=' . $currentVersion;
Expand All @@ -49,14 +48,15 @@ public function versionControlIndex(
$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 int $updateId
* @param String $answer
* @param String $type
* @return SeenUpdate
Expand All @@ -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']);
}

}
32 changes: 15 additions & 17 deletions src/Clients/ProposalsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace NStack\Clients;

use NStack\Exceptions\FailedToParseException;
use NStack\Models\IpAddress;
use NStack\Models\Proposal;
use NStack\Models\ProposalDeleted;

Expand Down Expand Up @@ -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
*/
Expand All @@ -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));
}

}
3 changes: 2 additions & 1 deletion src/Clients/TimezoneClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand All @@ -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']);
}

}
Loading