Skip to content

Commit

Permalink
Merge pull request #15 from fkmhrk/publish-api
Browse files Browse the repository at this point in the history
Implement publish API
  • Loading branch information
fkmhrk committed Jul 13, 2015
2 parents 761c4a8 + e4046b3 commit e7dd50c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions demo/DownloadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
$fp2 = fopen(dirname(__FILE__). '/downloadImage.jpg', 'wb');
$api->downloadBody($obj, $fp2);
echo "Download is done! Please see downloadImage.jpg\n";

// publish file
$url = $api->publish($obj);
echo "publish URL=". $url. "\n";

} catch (CloudException $e) {
echo 'failed to call Kii API '. $e->getStatus();
Expand Down
2 changes: 2 additions & 0 deletions src/ObjectAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function delete(KiiObject $object);
public function updateBody(KiiObject $object, $contentType, $data);

public function downloadBody(KiiObject $object, $fp);

public function publish(KiiObject $object);
}

?>
21 changes: 21 additions & 0 deletions src/kii/KiiObjectAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ public function downloadBody(KiiObject $object, $fp) {
}
throw new CloudException($resp->getStatus(), $resp->getAsJson());
}

public function publish(KiiObject $object) {
$c = $this->context;
$url = $c->getServerUrl().
'/apps/'. $c->getAppId().
$object->getPath().
'/body/publish';

$client = $c->getNewClient();
$client->setUrl($url);
$client->setMethod(HttpClient::HTTP_POST);
$client->setKiiHeader($c, TRUE);
$client->setContentType('application/vnd.kii.ObjectBodyPublicationRequest+json');

$resp = $client->sendJson(null);
if ($resp->getStatus() == 201) {
$respJson = $resp->getAsJson();
return $respJson['url'];
}
throw new CloudException($resp->getStatus(), $resp->getAsJson());
}
}

?>

0 comments on commit e7dd50c

Please sign in to comment.