jenkins-bot has submitted this change and it was merged.

Change subject: Add API parameter handling details for the bounehandler API
......................................................................


Add API parameter handling details for the bounehandler API

* Updated tests too to work with with the change
* The API now receive parameters from $this->extractRequestParams();
* Updated API to use i18n messages

Bug: 72685
Change-Id: I83f6854a8ee007e1944d2501d11b244e0254fd91
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiBounceHandler.php
M tests/ApiBounceHandlerTest.php
4 files changed, 57 insertions(+), 28 deletions(-)

Approvals:
  Anomie: Looks good to me, but someone else must approve
  Reedy: Looks good to me, approved
  01tonythomas: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index ad7c7cd..2c3c0d2 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -5,5 +5,8 @@
                ]
        },
        "bouncehandler-desc": "Helps in handling email bounces for MediaWiki",
-       "bouncehandler-notify_subject": "Returning temporary bounce"
+       "bouncehandler-notify_subject": "Returning temporary bounce",
+       "apihelp-bouncehandler-example-1": "Receive a bounce email for 
processing with the content \"This is a test email\".",
+       "apihelp-bouncehandler-description": "Receive a bounce email and 
process it to handle the failing recipient.",
+       "apihelp-bouncehandler-param-email": "The bounced email."
 }
\ No newline at end of file
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 8f3aafe..3e79b9e 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -5,5 +5,8 @@
                ]
        },
        "bouncehandler-desc": "{{desc|name=Bounce 
Handler|url=https://www.mediawiki.org/wiki/Extension:BounceHandler}}";,
-       "bouncehandler-notify_subject": "Subject of notification email sent to 
wiki administrators on a failed to parse bounce"
+       "bouncehandler-notify_subject": "Subject of notification email sent to 
wiki administrators on a failed to parse bounce",
+       "apihelp-bouncehandler-example-1": 
"{{doc-apihelp-example|bouncehandler}}",
+       "apihelp-bouncehandler-description": 
"{{doc-apihelp-description|bouncehandler}}",
+       "apihelp-bouncehandler-param-email": 
"{{doc-apihelp-param|bouncehandler|email}}"
 }
diff --git a/includes/ApiBounceHandler.php b/includes/ApiBounceHandler.php
index f6c78ca..403058e 100644
--- a/includes/ApiBounceHandler.php
+++ b/includes/ApiBounceHandler.php
@@ -19,26 +19,17 @@
                        $this->dieUsage( 'This API module is for internal use 
only.', 'invalid-ip' );
                }
 
-               $email = $this->getMain()->getVal( 'email' );
+               $params = $this->extractRequestParams();
 
-               if ( $email ) {
-                       $params = array ( 'email' => $email );
-                       $title = Title::newFromText( 'BounceHandler Job' );
-                       $job = new BounceHandlerJob( $title, $params );
-                       JobQueueGroup::singleton()->push( $job );
+               $title = Title::newFromText( 'BounceHandler Job' );
+               $job = new BounceHandlerJob( $title, $params );
+               JobQueueGroup::singleton()->push( $job );
 
-                       $this->getResult()->addValue(
-                               null,
-                               $this->getModuleName(),
-                               array ( 'submitted' => 'job' )
-                       );
-               } else {
-                       $this->getResult()->addValue(
-                               null,
-                               $this->getModuleName(),
-                               array ( 'submitted' => 'failure' )
-                       );
-               }
+               $this->getResult()->addValue(
+                       null,
+                       $this->getModuleName(),
+                       array ( 'submitted' => 'job' )
+               );
 
                return true;
        }
@@ -52,4 +43,35 @@
                return true;
        }
 
+       public function mustBePosted() {
+               return true;
+       }
+
+       public function isWriteMode() {
+               return true;
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'email' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true
+                       )
+               );
+       }
+
+       /**
+        * @see ApiBase::getExamplesMessages()
+        */
+       public function getExamplesMessages() {
+               return array(
+                       
'action=bouncehandler&email=This%20is%20a%20test%20email'
+                               => 'apihelp-bouncehandler-example-1'
+               );
+       }
+
+       public function getHelpUrls() {
+               return 
"https://www.mediawiki.org/wiki/Extension:BounceHandler#API";;
+       }
+
 }
\ No newline at end of file
diff --git a/tests/ApiBounceHandlerTest.php b/tests/ApiBounceHandlerTest.php
index b02322c..5a96345 100644
--- a/tests/ApiBounceHandlerTest.php
+++ b/tests/ApiBounceHandlerTest.php
@@ -39,7 +39,7 @@
         */
        function testBounceHandlerWithBadIPPasses() {
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'111.111.111.111' ) );
-               list( $apiResult ) = $this->doApiRequest( array(
+               $this->doApiRequest( array(
                        'action' => 'bouncehandler',
                        'email' => self::$bounceEmail
                ) );
@@ -48,29 +48,30 @@
        /**
         * Tests API request with null 'email' param
         *
+        * @expectedException UsageException
+        * @expectedException The email parameter must be set
         */
        function testBounceHandlerWithNullParams() {
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
-                       list( $apiResult ) = $this->doApiRequest( array(
+               $this->doApiRequest( array(
                        'action' => 'bouncehandler',
                        'email' => ''
-                       ) );
+               ) );
 
-               $this->assertEquals( 'failure', 
$apiResult['bouncehandler']['submitted'] );
        }
 
        /**
         * Tests API with Wrong params
         *
+        * @expectedException UsageException
+        * @expectedException The email parameter must be set
         */
        function testBounceHandlerWithWrongParams() {
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
-               list( $apiResult ) = $this->doApiRequest( array(
+               $this->doApiRequest( array(
                        'action' => 'bouncehandler',
-                       'emails' => self::$bounceEmail
+                       'foo' => self::$bounceEmail
                ) );
-
-               $this->assertEquals( 'failure', 
$apiResult['bouncehandler']['submitted'] );
        }
 
 }
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/170889
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I83f6854a8ee007e1944d2501d11b244e0254fd91
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: 01tonythomas <01tonytho...@gmail.com>
Gerrit-Reviewer: 01tonythomas <01tonytho...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jgreen <jgr...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to