Skip to content

Commit

Permalink
Merge branch 'release/0.2.0-beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
brolaugh committed Mar 20, 2017
2 parents 39273c0 + 4e2e609 commit 461b0e8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
],
"autoload": {
"psr-4": {
"IP1\\RESTClient\\": "src"
"IP1\\RESTClient\\": "src",
"IP1\\RESTClient\\Test\\": "tests"
}
},
"require" : {
"php" : "^7.1.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "2.*",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^6.0",
"phpdocumentor/phpdocumentor": "2.*"
"phpunit/phpunit": "^6.0"
}
}
13 changes: 13 additions & 0 deletions src/Core/Communicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace IP1\RESTClient\Core;

use IP1\RESTClient\Recipient\RecipientFactory;
use IP1\RESTClient\Recipient\ProcessedBlacklistEntry;
use IP1\RESTClient\Core\ProcessedComponentInterface;
use IP1\RESTClient\Core\UpdatableComponentInterface;
use IP1\RESTClient\Core\ProcessableComponentInterface;
Expand Down Expand Up @@ -63,6 +64,11 @@ public function add(ProcessableComponentInterface $component): ProcessedComponen
case "IP1\RESTClient\SMS\OutGoingSMS":
$response = $this->sendRequest("api/sms/send", "POST", json_encode($component));
return RecipientFactory::createProcessedOutGoingSMSFromJSONArray($response);
case "IP1\RESTClient\Recipient\BlacklistEntry":
$response = $this->sendRequest("api/blacklist", "POST", json_encode($component));
$stdResponse = json_decode($response);
$created = new \DateTime($stdResponse->Created);
return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created);
default:
throw new \InvalidArgumentException("Given JsonSerializable not supported.");
}
Expand All @@ -88,6 +94,13 @@ public function remove(ProcessedComponentInterface $component): ProcessedCompone
case "IP1\RESTClient\Recipient\ProcessedMembership":
$response = $this->sendRequest("api/memberships/".$component->getID(), "DELETE");
return RecipientFactory::createProcessedMembershipFromJSON($response);

case "IP1\RESTClient\Recipient\ProcessedBlacklistEntry":
$response = $this->sendRequest("api/blacklist/".$component->getID(), "DELETE");
$stdResponse = json_decode($response);
$created = new \DateTime($stdResponse->Created);
return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created);

default:
throw new \InvalidArgumentException("Given JsonSerializable not supported.");
}
Expand Down
36 changes: 22 additions & 14 deletions tests/General/ConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,35 @@
use IP1\RESTClient\Recipient\ProcessedGroup;
use IP1\RESTClient\SMS\ProcessedOutGoingSMS;
use PHPUnit\Framework\TestCase;
use \DateTime;

class ConstructorTest extends TestCase
{
/**
* @covers Contact::__construct
* @covers ProcessedContact::__construct
*/

public function testRecipientConstructors()
{
new Contact("Jack", "12025550161");
new ProcessedContact("Jack", "12025550161", 13, "Sparrow", "Captain", "Black Pearl Co.", "", "");
new Group("Crew men", "#ffffff");
new ProcessedGroup("Crew men", "#ffffff", 12, new DateTime(), new DateTime());
new Membership(12, 22);
new ProcessedMembership(12, 22, 43, new DateTime());
new ProcessedMembership(1, 2, 3, new DateTime());
$this->requireAll("src");
$this->addToAssertionCount(1);
}
public function testSMSConstructors()
/**
* Scan the api path, recursively including all PHP files
*
* @param string $dir
* @param int $depth (optional)
* @author mrashad10 at github.com
* @author pwenzel at github.com
* @link https://gist.github.com/mrashad10/807456e12a6811f644ca
*/
protected function requireAll($dir, $depth = 0)
{
new ProcessedOutGoingSMS("Jack", "Why is the rum gone?", "12025550109", 1, new DateTime(), new DateTime(), 22);
$this->addToAssertionCount(1);
// require all php files
$scan = glob("$dir" . DIRECTORY_SEPARATOR . "*");
foreach ($scan as $path) {
if (preg_match('/\.php$/', $path)) {
require_once $path;
} elseif (is_dir($path)) {
$this->requireAll($path, $depth+1);
}
}
}
}

0 comments on commit 461b0e8

Please sign in to comment.