Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Refacto and enhancement (#9)
Browse files Browse the repository at this point in the history
- Added .gitignore, .gitattributes 
- Made some changes to the NexmoServiceProvider and Facade so as they reflect more the Laravel coding style.
- Added some test cases.
  • Loading branch information
percymamedy authored and mheap committed Oct 5, 2017
1 parent b30241a commit f4cd2a4
Show file tree
Hide file tree
Showing 14 changed files with 486 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto

/.gitattributes export-ignore
/.gitignore export-ignore
/README.md export-ignore
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/vendor
/.env
composer.phar
composer.lock
.DS_Store
Thumbs.db
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: php

php:
- 5.6
- 7.0
- 7.1

before_script:
- composer self-update

install:
- composer install --prefer-source --no-interaction --dev

script: vendor/bin/phpunit
85 changes: 62 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
Nexmo Package for Laravel
=========================
<h2 align="center">
Nexmo Package for Laravel
</h2>

<p align="center">
<a href="https://packagist.org/packages/nexmo/laravel"><img src="https://poser.pugx.org/nexmo/laravel/v/stable?format=flat-square" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/nexmo/laravel"><img src="https://poser.pugx.org/nexmo/laravel/v/unstable?format=flat-square" alt="Latest Unstable Version"></a>
<a href="https://packagist.org/packages/nexmo/laravel"><img src="https://poser.pugx.org/nexmo/laravel/license?format=flat-square" alt="License"></a>
<a href="https://packagist.org/packages/nexmo/laravel"><img src="https://poser.pugx.org/nexmo/laravel/downloads" alt="Total Downloads"></a>
</p>

## Introduction

This is a simple Laravel Service Provider providing access to the [Nexmo PHP Client Library][client-library].

Installation
------------

To install the PHP client library using Composer:

composer require nexmo/laravel
```bash
composer require nexmo/laravel
```

Alternatively, add these two lines to your composer require section:

"nexmo/laravel": "^1.0"
```json
{
"require": {
"nexmo/laravel": "^1.0"
}
}
```

### Laravel 5.5+

Expand All @@ -21,49 +40,69 @@ If you're using Laravel 5.5 or above, the package will automatically register th

Add `Nexmo\Laravel\NexmoServiceProvider` to the `providers` array in your `config/app.php`:

Nexmo\Laravel\NexmoServiceProvider::class
```php
'providers' => [
// Other service providers...

Nexmo\Laravel\NexmoServiceProvider::class,
],
```

If you want to use the facade interface, you can `use` the facade class when needed:

use Nexmo\Laravel\Facade\Nexmo;
```php
use Nexmo\Laravel\Facade\Nexmo;
```

Or add an alias in your `config/app.php`:

'Nexmo' => \Nexmo\Laravel\Facade\Nexmo::class
```php
'aliases' => [
...
'Nexmo' => Nexmo\Laravel\Facade\Nexmo::class,
],
```

Configuration
-------------

You can use `artisan vendor:publish` to copy the distribution configuration file to your app's config directory:

php artisan vendor:publish
```bash
php artisan vendor:publish
```

Then update `config/nexmo.php` with your credentials. Alternatively, you can update your `.env` file with the following:

```
NEXMO_KEY = my_api_key
NEXMO_SECRET = my_secret
```dotenv
NEXMO_KEY=my_api_key
NEXMO_SECRET=my_secret
```

Usage
-----

To use the Nexmo Client Library you can use the facade, or request the instance from the service container:

Nexmo::message()->send([
'to' => '14845551244',
'from' => '16105552344',
'text' => 'Using the facade to send a message.'
]);
```php
Nexmo::message()->send([
'to' => '14845551244',
'from' => '16105552344',
'text' => 'Using the facade to send a message.'
]);
```

Or

//or
```php
$nexmo = app('Nexmo\Client');

$nexmo = app('Nexmo\Client');
$nexmo->message()->send([
'to' => '14845551244',
'from' => '16105552344',
'text' => 'Using the instance to send a message.'
]);
$nexmo->message()->send([
'to' => '14845551244',
'from' => '16105552344',
'text' => 'Using the instance to send a message.'
]);
```

For more information on using the Nexmo client library, see the [official client library repository][client-library].

Expand Down
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@
"email": "devrel@nexmo.com"
},
"require": {
"php": ">=5.6",
"illuminate/support": "^5.2",
"nexmo/client": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.3",
"orchestra/testbench": "~3.0"
},
"autoload": {
"psr-4": {
"Nexmo\\Laravel\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Nexmo\\Laravel\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
Expand Down
5 changes: 3 additions & 2 deletions config/nexmo.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

return [

/*
Expand All @@ -11,7 +12,7 @@
|
*/

'api_key' => function_exists('env') ? env('NEXMO_KEY', '') : '',
'api_key' => function_exists('env') ? env('NEXMO_KEY', '') : '',
'api_secret' => function_exists('env') ? env('NEXMO_SECRET', '') : '',

/*
Expand All @@ -27,4 +28,4 @@

'signature_secret' => function_exists('env') ? env('NEXMO_SIGNATURE_SECRET', '') : '',

];
];
23 changes: 23 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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="Nexmo Laravel Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_DEBUG" value="true"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="CACHE_DRIVER" value="array"/>
</php>
</phpunit>
11 changes: 9 additions & 2 deletions src/Facade/Nexmo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

namespace Nexmo\Laravel\Facade;

use Illuminate\Support\Facades\Facade;
use Nexmo\Client;
use Illuminate\Support\Facades\Facade;

class Nexmo extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*
* @throws \RuntimeException
*/
protected static function getFacadeAccessor()
{
return Client::class;
}
}
}
Loading

0 comments on commit f4cd2a4

Please sign in to comment.