mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +01:00
Add phame.queryblog and phame.querypost Conduit calls.
Summary: This implements Conduit calls for querying Phame blogs and Phame posts. Test Plan: Made some calls and they seem to generally work. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T3695 Differential Revision: https://secure.phabricator.com/D7478
This commit is contained in:
parent
10a9f6501f
commit
24579e2956
4 changed files with 223 additions and 0 deletions
|
@ -195,6 +195,9 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_paste_create_Method' => 'applications/paste/conduit/ConduitAPI_paste_create_Method.php',
|
||||
'ConduitAPI_paste_info_Method' => 'applications/paste/conduit/ConduitAPI_paste_info_Method.php',
|
||||
'ConduitAPI_paste_query_Method' => 'applications/paste/conduit/ConduitAPI_paste_query_Method.php',
|
||||
'ConduitAPI_phame_Method' => 'applications/phame/conduit/ConduitAPI_phame_Method.php',
|
||||
'ConduitAPI_phame_query_Method' => 'applications/phame/conduit/ConduitAPI_phame_query_Method.php',
|
||||
'ConduitAPI_phame_queryposts_Method' => 'applications/phame/conduit/ConduitAPI_phame_queryposts_Method.php',
|
||||
'ConduitAPI_phid_Method' => 'applications/phid/conduit/ConduitAPI_phid_Method.php',
|
||||
'ConduitAPI_phid_info_Method' => 'applications/phid/conduit/ConduitAPI_phid_info_Method.php',
|
||||
'ConduitAPI_phid_lookup_Method' => 'applications/phid/conduit/ConduitAPI_phid_lookup_Method.php',
|
||||
|
@ -2406,6 +2409,9 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_paste_create_Method' => 'ConduitAPI_paste_Method',
|
||||
'ConduitAPI_paste_info_Method' => 'ConduitAPI_paste_Method',
|
||||
'ConduitAPI_paste_query_Method' => 'ConduitAPI_paste_Method',
|
||||
'ConduitAPI_phame_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_phame_query_Method' => 'ConduitAPI_phame_Method',
|
||||
'ConduitAPI_phame_queryposts_Method' => 'ConduitAPI_phame_Method',
|
||||
'ConduitAPI_phid_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_phid_info_Method' => 'ConduitAPI_phid_Method',
|
||||
'ConduitAPI_phid_lookup_Method' => 'ConduitAPI_phid_Method',
|
||||
|
|
12
src/applications/phame/conduit/ConduitAPI_phame_Method.php
Normal file
12
src/applications/phame/conduit/ConduitAPI_phame_Method.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
abstract class ConduitAPI_phame_Method extends ConduitAPIMethod {
|
||||
|
||||
public function getApplication() {
|
||||
return PhabricatorApplication::getByClass('PhabricatorApplicationPhame');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_phame_query_Method extends ConduitAPI_phame_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Query phame blogs.";
|
||||
}
|
||||
|
||||
public function getMethodStatus() {
|
||||
return self::METHOD_STATUS_UNSTABLE;
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'ids' => 'optional list<int>',
|
||||
'phids' => 'optional list<phid>',
|
||||
'after' => 'optional int',
|
||||
'before' => 'optional int',
|
||||
'limit' => 'optional int',
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'list<dict>';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
|
||||
$query = new PhameBlogQuery();
|
||||
|
||||
$query->setViewer($request->getUser());
|
||||
|
||||
$ids = $request->getValue('ids', array());
|
||||
if ($ids) {
|
||||
$query->withIDs($ids);
|
||||
}
|
||||
|
||||
$phids = $request->getValue('phids', array());
|
||||
if ($phids) {
|
||||
$query->withPHIDs($phids);
|
||||
}
|
||||
|
||||
$after = $request->getValue('after', null);
|
||||
if ($after !== null) {
|
||||
$query->setAfterID($after);
|
||||
}
|
||||
|
||||
$before = $request->getValue('before', null);
|
||||
if ($before !== null) {
|
||||
$query->setBeforeID($before);
|
||||
}
|
||||
|
||||
$limit = $request->getValue('limit', null);
|
||||
if ($limit !== null) {
|
||||
$query->setLimit($limit);
|
||||
}
|
||||
|
||||
$blogs = $query->execute();
|
||||
|
||||
$results = array();
|
||||
foreach ($blogs as $blog) {
|
||||
$results[] = array(
|
||||
'id' => $blog->getID(),
|
||||
'phid' => $blog->getPHID(),
|
||||
'name' => $blog->getName(),
|
||||
'description' => $blog->getDescription(),
|
||||
'domain' => $blog->getDomain(),
|
||||
'creatorPHID' => $blog->getCreatorPHID(),
|
||||
);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_phame_queryposts_Method extends ConduitAPI_phame_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Query phame posts.";
|
||||
}
|
||||
|
||||
public function getMethodStatus() {
|
||||
return self::METHOD_STATUS_UNSTABLE;
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'ids' => 'optional list<int>',
|
||||
'phids' => 'optional list<phid>',
|
||||
'blogPHIDs' => 'optional list<phid>',
|
||||
'bloggerPHIDs' => 'optional list<phid>',
|
||||
'phameTitles' => 'optional list<string>',
|
||||
'published' => 'optional bool',
|
||||
'publishedAfter' => 'optional date',
|
||||
'before' => 'optional int',
|
||||
'after' => 'optional int',
|
||||
'limit' => 'optional int',
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'list<dict>';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
|
||||
$query = new PhamePostQuery();
|
||||
|
||||
$query->setViewer($request->getUser());
|
||||
|
||||
$ids = $request->getValue('ids', array());
|
||||
if ($ids) {
|
||||
$query->withIDs($ids);
|
||||
}
|
||||
|
||||
$phids = $request->getValue('phids', array());
|
||||
if ($phids) {
|
||||
$query->withPHIDs($phids);
|
||||
}
|
||||
|
||||
$blog_phids = $request->getValue('blogPHIDs', array());
|
||||
if ($blog_phids) {
|
||||
$query->withBlogPHIDs($blog_phids);
|
||||
}
|
||||
|
||||
$blogger_phids = $request->getValue('bloggerPHIDs', array());
|
||||
if ($blogger_phids) {
|
||||
$query->withBloggerPHIDs($blogger_phids);
|
||||
}
|
||||
|
||||
$phame_titles = $request->getValue('phameTitles', array());
|
||||
if ($phame_titles) {
|
||||
$query->withPhameTitles($phame_titles);
|
||||
}
|
||||
|
||||
$published = $request->getValue('published', null);
|
||||
if ($published === true) {
|
||||
$query->withVisibility(PhamePost::VISIBILITY_PUBLISHED);
|
||||
} else if ($published === false) {
|
||||
$query->withVisibility(PhamePost::VISIBILITY_DRAFT);
|
||||
}
|
||||
|
||||
$published_after = $request->getValue('publishedAfter', null);
|
||||
if ($published_after !== null) {
|
||||
$query->withPublishedAfter($published_after);
|
||||
}
|
||||
|
||||
$after = $request->getValue('after', null);
|
||||
if ($after !== null) {
|
||||
$query->setAfterID($after);
|
||||
}
|
||||
|
||||
$before = $request->getValue('before', null);
|
||||
if ($before !== null) {
|
||||
$query->setBeforeID($before);
|
||||
}
|
||||
|
||||
$limit = $request->getValue('limit', null);
|
||||
if ($limit !== null) {
|
||||
$query->setLimit($limit);
|
||||
}
|
||||
|
||||
$blogs = $query->execute();
|
||||
|
||||
$results = array();
|
||||
foreach ($blogs as $blog) {
|
||||
$results[] = array(
|
||||
'id' => $blog->getID(),
|
||||
'phid' => $blog->getPHID(),
|
||||
'blogPHID' => $blog->getBlogPHID(),
|
||||
'bloggerPHID' => $blog->getBloggerPHID(),
|
||||
'viewURI' => $blog->getViewURI(),
|
||||
'title' => $blog->getTitle(),
|
||||
'phameTitle' => $blog->getPhameTitle(),
|
||||
'body' => $blog->getBody(),
|
||||
'summary' => PhabricatorMarkupEngine::summarize($blog->getBody()),
|
||||
'datePublished' => $blog->getDatePublished(),
|
||||
'published' => !$blog->isDraft(),
|
||||
);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue