Skip to content

Commit

Permalink
Merge pull request #20 from JeroenDeDauw/seggregate
Browse files Browse the repository at this point in the history
Add interfaces
  • Loading branch information
addshore committed Jan 15, 2016
2 parents 15d062f + 906c707 commit 75ba537
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 1 deletion.
9 changes: 9 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
These are the release notes for the [mediawiki-api-base](README.md).

## Version 2.2.0 (dev)

* Added `MediawikiApiInterface`, now implemented by `MediawikiApi`
* Added `ApiRequester`, now implemented by `MediawikiApi`
* Added `AsyncApiRequester`, now implemented by `MediawikiApi`

## Version 2.1.0 (29 December 2015)

* Retry throttled actions that return a failed-save code and anti-abuse message
* Added delay between retried requests
* Added and used `Guzzle/ClientFactory`

## Version 2.0.0 (18 December 2015)

* Added `MediawikiApi::newFromApiEndpoint` and `MediawikiApi::newFromPage`
* MediawikiApi constructor access marked as private (please use static factory methods)
* Added async methods to MediawikiApi `getRequestAsync` & `postRequestAsync`
* Requires "guzzlehttp/guzzle": "~6.0" ( From "guzzle/guzzle": "~5.2" )
* Requires "guzzlehttp/promises": "~1.0"

## Version 1.1.0 (5 September 2015)

* Requests that encounter a connection exception are now retried
* Requests that result in non blocking mediawiki api error codes are now retried (ratelimited, readonly, internal_api_error_DBQueryError)
* MediawikiApi now implements PSR-3 LoggerAwareInterface
Expand Down
31 changes: 31 additions & 0 deletions src/ApiRequester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Mediawiki\Api;

/**
* @since 2.2
* @licence GNU GPL v2+
* @author Addshore
* @author Jeroen De Dauw < [email protected] >
*/
interface ApiRequester {

/**
* @since 2.2
*
* @param Request $request
*
* @return mixed Normally an array
*/
public function getRequest( Request $request );

/**
* @since 2.2
*
* @param Request $request
*
* @return mixed Normally an array
*/
public function postRequest( Request $request );

}
37 changes: 37 additions & 0 deletions src/AsyncApiRequester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Mediawiki\Api;

use GuzzleHttp\Promise\PromiseInterface;

/**
* @since 2.2
* @licence GNU GPL v2+
* @author Addshore
* @author Jeroen De Dauw < [email protected] >
*/
interface AsyncApiRequester {

/**
* @since 2.2
*
* @param Request $request
*
* @return PromiseInterface
* Normally promising an array, though can be mixed (json_decode result)
* Can throw UsageExceptions or RejectionExceptions
*/
public function getRequestAsync( Request $request );

/**
* @since 2.2
*
* @param Request $request
*
* @return PromiseInterface
* Normally promising an array, though can be mixed (json_decode result)
* Can throw UsageExceptions or RejectionExceptions
*/
public function postRequestAsync( Request $request );

}
2 changes: 1 addition & 1 deletion src/MediawikiApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author Addshore
*/
class MediawikiApi implements LoggerAwareInterface {
class MediawikiApi implements MediawikiApiInterface, LoggerAwareInterface {

/**
* @var Client|null Should be accessed through getClient
Expand Down
60 changes: 60 additions & 0 deletions src/MediawikiApiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Mediawiki\Api;

/**
* @since 2.2
* @licence GNU GPL v2+
* @author Addshore
* @author Jeroen De Dauw < [email protected] >
*/
interface MediawikiApiInterface extends ApiRequester, AsyncApiRequester {

/**
* @since 2.2
*
* @return bool|string false or the name of the current user
*/
public function isLoggedin();

/**
* @since 2.2
*
* @param ApiUser $apiUser
*
* @throws UsageException
* @return bool success
*/
public function login( ApiUser $apiUser );

/**
* @since 2.2
*
* @return bool success
*/
public function logout();

/**
* @since 2.2
*
* @param string $type
*
* @return string
*/
public function getToken( $type = 'csrf' );

/**
* @since 2.2
*
* Clears all tokens stored by the api
*/
public function clearTokens();

/**
* @since 2.2
*
* @return string
*/
public function getVersion();

}

0 comments on commit 75ba537

Please sign in to comment.