Skip to content

Commit

Permalink
Merge branch 'release/0.3.0-beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
brolaugh committed Mar 21, 2017
2 parents 461b0e8 + eb70222 commit 6f6161f
Show file tree
Hide file tree
Showing 37 changed files with 355 additions and 105 deletions.
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
"description": "A PHP client library for the IP1SMS RESTful API",
"type": "library",
"license": "LGPL-3.0",
"authors": [
{
"name": "Hannes Kindströmmer",
"email": "[email protected]",
"homepage": "http://kindstrommer.se",
"role": "Developer"
}
],
"autoload": {
"authors": [
{
"name": "Hannes Kindströmmer",
"email": "[email protected]",
"homepage": "http://kindstrommer.se",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"IP1\\RESTClient\\": "src",
"IP1\\RESTClient\\Test\\": "tests"
}
},
"require" : {
"php" : "^7.1.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "2.*",
"phpunit/phpunit": "^6.0"
}
"require" : {
"php" : "^7.1.1",
"nategood/httpful": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "2.*",
"phpunit/phpunit": "^6.0"
}
}
55 changes: 53 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Core/ClassValidationArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.1.0-beta
* @since File available since Release 0.1.0-beta
Expand Down
57 changes: 34 additions & 23 deletions src/Core/Communicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.2.0-beta
* @version 0.3.0-beta
* @since File available since Release 0.1.0-beta
* @link http://api.ip1sms.com/Help
* @link https://github.com/iP1SMS/ip1-php-sdk
Expand All @@ -16,6 +16,7 @@
use IP1\RESTClient\Core\ProcessedComponentInterface;
use IP1\RESTClient\Core\UpdatableComponentInterface;
use IP1\RESTClient\Core\ProcessableComponentInterface;
use \Httpful\Response;

/**
* Handles request to the API and converts the responses into the data classes.
Expand All @@ -24,11 +25,20 @@
class Communicator
{
/**
* The accountToken and $accessToken combined into the HTTP Basic Auth format.
* @var string $accessQuery
* The accountToken used for the first argument in HTTP Basic Auth.
* @var string $accountToken
*/
private $accessQuery;

private $accountToken;
/**
* The apiToken used for the second argument in HTTP Basic Auth.
* @var string $apiToken
*/
private $apiToken;
/**
* An array of \Httpful\Response that returned HTTP code above or equal to 400.
* @var array \Httpful\Response
*/
public $errorResponses = [];
const DOMAIN = "api.ip1sms.com";
/**
* Communicator constructor
Expand All @@ -37,7 +47,8 @@ class Communicator
*/
public function __construct(string $accountToken, string $apiToken)
{
$this->accessQuery = base64_encode($accountToken .":" . $apiToken);
$this->accountToken = $accountToken;
$this->apiToken = $apiToken;
}
/**
* Adds the param to the API and returns the response as the corresponding object.
Expand Down Expand Up @@ -196,28 +207,28 @@ private static function parseEndPoint(string $endPoint)
* Sends a HTTP request to the RESTful API and returns the result as a JSON string.
*
* @param string $endPoint The URI that the function should use.
* @param string $method The HTTP method that should be used, valid ones are: POST, GET, DELETE, PUT.
* @param string $method The HTTP method that should be used, valid ones are:
* METH_POST, METH_GET, METH_DELETE and METH_PUT.
* @param string $content A JSON string containing all additional data that can not be provided by $endPoint.
* @param boolean $https Whether the the API call should use HTTPS or not(HTTP).
* @return string The response from the API.
*/
private function sendRequest(string $endPoint, string $method, string $content = "", bool $https = false): string
private function sendRequest(string $endPoint, string $method, string $content = "", bool $https = false): Response
{
$options = array(
'http' => array(
'header' => array(
'Content-Type: application/json',
'Authorization: Basic '. $this->accessQuery,
'Content-Length: ' . strlen($content),
),
'user_agent' => 'IP1sms/indev',
'method' => $method,
'content' => $content,
)
);
$url = ($https ? "https://" : "http://") . self::DOMAIN . "/" .$endPoint;
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$request = \Httpful\Request::init($method, 'application/json');
$request->basicAuth($this->accountToken, $this->apiToken)
->addHeader('User-Agent', 'iP1sms/indev')
->expectsJson()
->Uri($url)
->body($content, 'application/json')
->neverSerialize();

$response = $request->send();

if ($response->hasErrors()) {
$this->errorResponses[] = $response;
}
return $response;
}
}
22 changes: 22 additions & 0 deletions src/Core/OwnableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.3.0-beta
* @since File available since Release 0.3.0-beta
* @link http://api.ip1sms.com/Help
* @link https://github.com/iP1SMS/ip1-php-sdk
*/
namespace IP1\RESTClient\Core;

interface OwnableInterface
{

/**
* Returns ID of account owning the implemented object.
* @return ID of account owning the implemented object.
*/
public function getOwnerID(): string;
}
2 changes: 1 addition & 1 deletion src/Core/ProcessableComponentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.1.0-beta
* @since File available since Release 0.1.0-beta
Expand Down
2 changes: 1 addition & 1 deletion src/Core/ProcessedComponentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.1.0-beta
* @since File available since Release 0.1.0-beta
Expand Down
2 changes: 1 addition & 1 deletion src/Core/UpdatableComponentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.1.0-beta
* @since File available since Release 0.1.0-beta
Expand Down
2 changes: 1 addition & 1 deletion src/Recipient/BlacklistEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.2.0-beta
* @since File available since Release 0.2.0-beta
Expand Down
2 changes: 1 addition & 1 deletion src/Recipient/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.2.0-beta
* @since File available since Release 0.1.0-beta
Expand Down
2 changes: 1 addition & 1 deletion src/Recipient/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.2.0-beta
* @since File available since Release 0.1.0-beta
Expand Down
6 changes: 3 additions & 3 deletions src/Recipient/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.1.0-beta
* @version 0.3.0-beta
* @since File available since Release 0.1.0-beta
* @link http://api.ip1sms.com/Help
* @link https://github.com/iP1SMS/ip1-php-sdk
Expand Down Expand Up @@ -64,7 +64,7 @@ public function jsonSerialize(): array
{
$returnArray = [
'Group' => $this->groupID,
'Contact' => $this->ContactID,
'Contact' => $this->contactID,
];
return $returnArray;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Recipient/MembershipRelationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.1.0-beta
* @since File available since Release 0.1.0-beta
Expand Down
2 changes: 1 addition & 1 deletion src/Recipient/ProcessedBlacklistEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <[email protected]>
* @copyright 2017 IP1 SMS
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.2.0-beta
* @since File available since Release 0.2.0-beta
Expand Down
Loading

0 comments on commit 6f6161f

Please sign in to comment.