Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2 from pear2/bugfix/articlesearch-no-result

Bugfix/articlesearch no result
  • Loading branch information...
commit aa3613c0acc000f9052d125416c4de3c72863b50 2 parents ba88d69 + ac3d0af
@till till authored
View
10 generate-package.php
@@ -8,11 +8,11 @@
$api_version = '0.2.0';
$api_state = 'alpha';
-$release_version = $api_version;
+$release_version = '0.2.3';
$release_state = 'alpha';
-$release_notes = "Making a pear compatible package.";
+$release_notes = "Bugfix (error handling)";
-$description = "An API wrapper to retrieve meta data of articles on huffingtonpost.com.";
+$description = "An API wrapper for the NYTimes APIs.";
$package = new PEAR_PackageFileManager2();
@@ -90,7 +90,7 @@ function readDirectory($path) {
}
$files = array();
-readDirectory(__DIR__ . '/library');
+readDirectory(__DIR__ . '/src');
/**
* @desc Strip this from the filename for 'addInstallAs'
@@ -108,7 +108,7 @@ function readDirectory($path) {
'version'
);
$file2 = str_replace($base, '', $file);
- $package->addInstallAs($file2, str_replace('library/', '', $file2));
+ $package->addInstallAs($file2, str_replace('src/', '', $file2));
}
$package->setPhpDep('5.3.0');
View
111 package.xml
@@ -5,8 +5,8 @@
http://pear.php.net/dtd/package-2.0.xsd">
<name>PEAR2_Services_NYTimes</name>
<channel>easybib.github.com/pear</channel>
- <summary>An API wrapper to retrieve meta data of articles on huffingtonpost.com.</summary>
- <description>An API wrapper to retrieve meta data of articles on huffingtonpost.com.</description>
+ <summary>An API wrapper for the NYTimes APIs.</summary>
+ <description>An API wrapper for the NYTimes APIs.</description>
<lead>
<name>Till Klampaeckel</name>
<user>till</user>
@@ -14,9 +14,9 @@
<active>yes</active>
</lead>
<date>2012-05-05</date>
- <time>19:22:33</time>
+ <time>20:14:45</time>
<version>
- <release>0.2.0</release>
+ <release>0.2.3</release>
<api>0.2.0</api>
</version>
<stability>
@@ -25,7 +25,7 @@
</stability>
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD</license>
<notes>
-Making a pear compatible package.
+Bugfix (error handling)
</notes>
<contents>
<dir baseinstalldir="/" name="/">
@@ -33,11 +33,21 @@ Making a pear compatible package.
<dir name="PEAR2">
<dir name="Services">
<dir name="NYTimes">
- <file name="Articlesearch.php" role="php" />
- <file name="Base.php" role="php" />
- <file name="Main.php" role="php" />
- <file name="Newswire.php" role="php" />
- <file name="NYTimesInterface.php" role="php" />
+ <file baseinstalldir="/" name="Articlesearch.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ <file baseinstalldir="/" name="Base.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ <file baseinstalldir="/" name="Main.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ <file baseinstalldir="/" name="Newswire.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ <file baseinstalldir="/" name="NYTimesInterface.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
</dir> <!-- /src/PEAR2/Services/NYTimes -->
</dir> <!-- /src/PEAR2/Services -->
</dir> <!-- /src/PEAR2 -->
@@ -46,16 +56,16 @@ Making a pear compatible package.
<dir name="fixtures">
<dir name="articlesearch">
<dir name="v1">
- <file name="by-url.php" role="test" />
+ <file baseinstalldir="/" name="by-url.php" role="test" />
</dir> <!-- /tests/fixtures/articlesearch/v1 -->
</dir> <!-- /tests/fixtures/articlesearch -->
<dir name="newswire">
<dir name="v3">
- <file name="get-items.php" role="test" />
- <file name="get-sections.php" role="test" />
- <file name="shuttle-article-sphp.php" role="test" />
- <file name="shuttle-article-xml.php" role="test" />
- <file name="shuttle-article.php" role="test" />
+ <file baseinstalldir="/" name="get-items.php" role="test" />
+ <file baseinstalldir="/" name="get-sections.php" role="test" />
+ <file baseinstalldir="/" name="shuttle-article-sphp.php" role="test" />
+ <file baseinstalldir="/" name="shuttle-article-xml.php" role="test" />
+ <file baseinstalldir="/" name="shuttle-article.php" role="test" />
</dir> <!-- /tests/fixtures/newswire/v3 -->
</dir> <!-- /tests/fixtures/newswire -->
</dir> <!-- /tests/fixtures -->
@@ -63,18 +73,18 @@ Making a pear compatible package.
<dir name="Services">
<dir name="NYTimes">
<dir name="Test">
- <file name="ArticlesearchTest.php" role="test" />
- <file name="BaseTest.php" role="test" />
- <file name="MainTest.php" role="test" />
- <file name="NewswireTest.php" role="test" />
- <file name="TestCase.php" role="test" />
+ <file baseinstalldir="/" name="ArticlesearchTest.php" role="test" />
+ <file baseinstalldir="/" name="BaseTest.php" role="test" />
+ <file baseinstalldir="/" name="MainTest.php" role="test" />
+ <file baseinstalldir="/" name="NewswireTest.php" role="test" />
+ <file baseinstalldir="/" name="TestCase.php" role="test" />
</dir> <!-- /tests/PEAR2/Services/NYTimes/Test -->
</dir> <!-- /tests/PEAR2/Services/NYTimes -->
</dir> <!-- /tests/PEAR2/Services -->
</dir> <!-- /tests/PEAR2 -->
- <file name="TestInit.php" role="test" />
+ <file baseinstalldir="/" name="TestInit.php" role="test" />
</dir> <!-- /tests -->
- <file name="README.md" role="doc" />
+ <file baseinstalldir="/" name="README.md" role="doc" />
</dir> <!-- / -->
</contents>
<dependencies>
@@ -94,7 +104,15 @@ Making a pear compatible package.
</extension>
</required>
</dependencies>
- <phprelease />
+ <phprelease>
+ <filelist>
+ <install as="PEAR2/Services/NYTimes/Articlesearch.php" name="src/PEAR2/Services/NYTimes/Articlesearch.php" />
+ <install as="PEAR2/Services/NYTimes/Base.php" name="src/PEAR2/Services/NYTimes/Base.php" />
+ <install as="PEAR2/Services/NYTimes/Main.php" name="src/PEAR2/Services/NYTimes/Main.php" />
+ <install as="PEAR2/Services/NYTimes/NYTimesInterface.php" name="src/PEAR2/Services/NYTimes/NYTimesInterface.php" />
+ <install as="PEAR2/Services/NYTimes/Newswire.php" name="src/PEAR2/Services/NYTimes/Newswire.php" />
+ </filelist>
+ </phprelease>
<changelog>
<release>
<version>
@@ -111,5 +129,50 @@ Making a pear compatible package.
Making a pear compatible package.
</notes>
</release>
+ <release>
+ <version>
+ <release>0.2.1</release>
+ <api>0.2.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2012-05-05</date>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD</license>
+ <notes>
+Bugfix (installation)
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>0.2.2</release>
+ <api>0.2.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2012-05-05</date>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD</license>
+ <notes>
+Bugfix (description :))
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>0.2.3</release>
+ <api>0.2.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2012-05-05</date>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD</license>
+ <notes>
+Bugfix (error handling)
+ </notes>
+ </release>
</changelog>
</package>
View
7 src/PEAR2/Services/NYTimes/Articlesearch.php
@@ -42,9 +42,11 @@ class Articlesearch extends Base implements NYTimesInterface
/**
* Search by URL.
*
+ * Returns a \stdClass if successful, or false when not (no result).
+ *
* @param string $url A URL to an article.
*
- * @return stdClass
+ * @return stdClass|false
*/
public function byUrl($url)
{
@@ -55,6 +57,9 @@ public function byUrl($url)
$response = $this->makeRequest($uri);
$data = $this->parseResponse($response);
+ if (empty($data->results)) {
+ return false;
+ }
return $data->results[0];
}
View
2  src/PEAR2/Services/NYTimes/Base.php
@@ -150,7 +150,7 @@ protected function isSuccessful(\HTTP_Request2_Response $response)
*/
protected function hazProblem(\HTTP_Request2_Response $response)
{
- switch ($response->getStatus) {
+ switch ($response->getStatus()) {
case 400:
throw new \RuntimeException("Bad request.");
case 403:
View
14 tests/PEAR2/Services/NYTimes/Test/ArticlesearchTest.php
@@ -43,4 +43,18 @@ public function testUrlSearch()
$this->assertInstanceOf('stdClass', $data);
}
+
+ public function testUrlSearchNoResult()
+ {
+ $responseObject = $this->setUpResponseObject(
+ 'articlesearch',
+ 'v1',
+ 'by-url-no-result.php'
+ );
+
+ $asMock = $this->getApiMocked('articlesearch', $responseObject);
+ $data = $asMock->byUrl('http://www.nytimes.com/2011/07/09/business/economy/job-growth-falters-badly-clouding-hope-for-recovery.html?hp');
+
+ $this->assertFalse($data);
+ }
}
View
6 tests/fixtures/articlesearch/v1/by-url-no-result.php
@@ -0,0 +1,6 @@
+<?php
+return array(
+ 'effectiveUrl' => 'http://api.nytimes.com/svc/search/v1/article?query=url%3Ahttp%3A%2F%2Fwww.nytimes.com%2F2011%2F07%2F09%2Fbusiness%2Feconomy%2Fjob-growth-falters-badly-clouding-hope-for-recovery.html&api-key=f8f203975851104767077c83bb51fd95%3A6%3A57657007',
+ 'body' => '{"offset" : "0" , "results" : [] , "tokens" : ["url:http" , "www" , "nytimes" , "com" , "2012" , "09" , "05" , "opinion" , "why" , "mali" , "matters" , "html"] , "total" : 0}',
+ 'statusLine' => 'HTTP/1.1 200 OK',
+);

0 comments on commit aa3613c

Please sign in to comment.
Something went wrong with that request. Please try again.