Skip to content

Commit

Permalink
add queryargs option to all get_items_of_type functions, and make the…
Browse files Browse the repository at this point in the history
… private option for get_asset be optional and replaceable with an array
  • Loading branch information
tamw-wnet committed Jul 28, 2017
1 parent f76d645 commit 07c42f9
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions class-PBS-Media-Manager-API-Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,18 @@ public function delete_object($id, $type) {

/* main constructor for getting single items
* asset, episode, special, collection, season, show, franchise, station */
public function get_item_of_type($id, $type, $private=false) {
public function get_item_of_type($id, $type, $private=false, $queryargs = array()) {
/* note that $id can also be a slug */
$query = "/" . $type . "s/" . $id . "/";
$endpoint = "/" . $type . "s/" . $id . "/";
// unpublished, 'private' items have to do a GET on the update endpoint
if ($private) {
$query = $this->_get_update_endpoint($id, $type);
if ($private === true) {
$endpoint = $this->_get_update_endpoint($id, $type);
}
return $this->get_request($query);
if (empty($queryargs) && is_array($private)) {
$queryargs = $private;
}
$querystring = $this->build_pbs_querystring($queryargs);
return $this->get_request($endpoint . $querystring);
}


Expand Down Expand Up @@ -368,40 +372,40 @@ public function get_changelog($args = array()) {

/* shortcut functions for single items */

public function get_asset($id, $private=false) {
return $this->get_item_of_type($id, 'asset', $private);
public function get_asset($id, $private=false, $queryargs = array()) {
return $this->get_item_of_type($id, 'asset', $private, $queryargs);
}

public function get_episode($id) {
return $this->get_item_of_type($id, 'episode');
public function get_episode($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'episode', $queryargs);
}

public function get_special($id) {
return $this->get_item_of_type($id, 'special');
public function get_special($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'special', $queryargs);
}

public function get_collection($id) {
return $this->get_item_of_type($id, 'collection');
public function get_collection($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'collection', $queryargs);
}

public function get_season($id) {
return $this->get_item_of_type($id, 'season');
public function get_season($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'season', $queryargs);
}

public function get_show($id) {
return $this->get_item_of_type($id, 'show');
public function get_show($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'show', $queryargs);
}

public function get_remote_asset($id) {
return $this->get_item_of_type($id, 'remote-asset');
public function get_remote_asset($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'remote-asset', $queryargs);
}

public function get_franchise($id) {
return $this->get_item_of_type($id, 'franchise');
public function get_franchise($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'franchise', $queryargs);
}

public function get_station($id) {
return $this->get_item_of_type($id, 'station');
public function get_station($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'station', $queryargs);
}


Expand Down

1 comment on commit 07c42f9

@tamw-wnet
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@augustuswm @acrosman RE #10 I think I've got a non-breaking solution here. If the 3rd argument is not an array and is 'true', it is read as the 'private' arg. If the 3rd argument is an array, it is the queryargs arg. If there is a 4th argument, and the 3rd argument is not an array, the 4th argument is the queryargs arg.

Please sign in to comment.