1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-11 17:32:41 +01:00
phorge-phorge/src/applications/phame/conduit/PhameQueryConduitAPIMethod.php
Joshua Spence 023dee0d3b Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.

Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin, hach-que

Maniphest Tasks: T5655

Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 10:54:15 +10:00

82 lines
1.8 KiB
PHP

<?php
final class PhameQueryConduitAPIMethod extends PhameConduitAPIMethod {
public function getAPIMethodName() {
return 'phame.query';
}
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;
}
}