Index: trunk/extensions/MetricsReporting/fetchGoogleSpreadsheet.php |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | 'service' => 'wise', // Spreadsheet service is "wise" |
23 | 23 | 'Email' => '', |
24 | 24 | 'Passwd' => '', |
25 | | - 'source' => Http::userAgent() . ' MetricsReporting/' . METRICS_REPORTING_VERSION, |
| 25 | + 'source' => self::getUserAgent(), |
26 | 26 | ) |
27 | 27 | ) |
28 | 28 | ); |
— | — | @@ -47,22 +47,10 @@ |
48 | 48 | $this->output( "Authorised. Got an authorisation token from Google\n" ); |
49 | 49 | |
50 | 50 | $cookies = $http->getCookieJar(); |
51 | | - //var_dump( $cookies ); |
52 | | - //var_dump( $authToken ); |
| 51 | + $http = $this->buildAuthedRequest( $url, $authToken, $cookies ); |
53 | 52 | |
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(); |
65 | 54 | $content = $http->getContent(); |
66 | | - //var_dump( $this->formatXmlString( $content ) ); |
67 | 55 | |
68 | 56 | $reader = new XMLReader(); |
69 | 57 | $reader->XML( $content ); |
— | — | @@ -82,6 +70,13 @@ |
83 | 71 | $reader->next( 'entry' ); |
84 | 72 | } |
85 | 73 | |
| 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 | + |
86 | 81 | $this->output( "Finished!\n" ); |
87 | 82 | } |
88 | 83 | |
— | — | @@ -98,6 +93,33 @@ |
99 | 94 | $dom->formatOutput = true; |
100 | 95 | return $dom->saveXml(); |
101 | 96 | } |
| 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 | + } |
102 | 124 | } |
103 | 125 | |
104 | 126 | $maintClass = "FetchGoogleSpreadsheet"; |