r94524 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94523‎ | r94524 | r94525 >
Date:15:53, 15 August 2011
Author:reedy
Status:deferred
Tags:
Comment:
Little bit of refactoring

Remove debugging comments not currently needed

Iteratively get worksheets, dump to console
Modified paths:
  • /trunk/extensions/MetricsReporting/fetchGoogleSpreadsheet.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetricsReporting/fetchGoogleSpreadsheet.php
@@ -21,7 +21,7 @@
2222 'service' => 'wise', // Spreadsheet service is "wise"
2323 'Email' => '',
2424 'Passwd' => '',
25 - 'source' => Http::userAgent() . ' MetricsReporting/' . METRICS_REPORTING_VERSION,
 25+ 'source' => self::getUserAgent(),
2626 )
2727 )
2828 );
@@ -47,22 +47,10 @@
4848 $this->output( "Authorised. Got an authorisation token from Google\n" );
4949
5050 $cookies = $http->getCookieJar();
51 - //var_dump( $cookies );
52 - //var_dump( $authToken );
 51+ $http = $this->buildAuthedRequest( $url, $authToken, $cookies );
5352
54 - $http = MWHttpRequest::factory( $url, array(
55 - 'method' => 'GET',
56 - )
57 - );
58 - $http->setCookieJar( $cookies );
59 - $http->setHeader( 'GData-Version', '3.0' );
60 - $http->setHeader( 'Authorization', "GoogleLogin auth=\"{$authToken}\"" );
61 -
62 - $res = $http->execute();
63 - //var_dump( $res );
64 - //var_dump( $http->getResponseHeaders() );
 53+ $http->execute();
6554 $content = $http->getContent();
66 - //var_dump( $this->formatXmlString( $content ) );
6755
6856 $reader = new XMLReader();
6957 $reader->XML( $content );
@@ -82,6 +70,13 @@
8371 $reader->next( 'entry' );
8472 }
8573
 74+ foreach( $worksheets as $sheet ) {
 75+ $http = $this->buildAuthedRequest( $sheet, $authToken, $cookies );
 76+ $http->execute();
 77+ $content = $http->getContent();
 78+ var_dump( $this->formatXmlString( $content ) );
 79+ }
 80+
8681 $this->output( "Finished!\n" );
8782 }
8883
@@ -98,6 +93,33 @@
9994 $dom->formatOutput = true;
10095 return $dom->saveXml();
10196 }
 97+
 98+ /**
 99+ * @param $url string
 100+ * @param $token string
 101+ * @param $cookies CookieJar
 102+ * @return MWHttpRequest
 103+ */
 104+ function buildAuthedRequest( $url, $token, $cookies = null ) {
 105+ $http = MWHttpRequest::factory( $url, array(
 106+ 'method' => 'GET',
 107+ 'source' => self::getUserAgent(),
 108+ )
 109+ );
 110+ if ( $cookies !== null ) {
 111+ $http->setCookieJar( $cookies );
 112+ }
 113+ $http->setHeader( 'GData-Version', '3.0' );
 114+ $http->setHeader( 'Authorization', "GoogleLogin auth=\"{$token}\"" );
 115+ return $http;
 116+ }
 117+
 118+ /**
 119+ * @return string
 120+ */
 121+ private static function getUserAgent() {
 122+ return Http::userAgent() . ' MetricsReporting/' . METRICS_REPORTING_VERSION;
 123+ }
102124 }
103125
104126 $maintClass = "FetchGoogleSpreadsheet";

Status & tagging log