Skip to content

Commit

Permalink
return the URL of the editable asset after creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tamw-wnet committed Mar 3, 2017
1 parent cda0e3e commit 72ed0d6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions class-PBS-Media-Manager-API-Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function get_request($query) {
/* main constructor for creating elements
* asset, episode, special, collection, season */
public function create_child($parent_id, $parent_type, $type, $attribs = array()) {
/* note that $parent_id can also be a slug */
/* on success returns the url path of the editable asset
* note that $parent_id can also be a slug */
$endpoint = "/" . $parent_type . "s/" . $parent_id . "/" . $type . "s/";
$data = array(
"data" => array(
Expand All @@ -81,7 +82,8 @@ public function create_child($parent_id, $parent_type, $type, $attribs = array()
$payload_json = json_encode($data);
$request_url = $this->base_endpoint . $endpoint;
$ch = $this->build_curl_handle($request_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($payload_json)));
$result=curl_exec($ch);
Expand All @@ -93,8 +95,9 @@ public function create_child($parent_id, $parent_type, $type, $attribs = array()
}
/* successful request will return a 201 and the location of the created object
* we'll follow that location and parse the resulting JSON to return the cid */
$result = json_decode($result, TRUE);
return $result;
preg_match("!\r\n(?:Location|URI): *(.*?) *\r\n!", $result, $matches);
$url = $matches[1];
return $url;
}


Expand Down

0 comments on commit 72ed0d6

Please sign in to comment.