Skip to content

Commit

Permalink
Merge 9ea391a into b5bb416
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sc committed Jul 27, 2023
2 parents b5bb416 + 9ea391a commit ec4cb5d
Show file tree
Hide file tree
Showing 96 changed files with 765 additions and 846 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
php: [ 7.3, 7.4, 8.0 ]
php: [ 7.3, 7.4, 8.0, 8.2 ]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
@@ -1,6 +1,7 @@
[7.0.0](#v7.0.0) / [unreleased]
==================
* BREAKING: Replace static `Podio` client with instantiable `PodioClient` class. #228
* BREAKING: Replace update/save methods on instances with static methods #234

[6.1.1](#v6.1.1) / 2023-06-12
==================
Expand Down
2 changes: 1 addition & 1 deletion lib/PodioCollection.php
Expand Up @@ -15,7 +15,7 @@ class PodioCollection implements IteratorAggregate, ArrayAccess, Countable
* Constructor. Pass in an array of PodioObject objects.
* @param PodioClient $podio_client not used, but required for compatibility with other Podio collections.
*/
public function __construct(PodioClient $podio_client, $items = array())
public function __construct($items = array())
{
foreach ($items as $item) {
$this->offsetSet(null, $item);
Expand Down
21 changes: 9 additions & 12 deletions lib/PodioObject.php
Expand Up @@ -7,13 +7,10 @@ class PodioObject
private $__properties = array();
private $__relationships = array();

/** @var PodioClient */
protected $podio_client;
protected $__id_column;

public function __construct(PodioClient $podio_client)
public function __construct()
{
$this->podio_client = $podio_client;
}

public function init($default_attributes = array())
Expand Down Expand Up @@ -57,7 +54,7 @@ public function init($default_attributes = array())
$class_name = 'Podio'.$property['type'];

if ($type == 'has_one') {
$child = is_object($default_attributes[$name]) ? $default_attributes[$name] : new $class_name($this->podio_client, $default_attributes[$name]);
$child = is_object($default_attributes[$name]) ? $default_attributes[$name] : new $class_name($default_attributes[$name]);
$child->add_relationship($this, $name);
$this->set_attribute($name, $child);
} elseif ($type == 'has_many' && is_array($default_attributes[$name])) {
Expand All @@ -69,17 +66,17 @@ public function init($default_attributes = array())

// Make sure we pass along info on whether the values property
// contains API style values or not
$collection = new PodioItemFieldCollection($this->podio_client, $values, $has_api_values);
$collection = new PodioItemFieldCollection($values, $has_api_values);
} elseif ($class_name == 'PodioAppField') {
$values = $default_attributes[$name];
$collection = new PodioAppFieldCollection($this->podio_client, $values);
$collection = new PodioAppFieldCollection($values);
} else {
$values = array();
foreach ($default_attributes[$name] as $value) {
$child = is_object($value) ? $value : new $class_name($this->podio_client, $value);
$child = is_object($value) ? $value : new $class_name($value);
$values[] = $child;
}
$collection = new PodioCollection($this->podio_client, $values);
$collection = new PodioCollection($values);
}
$collection->add_relationship($this, $name);
$this->set_attribute($name, $collection);
Expand Down Expand Up @@ -187,7 +184,7 @@ protected function set_attribute($name, $value)
throw new PodioDataIntegrityError("Attribute cannot be assigned. Property '{$name}' doesn't exist.");
}

public static function listing($response_or_attributes, PodioClient $podio_client)
public static function listing(PodioClient $podio_client, $response_or_attributes)
{
if ($response_or_attributes) {
if (is_object($response_or_attributes) && get_class($response_or_attributes) == 'PodioResponse') {
Expand All @@ -204,15 +201,15 @@ public static function listing($response_or_attributes, PodioClient $podio_clien
}
}

public static function member($response, PodioClient $podio_client)
public static function member(PodioClient $podio_client, $response)
{
if ($response) {
$class_name = get_called_class();
return new $class_name($podio_client, array_merge($response instanceof PodioResponse ? $response->json_body() : $response, array('__api_values' => true)));
}
}

public static function collection($response, $collection_type = "PodioCollection", PodioClient $podio_client)
public static function collection(PodioClient $podio_client, $response, $collection_type = "PodioCollection")
{
if ($response) {
$body = $response->json_body();
Expand Down
11 changes: 9 additions & 2 deletions lib/error/PodioError.php
Expand Up @@ -2,13 +2,20 @@

class PodioError extends Exception
{
/** @var array|null */
public $body;
public $status;
public $url;
public $request;

/**
* @param string|null $body
* @param int|null $status
* @param string|null $url
*/
public function __construct($body, $status, $url)
{
$this->body = json_decode($body, true);
$this->body = $body !== null ? json_decode($body, true) : null;
$this->status = $status;
$this->url = $url;
$this->request = $this->body['request'] ?? null;
Expand All @@ -17,7 +24,7 @@ public function __construct($body, $status, $url)

public function __toString()
{
$str = $str = get_class($this);
$str = get_class($this);
if (!empty($this->body['error_description'])) {
$str .= ': "'.$this->body['error_description'].'"';
}
Expand Down
8 changes: 4 additions & 4 deletions models/PodioAction.php
Expand Up @@ -4,9 +4,9 @@
*/
class PodioAction extends PodioObject
{
public function __construct(PodioClient $podio_client, $attributes = array())
public function __construct($attributes = array())
{
parent::__construct($podio_client);
parent::__construct();
$this->property('action_id', 'integer', array('id' => true));
$this->property('type', 'string');
$this->property('data', 'hash');
Expand All @@ -20,8 +20,8 @@ public function __construct(PodioClient $podio_client, $attributes = array())
/**
* @see https://developers.podio.com/doc/actions/get-action-1701120
*/
public static function get($action_id, PodioClient $podio_client)
public static function get(PodioClient $podio_client, $action_id)
{
return self::member($podio_client->get("/action/{$action_id}"), $podio_client);
return self::member($podio_client, $podio_client->get("/action/{$action_id}"));
}
}
4 changes: 2 additions & 2 deletions models/PodioActivity.php
Expand Up @@ -4,9 +4,9 @@
*/
class PodioActivity extends PodioObject
{
public function __construct(PodioClient $podio_client, $attributes = array())
public function __construct($attributes = array())
{
parent::__construct($podio_client);
parent::__construct();
$this->property('id', 'integer');
$this->property('type', 'string');
$this->property('activity_type', 'string');
Expand Down
60 changes: 30 additions & 30 deletions models/PodioApp.php
Expand Up @@ -4,9 +4,9 @@
*/
class PodioApp extends PodioObject
{
public function __construct(PodioClient $podio_client, $attributes = array())
public function __construct($attributes = array())
{
parent::__construct($podio_client);
parent::__construct();
$this->property('app_id', 'integer', array('id' => true));
$this->property('original', 'integer');
$this->property('original_revision', 'integer');
Expand Down Expand Up @@ -38,79 +38,79 @@ public function __construct(PodioClient $podio_client, $attributes = array())
/**
* @see https://developers.podio.com/doc/applications/get-app-22349
*/
public static function get($app_id, $attributes = array(), PodioClient $podio_client)
public static function get(PodioClient $podio_client, $app_id, $attributes = array())
{
return self::member($podio_client->get("/app/{$app_id}", $attributes), $podio_client);
return self::member($podio_client, $podio_client->get("/app/{$app_id}", $attributes));
}

/**
* @see https://developers.podio.com/doc/applications/get-all-user-apps-5902728
*/
public static function get_all($attributes = array(), PodioClient $podio_client)
public static function get_all(PodioClient $podio_client, $attributes = array())
{
return self::listing($podio_client->get("/app/v2/", $attributes), $podio_client);
return self::listing($podio_client, $podio_client->get("/app/v2/", $attributes));
}

/**
* @see https://developers.podio.com/doc/applications/get-top-apps-22476
*/
public static function get_top($attributes = array(), PodioClient $podio_client)
public static function get_top(PodioClient $podio_client, $attributes = array())
{
return self::listing($podio_client->get("/app/top/", $attributes), $podio_client);
return self::listing($podio_client, $podio_client->get("/app/top/", $attributes));
}

/**
* @see https://developers.podio.com/doc/applications/get-top-apps-for-organization-1671395
*/
public static function get_top_for_org($org_id, $attributes = array(), PodioClient $podio_client)
public static function get_top_for_org(PodioClient $podio_client, $org_id, $attributes = array())
{
return self::listing($podio_client->get("/app/org/{$org_id}/top/", $attributes), $podio_client);
return self::listing($podio_client, $podio_client->get("/app/org/{$org_id}/top/", $attributes));
}

/**
* @see https://developers.podio.com/doc/applications/get-app-on-space-by-url-label-477105
*/
public static function get_for_url($space_id, $url_label, $attributes = array(), PodioClient $podio_client)
public static function get_for_url(PodioClient $podio_client, $space_id, $url_label, $attributes = array())
{
return self::member($podio_client->get("/app/space/{$space_id}/{$url_label}", $attributes), $podio_client);
return self::member($podio_client, $podio_client->get("/app/space/{$space_id}/{$url_label}", $attributes));
}

/**
* @see https://developers.podio.com/doc/applications/get-apps-by-space-22478
*/
public static function get_for_space($space_id, $attributes = array(), PodioClient $podio_client)
public static function get_for_space(PodioClient $podio_client, $space_id, $attributes = array())
{
return self::listing($podio_client->get("/app/space/{$space_id}/", $attributes), $podio_client);
return self::listing($podio_client, $podio_client->get("/app/space/{$space_id}/", $attributes));
}

/**
* @see https://developers.podio.com/doc/applications/add-new-app-22351
*/
public static function create($attributes = array(), $silent = false, PodioClient $podio_client)
public static function create(PodioClient $podio_client, $attributes = array(), $silent = false)
{
return self::member($podio_client->post($podio_client->url_with_options("/app/", array('silent' => $silent)), $attributes), $podio_client);
return self::member($podio_client, $podio_client->post($podio_client->url_with_options("/app/", array('silent' => $silent)), $attributes));
}

/**
* @see https://developers.podio.com/doc/applications/update-app-22352
*/
public static function update($app_id, $attributes = array(), $silent = false, PodioClient $podio_client)
public static function update(PodioClient $podio_client, $app_id, $attributes = array(), $silent = false)
{
return $podio_client->put($podio_client->url_with_options("/app/{$app_id}", array('silent' => $silent)), $attributes);
}

/**
* @see https://developers.podio.com/doc/applications/delete-app-43693
*/
public static function delete($app_id, $silent = false, PodioClient $podio_client)
public static function delete(PodioClient $podio_client, $app_id, $silent = false)
{
return $podio_client->delete($podio_client->url_with_options("/app/{$app_id}", array('silent' => $silent)));
}

/**
* @see https://developers.podio.com/doc/applications/install-app-22506
*/
public static function install($app_id, $attributes = array(), PodioClient $podio_client)
public static function install(PodioClient $podio_client, $app_id, $attributes = array())
{
$body = $podio_client->post("/app/{$app_id}/install", $attributes)->json_body();
return $body['app_id'];
Expand All @@ -119,67 +119,67 @@ public static function install($app_id, $attributes = array(), PodioClient $podi
/**
* @see https://developers.podio.com/doc/applications/update-app-order-22463
*/
public static function update_org($space_id, $attributes = array(), PodioClient $podio_client)
public static function update_org(PodioClient $podio_client, $space_id, $attributes = array())
{
return $podio_client->put("/app/space/{$space_id}/order", $attributes);
}

/**
* @see https://developers.podio.com/doc/applications/activate-app-43822
*/
public static function activate($app_id, PodioClient $podio_client)
public static function activate(PodioClient $podio_client, $app_id)
{
return $podio_client->post("/app/{$app_id}/activate");
}

/**
* @see https://developers.podio.com/doc/applications/deactivate-app-43821
*/
public static function deactivate($app_id, PodioClient $podio_client)
public static function deactivate(PodioClient $podio_client, $app_id)
{
return $podio_client->post("/app/{$app_id}/deactivate");
}

/**
* @see https://developers.podio.com/doc/applications/get-calculations-for-app-773005
*/
public static function calculations($app_id, PodioClient $podio_client)
public static function calculations(PodioClient $podio_client, $app_id)
{
return self::listing($podio_client->get("/app/{$app_id}/calculation/"), $podio_client);
return self::listing($podio_client, $podio_client->get("/app/{$app_id}/calculation/"));
}

/**
* @see https://developers.podio.com/doc/applications/get-features-43648
*/
public static function features($attributes = array(), PodioClient $podio_client)
public static function features(PodioClient $podio_client, $attributes = array())
{
return $podio_client->get("/app/features/")->json_body();
}

/**
* @see https://developers.podio.com/doc/applications/get-app-dependencies-39159
*/
public static function dependencies($app_id, PodioClient $podio_client)
public static function dependencies(PodioClient $podio_client, $app_id)
{
$result = $podio_client->get("/app/{$app_id}/dependencies/")->json_body();
$result['apps'] = self::listing($result['apps'], $podio_client);
$result['apps'] = self::listing($podio_client, $result['apps']);
return $result;
}

/**
* @see https://developers.podio.com/doc/applications/get-space-app-dependencies-45779
*/
public static function dependencies_space($space_id, PodioClient $podio_client)
public static function dependencies_space(PodioClient $podio_client, $space_id)
{
$result = $podio_client->get("/space/{$space_id}/dependencies/")->json_body();
$result['apps'] = self::listing($result['apps'], $podio_client);
$result['apps'] = self::listing($podio_client, $result['apps']);
return $result;
}

/**
* Activate app in space. Only applicable to Platform
*/
public static function activate_for_space($app_id, $space_id, $attributes = array(), PodioClient $podio_client)
public static function activate_for_space(PodioClient $podio_client, $app_id, $space_id, $attributes = array())
{
return $podio_client->put("/app/{$app_id}/activate/{$space_id}", $attributes);
}
Expand Down

0 comments on commit ec4cb5d

Please sign in to comment.