-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0864333
Showing
15 changed files
with
291 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
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,13 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --prefer-source --no-interaction --dev | ||
|
||
script: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "christian-giupponi/nexmo", | ||
"description": "This is a Laravel4 package that helps you integrate Nexmo sms services into your site.", | ||
"License": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Christian Giupponi", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "4.2.*", | ||
"guzzlehttp/guzzle": "~5.0" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"src/migrations" | ||
], | ||
"psr-0": { | ||
"ChristianGiupponi\\Nexmo\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
Empty file.
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,14 @@ | ||
<?php namespace ChristianGiupponi\Nexmo\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Nexmo extends Facade { | ||
|
||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() { return 'nexmo'; } | ||
|
||
} |
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,164 @@ | ||
<?php | ||
|
||
namespace ChristianGiupponi\Nexmo; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class Nexmo { | ||
|
||
protected $apiKey; | ||
protected $apiSecret; | ||
public $nexmoUrl = "https://rest.nexmo.com/account/"; | ||
public $nexmoPostUrl = "https://rest.nexmo.com/sms/json"; | ||
|
||
/** | ||
* getBalance | ||
* this function will return the balance of you Nexmo account | ||
* | ||
* @return json | ||
*/ | ||
public function getBalance() | ||
{ | ||
//Set the base api url | ||
$base_url = "get-balance/"; | ||
|
||
//Get result from api | ||
return $this->get_request( $base_url ); | ||
|
||
} | ||
|
||
/** | ||
* pricing | ||
* Get the price of a given country. | ||
* It returns also the available carrier name with price. | ||
* | ||
* @param string $countryOrPrefix | ||
* @return json | ||
*/ | ||
public function pricing( $countryOrPrefix = '' ) | ||
{ | ||
//check if the request is fo a specific country or prefix | ||
if( trim( $countryOrPrefix ) == '' ) | ||
{ | ||
return json_encode( [ | ||
'code' => '400', | ||
'reason' => 'Code or Prefix required', | ||
'body' => '' | ||
] ); | ||
} | ||
|
||
$base_url = 'get-pricing/outbound/'; | ||
$params = '/' . $countryOrPrefix; | ||
|
||
return $this->get_request( $base_url, $params ); | ||
|
||
} | ||
|
||
/** | ||
* Send SMS | ||
* | ||
* This function will send a post request to Nexmo website to send a new sms | ||
* To see all the options available please visite nexmo website: | ||
* https://docs.nexmo.com/index.php/sms-api/send-message | ||
* The option must be formed like: array( 'foo' => 'bar' ) | ||
* | ||
* @param string $from | ||
* @param string $to | ||
* @param string $text | ||
* @param array $options | ||
* @return json | ||
*/ | ||
public function sendSMS( $from = '', $to = '', $text = '', $options = [ ] ) | ||
{ | ||
if( trim( $from ) == '' || trim( $to ) == '' || trim( $text ) == '' ) | ||
{ | ||
return json_encode( [ | ||
'code' => '400', | ||
'reason' => 'Missing parameter, Form - To and Text are required.', | ||
'body' => '' | ||
] ); | ||
} | ||
|
||
$required = [ | ||
'from' => $from, | ||
'to' => $to, | ||
'text' => urlencode( $text ) | ||
]; | ||
|
||
return $this->post_request( $required, $options ); | ||
|
||
} | ||
|
||
/** | ||
* api_request | ||
* This function will make the api call using GuzzleHttp | ||
* | ||
* @param $method | ||
* @param $base_url | ||
* @param string $params | ||
* @return json | ||
*/ | ||
public function get_request( $base_url, $params = '' ) | ||
{ | ||
$this->apiKey = \Config::get( 'nexmo::nexmo_api_key' ); | ||
$this->apiSecret = \Config::get( 'nexmo::nexmo_api_secret' ); | ||
|
||
//Create the url | ||
$url = $this->nexmoUrl . $base_url . $this->apiKey . '/' . $this->apiSecret . $params; | ||
|
||
//Initialize a new client for api request | ||
$client = new Client(); | ||
|
||
//Send the request | ||
$response = $client->get( $url, [ | ||
'headers' => [ 'Accept' => 'application/json' ] | ||
] ); | ||
|
||
//Get the result | ||
$code = $response->getStatusCode(); | ||
$reason = $response->getReasonPhrase(); | ||
$body = $response->json(); | ||
|
||
//Format the result | ||
return json_encode( [ | ||
'code' => $code, | ||
'reason' => $reason, | ||
'body' => $body | ||
] ); | ||
} | ||
|
||
public function post_request( $requried = [ ], $optional = [ ] ) | ||
{ | ||
//Get api from config file | ||
$this->apiKey = \Config::get( 'nexmo::nexmo_api_key' ); | ||
$this->apiSecret = \Config::get( 'nexmo::nexmo_api_secret' ); | ||
|
||
//Create uri params with the required file | ||
$required_url = http_build_query( $requried ); | ||
|
||
//If there are any optional fields let's add them | ||
$optional_url = ( count( $optional ) > 0 ) ? '&' . http_build_query( $optional ) : ''; | ||
|
||
//This is the final url | ||
$url = $this->nexmoPostUrl . "?api_key=" . $this->apiKey . '&api_secret=' . $this->apiSecret . '&' . $required_url . $optional_url; | ||
|
||
//Initialize a new client for api request | ||
$client = new Client(); | ||
|
||
//Make POST request | ||
$response = $client->post( $url ); | ||
|
||
//Get the result | ||
$code = $response->getStatusCode(); | ||
$reason = $response->getReasonPhrase(); | ||
$body = $response->json(); | ||
|
||
//Format the result | ||
return json_encode( [ | ||
'code' => $code, | ||
'reason' => $reason, | ||
'body' => $body | ||
] ); | ||
|
||
} | ||
} |
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,47 @@ | ||
<?php namespace ChristianGiupponi\Nexmo; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class NexmoServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->package('christian-giupponi/nexmo'); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app['nexmo'] = $this->app->share(function($app) | ||
{ | ||
return new Nexmo; | ||
}); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array(); | ||
} | ||
|
||
} |
Empty file.
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,6 @@ | ||
<?php | ||
|
||
return [ | ||
'nexmo_api_key' => '', | ||
'nexmo_api_secret' => '' | ||
]; |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.