Skip to content

Commit

Permalink
Merge pull request #4 from eventum/methods-doc
Browse files Browse the repository at this point in the history
Use PHP Namespaces, add methods doc annotations
  • Loading branch information
glensc authored May 1, 2018
2 parents 1d7b2da + fedfb2d commit cef08fb
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ return Symfony\CS\Config\Config::create()
))
->finder($finder)
;

// vim:ft=php
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Eventum RPC Client Library

## [4.2.0] - 2018-05-01

- Move classes to `Eventum\RPC` namespace, deprecate root namespace [#4]
- Update xmlrpc methods doc, include `@method` annotation, [#4]

[4.2.0]: https://github.com/eventum/rpc/compare/v4.1.1...v4.2.0
[#4]: https://github.com/eventum/rpc/pull/4

## [4.1.1] - 2017-10-15

- add `addUserAgent` method for public access
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
eventum-rpc
===========
# Eventum RPC

Eventum RPC Client Library.

Expand Down Expand Up @@ -46,18 +45,18 @@ require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';

$rpc_url = "http://example.org/rpc/xmlrpc.php";
$client = new Eventum_RPC($rpc_url);
$client = new \Eventum\RPC\EventumXmlRpcClient($rpc_url);
$client->setCredentials("user@example.org", "password");

// add user@example.org as authorized replier in issue $issue_id belonging to project $project_id
$client->addAuthorizedReplier($issue_id, $project_id, "user@example.org");
```

The available XMLRPC Methods can be seen from [here](XMLRPC.md).
The available XMLRPC Methods can also be seen from [XMLRPC.md](XMLRPC.md).

## Copyright and License ##

This software is Copyright (c) 2008 - 2017 Eventum Team.
This software is Copyright (c) 2008 - 2018 Eventum Team.

This is free software, licensed under the GNU General Public License
version 2.
11 changes: 7 additions & 4 deletions XMLRPC.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Available XMLRPC methods ##

Here are available XMLRPC methods in [Eventum](https://github.com/eventum/eventum) as of version 3.0.2.
Here are available XMLRPC methods in [Eventum](https://github.com/eventum/eventum) as of version 3.4.0.
The methods themselves are defined in [RemoteApi](https://github.com/eventum/eventum/blob/master/lib/eventum/rpc/RemoteApi.php) class in Eventum codebase.
This output is created with Eventum [CLI](https://github.com/eventum/cli) application [DumpMethods](https://github.com/eventum/cli/blob/master/src/Command/DumpMethodsCommand.php) command.

Methods marked `@access public` do not require authentication, while `@access restricted` (default) require that you either use `setCredentials` to pass authentication credentials, or put `login` and `password` as first two parameters for the call.
Methods marked `@access public` do not require authentication, while `@access protected` (default) require that you either use `setCredentials` to pass authentication credentials, or put `login` and `password` as first two parameters for the call.

```php
/**
Expand Down Expand Up @@ -57,6 +57,7 @@ Methods marked `@access public` do not require authentication, while `@access re
* @param string $note
* @return string
* @access protected
* @since 3.3.0 checks user access and issue close state
*/
function closeIssue(int, string, int, boolean, string): string

Expand Down Expand Up @@ -231,11 +232,11 @@ Methods marked `@access public` do not require authentication, while `@access re
* @param DateTime $start
* @param DateTime $end
* @param struct $options
* @return string
* @return struct
* @access protected
* @since 3.0.2
*/
function getWeeklyReportData(int, string, string, struct): string
function getWeeklyReportData(int, string, string, struct): struct

/**
* @param string $email
Expand All @@ -249,6 +250,7 @@ Methods marked `@access public` do not require authentication, while `@access re
* @param string $command
* @return string
* @access protected
* @deprecated since 3.3.0 this method does nothing
*/
function logCommand(string): string

Expand Down Expand Up @@ -328,3 +330,4 @@ Methods marked `@access public` do not require authentication, while `@access re
* @access protected
*/
function unredeemIssue(int, array): string
```
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"phpxmlrpc/phpxmlrpc": "^4.2.2"
},
"autoload": {
"classmap": [ "src" ]
"psr-4": {
"Eventum\\RPC\\": "src/"
},
"classmap": [ "lib" ]
},
"autoload-dev": {
"psr-4": {
Expand Down
21 changes: 21 additions & 0 deletions lib/Eventum_RPC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Eventum (Issue Tracking System) package.
*
* @copyright (c) Eventum Team
* @license GNU General Public License, version 2 or later (GPL-2+)
*
* For the full copyright and license information,
* please see the COPYING and AUTHORS files
* that were distributed with this source code.
*/

use Eventum\RPC\EventumXmlRpcClient;

/**
* @deprecated since 4.2.0, use \Eventum\RPC\EventumXmlRpcClient
*/
class Eventum_RPC extends EventumXmlRpcClient
{
}
19 changes: 19 additions & 0 deletions lib/Eventum_RPC_Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Eventum (Issue Tracking System) package.
*
* @copyright (c) Eventum Team
* @license GNU General Public License, version 2 or later (GPL-2+)
*
* For the full copyright and license information,
* please see the COPYING and AUTHORS files
* that were distributed with this source code.
*/

/**
* @deprecated since 4.2.0, use \Eventum\RPC\XmlRpcException instead
*/
class Eventum_RPC_Exception extends RuntimeException
{
}
60 changes: 60 additions & 0 deletions src/EventumXmlRpcClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of the Eventum (Issue Tracking System) package.
*
* @copyright (c) Eventum Team
* @license GNU General Public License, version 2 or later (GPL-2+)
*
* For the full copyright and license information,
* please see the COPYING and AUTHORS files
* that were distributed with this source code.
*/

namespace Eventum\RPC;

use DateTime;

/**
* @method string addAuthorizedReplier(int $issue_id, int $project_id, string $new_replier)
* @method struct addFile(int $issue_id, string $filename, string $mimetype, base64 $contents, string $file_description, bool $internal_only)
* @method string assignIssue(int $issue_id, int $project_id, string $developer)
* @method boolean checkAuthentication()
* @method string closeIssue(int $issue_id, string $new_status, int $resolution_id, bool $send_notification, string $note)
* @method string convertNote(int $issue_id, int $note_id, string $target, bool $authorize_sender)
* @method struct getAbbreviationAssocList(int $prj_id, bool $show_closed)
* @method struct getClosedAbbreviationAssocList(int $prj_id)
* @method struct getDeveloperList(int $prj_id)
* @method struct getDraft(int $issue_id, int $draft_id)
* @method array getDraftListing(int $issue_id)
* @method array getEmail(int $issue_id, int $email_id)
* @method array getEmailListing(int $issue_id)
* @method struct getFile(int $file_id)
* @method array getFileList(int $issue_id)
* @method array getIncidentTypes(int $issue_id, bool $redeemed_only)
* @method struct getIssueDetails(int $issue_id)
* @method array getNote(int $issue_id, int $note_id)
* @method array getNoteListing(int $issue_id)
* @method array getOpenIssues(int $prj_id, bool $show_all_issues, string $status)
* @method array getResolutionAssocList()
* @method string getServerParameter(string $parameter)
* @method struct getSimpleIssueDetails(int $issue_id)
* @method struct getTimeTrackingCategories(int $issue_id)
* @method array getUserAssignedProjects(bool $only_customer_projects)
* @method string getWeeklyReport(int $week, string $start, string $end, bool $separate_closed, int $prj_id)
* @method struct getWeeklyReportData(int $prj_id, DateTime $start, DateTime $end, struct $options)
* @method boolean isValidLogin(string $email, string $password)
* @method string logCommand(string $command)
* @method string lookupCustomer(int $prj_id, string $field, string $value)
* @method string mayChangeIssue(int $issue_id)
* @method string recordTimeWorked(int $issue_id, int $cat_id, string $summary, int $time_spent)
* @method string redeemIssue(int $issue_id, array $types)
* @method string sendDraft(int $issue_id, int $draft_id)
* @method string setIssueStatus(int $issue_id, string $new_status)
* @method string takeIssue(int $issue_id, int $project_id)
* @method string timeClock(string $action)
* @method string unredeemIssue(int $issue_id, array $types)
*/
class EventumXmlRpcClient extends XmlRpcClient
{
}
16 changes: 8 additions & 8 deletions src/Eventum_RPC.php → src/XmlRpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* that were distributed with this source code.
*/

class Eventum_RPC_Exception extends Exception
{
}
namespace Eventum\RPC;

use PhpXmlRpc;

class Eventum_RPC
class XmlRpcClient
{
const VERSION = '4.1.1';
const VERSION = '4.2.0';

/** @var PhpXmlRpc\Client */
private $client;
Expand Down Expand Up @@ -70,7 +70,7 @@ public function encodeBinary($value)
* @param string $method
* @param array $args
* @return mixed
* @throws Eventum_RPC_Exception
* @throws XmlRpcException
*/
public function __call($method, $args = array())
{
Expand All @@ -94,10 +94,10 @@ public function __call($method, $args = array())
$result = $this->client->send($req);

if ($result === 0) {
throw new Eventum_RPC_Exception($this->client->errstr);
throw new XmlRpcException($this->client->errstr);
}
if (is_object($result) && $result->faultCode()) {
throw new Eventum_RPC_Exception($result->faultString());
throw new XmlRpcException($result->faultString(), $result->faultCode());
}

return $this->encoder->decode($result->value());
Expand Down
20 changes: 20 additions & 0 deletions src/XmlRpcException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the Eventum (Issue Tracking System) package.
*
* @copyright (c) Eventum Team
* @license GNU General Public License, version 2 or later (GPL-2+)
*
* For the full copyright and license information,
* please see the COPYING and AUTHORS files
* that were distributed with this source code.
*/

namespace Eventum\RPC;

use Eventum_RPC_Exception;

class XmlRpcException extends Eventum_RPC_Exception
{
}
20 changes: 20 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

namespace Eventum\RPC\Test;

use Eventum\RPC\XmlRpcException;
use Eventum_RPC;
use Eventum_RPC_Exception;

class ClientTest extends TestCase
{
Expand All @@ -40,5 +42,23 @@ public function testRequest()
$client = new Eventum_RPC($url);
$methods = $client->__call($method);
$this->assertContains($method, $methods);

// test that legacy exception class is catchable
try {
$client->unknownMethod($method);
$this->fail('Exception not thrown');
} catch (Eventum_RPC_Exception $e) {
$this->assertEquals('Unknown method', $e->getMessage());
$this->assertEquals(1, $e->getCode());
}

// test that new exception class is catchable
try {
$client->unknownMethod($method);
$this->fail('Exception not thrown');
} catch (XmlRpcException $e) {
$this->assertEquals('Unknown method', $e->getMessage());
$this->assertEquals(1, $e->getCode());
}
}
}

0 comments on commit cef08fb

Please sign in to comment.