Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break out Http request code + fixup phpunit + composer autload
- Loading branch information
Marc Littlemore
committed
Jul 13, 2017
1 parent
969a091
commit f4f4e3b
Showing
5 changed files
with
54 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,10 @@ | |
"psr-4": { | ||
"MarcL\\": "src/" | ||
} | ||
} | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"MarcL\\": "src/", | ||
"tests\\": "tests/" | ||
} | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit colors="true"> | ||
<phpunit colors="true" bootstrap="vendor/autoload.php"> | ||
<testsuites> | ||
<testsuite name="Application Test Suite"> | ||
<directory>./tests/</directory> | ||
<testsuite name="AmazonAPI Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace MarcL; | ||
|
||
interface IHttpRequest { | ||
public function execute($url); | ||
} | ||
|
||
class CurlHttpRequest implements IHttpRequest { | ||
private $url = NULL; | ||
private $error = NULL; | ||
|
||
public function __construct() { | ||
if (!function_exists('curl_init')) | ||
{ | ||
throw new \Exception('Curl not found'); | ||
} | ||
} | ||
|
||
public function execute($url) { | ||
// Use curl to retrieve data from Amazon | ||
$session = curl_init($url); | ||
curl_setopt($session, CURLOPT_HEADER, false); | ||
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); | ||
$response = curl_exec($session); | ||
|
||
if ($response === false) { | ||
$this->error = curl_error($session); | ||
} | ||
|
||
curl_close($session); | ||
|
||
if (!empty($error)) { | ||
throw new \Exception($error); | ||
} | ||
|
||
return($response); | ||
} | ||
} | ||
|
||
?> |