summaryrefslogtreecommitdiff
path: root/bin/wiki/vendor/addwiki/mediawiki-api-base/docs/quickstart.rst
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/vendor/addwiki/mediawiki-api-base/docs/quickstart.rst')
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api-base/docs/quickstart.rst87
1 files changed, 87 insertions, 0 deletions
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api-base/docs/quickstart.rst b/bin/wiki/vendor/addwiki/mediawiki-api-base/docs/quickstart.rst
new file mode 100644
index 00000000..5db0601f
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api-base/docs/quickstart.rst
@@ -0,0 +1,87 @@
+.. _quickstart:
+
+==========
+Quickstart
+==========
+
+This page provides a quick introduction to this library and introductory examples.
+If you have not already installed the library head over to the :ref:`installation`
+page.
+
+Getting an API object
+----------------------------------
+
+You can get an api object by simply passing the api endpoint:
+
+.. code-block:: php
+
+ use \Mediawiki\Api\MediawikiApi;
+
+ $api = MediawikiApi::newFromApiEndpoint( 'https://en.wikipedia.org/w/api.php' );
+
+You can even just pass a page:
+
+.. code-block:: php
+
+ use \Mediawiki\Api\MediawikiApi;
+
+ $api = MediawikiApi::newFromPage( 'https://en.wikipedia.org/wiki/Berlin' );
+
+Logging in and out
+----------------------------------
+
+.. code-block:: php
+
+ use \MediawikiApi\Api\ApiUser;
+
+ $api->login( new ApiUser( 'username', 'password' ) );
+ $api->logout();
+
+Making request objects
+----------------------------------
+
+The library provides two different way of constructing requests.
+
+.. code-block:: php
+
+ use Mediawiki\Api\SimpleRequest;
+ use Mediawiki\Api\FluentRequest;
+
+ $purgeRequest = new SimpleRequest( 'purge', array( 'titles' => 'Berlin' ) );
+ // or
+ $purgeRequest = FluentRequest::factory()->setAction( 'purge' )->setParam( 'titles', 'Berlin' ) );
+
+Sending requests
+----------------------------------
+
+.. code-block:: php
+
+ $api->postRequest( $purgeRequest );
+
+ $queryResponse = $api->getRequest( FluentRequest::factory()->setAction( 'query' )->setParam( 'meta', 'siteinfo' ) );
+
+ try{
+ $api->postRequest( new SimpleRequest( 'FooBarBaz' ) );
+ }
+ catch ( UsageException $e ) {
+ echo "The api returned an error!";
+ }
+
+
+Making async requests
+----------------------------------
+
+.. code-block:: php
+
+ // Initiate each request but do not block
+ $requestPromises = array(
+ 'Page1' => $api->postRequestAsync( FluentRequest::factory()->setAction( 'purge' )->setParam( 'titles', 'Page1' ) ),
+ 'Page2' => $api->postRequestAsync( FluentRequest::factory()->setAction( 'purge' )->setParam( 'titles', 'Page2' ) ),
+ 'Page3' => $api->postRequestAsync( FluentRequest::factory()->setAction( 'purge' )->setParam( 'titles', 'Page3' ) ),
+ );
+
+ // Wait on all of the requests to complete.
+ $results = GuzzleHttp\Promise\unwrap( $requestPromises );
+
+ // You can access each result using the key provided to the unwrap function.
+ print_r( $results['Page1'], $results['Page2'], $results['Page3'] )