poing / laravel-wombatdialer-api Goto Github PK
View Code? Open in Web Editor NEWWombatDialer API Library for Laravel
License: GNU General Public License v3.0
WombatDialer API Library for Laravel
License: GNU General Public License v3.0
I have not had time to look into it yet... But this is what I suspect is happening.
I think that subsequent API
calls are failing, silently. When the API::insert()
fails inside chunk(), we're not seeing any errors.
The first thing we can do, are some assertion tests on the chunk()
data. Confirm multiple chunks are processed, Model::count()
should be evenly dividable by $chunks
.
$chunks = config('wombatdialer.chunk_size');
$model = Model::seed(Factory($chunks * 12)); // SOMETHING LIKE THIS!! - Total should be multiple of $chunks
$model->chunk($chunks, function ($records) use ($list, $column) {
$chunk_count = config('wombatdialer.chunk_size');
assert($chunk_count, $records->count());
});
We can also look at using try{}
or add error handling inside chunk()
. See if we can catch the error and determine why Lists::insert()
is not processing every trunk.
$model->chunk($chunks, function ($records) use ($list, $column) {
try {
Lists::insert();
} catch (Throwable $e) {
report($e);
return false;
}
});
$model->chunk($chunks, function ($records) use ($list, $column) {
$response = Lists::insert();
if (!$response->ok()) {
report(SOME ERROR); // Whole $response or something...
}
});
Service Providers are how we integrate a packages into Laravel. When accessing the Laravel application, it will check boot()
and register()
from all the service providers.
We're going to change WombatdialerServiceProvider.php
from or basic test, into a service provider.
namespace WombatDialer
use Illuminate\Support\ServiceProvider;
class WombatdialerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
// do something
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// do something
}
}
We could add the service provider to the providers
section in config/app.php
. But that's the old manual way of doing it.
'providers' => [
....
WombatDialer\WombatdialerServiceProvider::class,
....
],
Instead, we're going to put a directive in composer.json
for the package. This will automatically add the service provider to any Laravel Application that uses the package.
"extra": {
"laravel": {
"providers": [
"WombatDialer\\WombatdialerServiceProvider"
]
}
}
So add the above to the packages composer.json
than run composer dumpautoload
in the Laravel Application.
We'll check it's working in the next task!
Please check and review all the verbs for edit/trunk
. We need this to work ASAP.
Please check all the verbs are working as expected.
I would like to see the documentation show the available methods and inputs. Use the below as a template.
API
Reference:Provides access to the WombatDialer trunk data
.
Equivalent to: http://example.com:8080/wombat/api/edit/trunk/
The Edit\Trunk::class
provides:
index()
show($id)
$id
the trunkId
value of a specific trunkcreate($data)
$data
is an array
containing data
to create a new trunk.$data
must not contain trunkId
.values
will be provided by $this->default
.update($data)
$data
is an array
containing the data
for the trunk you want to update.trunkId
of the trunk to update.destroy($id)
$id
the trunkId
value of a specific trunk delete.$default = [
'astId' => [
'id' => 101,
],
'name' => 'Gamma',
'dialstring' => 'Local/${num}@from-internal/n',
'capacity' => 10,
'securityKey' => '',
];
Create your own Controller
to change the $default
values.
The example below shows how to change the default values for Edit\Trunk::class
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use WombatDialer\Controllers\Edit\Trunk;
use Illuminate\Support\Facades\Http;
class MyTrunk extends Trunk
{
// change default values
protected $default = [
'astId' => [
'id' => 999,
],
'name' => 'New Default',
'dialstring' => 'SIP/${num}@from-other-context/n',
'capacity' => 100,
'securityKey' => '',
];
}
Same as edit/trunk.
Same as edit/trunk.
This is the master checklist. I will be using this to confirm each API
element has been addresses.
.
├── addkey
├── callinfo
├── calls
├── campaigns
├── dialer
├── edit
│ ├── asterisk
│ ├── campaign
│ │ ├── disposition
│ │ ├── ep
│ │ ├── list
│ │ ├── oh
│ │ ├── reschedule
│ │ └── trunk
│ ├── ep
│ ├── list
│ │ ├── logs
│ │ └── record
│ ├── oh
│ └── trunk
├── inspect_dialer
├── lists
├── live
│ ├── calls
│ └── runs
├── recallinfo
├── reports
│ ├── logs
│ ├── runs
│ └── stats
├── reserve
├── runlists
├── runs
└── sysup
└── jmx
Migrated from GitLab. This might be complete...
Add all the API
verbs for oh
.
get()
create()
update()
destroy()
index()
As identified in #40, the listRules
are composite objects. Not like other nested items.
With that in mind, let's resume working on Opening Hours. Addressing the DoW
appropriately.
Update the readme, add the following.
Below is the full tree
view of the WombatDialer API
. Including undocumented methods.
api
├── addkey
├── callinfo
├── calls
├── campaigns
├── dialer
├── edit
│ ├── asterisk
│ ├── campaign
│ │ ├── disposition
│ │ ├── ep
│ │ ├── list
│ │ ├── oh
│ │ ├── reschedule
│ │ └── trunk
│ ├── ep
│ ├── list
│ │ ├── logs
│ │ └── record
│ ├── oh
│ └── trunk
├── inspect_dialer
├── lists
├── live
│ ├── calls
│ └── runs
├── recallinfo
├── reports
│ ├── logs
│ ├── runs
│ └── stats
├── reserve
├── runlists
├── runs
└── sysup
└── jmx
Since we're making a stand-alone package, we don't have to put everything in app/Http/Controllers
. We can continue with the flat structure or try sorting the controllers closer to the API
structure above.
Just need to use the correct namespace
. Which would allow us to reuse some of the same class names.
namespace WombatDialer\Controllers\Edit;
use WombatDialer\Controllers\Wombat;
class Oh extends Wombat
{
use \WombatDialer\Concerns\OpenHourTraits;
}
namespace WombatDialer\Controllers\Edit\Campaign;
use WombatDialer\Controllers\Wombat;
class Oh extends Wombat
{
use \WombatDialer\Concerns\CampOpenHourTraits;
}
To use the abouve classes, we just have to do the following:
$openHours = new \WombatDialer\Controllers\Edit\Oh;
$campOpenHours = new \WombatDialer\Controllers\Edit\Campaign\Oh;
So... Most of the primary API
's have been addressed. At least the one's we really need for another project.
There are some lesser API
's we should include in the package. At a minimum, provide index()
for them.
Most of these I personally have not used, not sure how to use. You'll need to refer to the documentation for more information.
Note: Some may even require a campaign to be running or a call to be established.
Please add the following to the package:
Same as edit/trunk.
Destroy()
is throwing the below error for both the Reschedule Rules
and Disposition Rules
.
See #43(GitLab) for images.
You may was to tyr passing the record as URL query, not $data
. Check the docs.
Let's get starting with unit testing with phpunit
.
First, you should review Writing unit tests in PHP using PHPUnit and try making CalculatorTest.php
from the article work on your local machine.
For this package, you can start by looking at the test setup for earmark. I will walk you through some of the harder parts.
It's time to change userAuth()
and passAuth()
to use session based variables.
session(['wombatUser' => 'alpha']);
session(['WombatPass' => 'alpha']);
$campaign = new Campaign;
$campaign->index();
Using alpha
you should only see two (2)
campaigns. Same goes for the GUI
.
The methods should be something like this...
function xxxxAuth()
{
return $request->session()->pull('wombatAuth', $this->userPass);
}
The reason we created userAuth()
and passAuth()
is to allow the function to be over-ridden in different ways.
One way is with a customized controller, although we have no real reason to do this. It's just for flexibility.
use App\Http\Controllers\Campaign;
class myCampaign extends Campaign
{
function userAuth()
{
return 'customUser';
}
function passAuth()
{
return 'customPass';
}
}
We might want to consider adding variables
to the Wombat construct()
too.
public function __construct($user=null, $pass=null)
{
$this->user = $user ?: config('wombatapi.admin.user'); //the config should be changed to session for authentication
$this->pass = $pass ?: config('wombatapi.admin.pass');
}
This could allow us to do the following:
tinker
>>> $campaign = new Name\Space\Campaign('alpha','alpha');
Let's make the variable name for the session
a configuration option. That could be set in the config file -or- .env
.
This is to add flexibility.
Up to you, if you put it in the default
or wombatdialer
config file.
Once issue #8 is working and you created config/wombatdialer.php
in your Laravel Application, we can modify the config file directly to set the host
. Try: example.com
.
'url' => [
'scheme' => env('WOMBAT_SCHEME' , 'http'),
'host' => env('WOMBAT_HOST', 'example.com'),
'port' => env('WOMBAT_PORT' , '8080'),
'path' => env('WOMBAT_PATH', '/wombat/api/'),
],
tinker
>>> config('wombatdialer.url')
And then....
We can modify the config via .env
.
WOMBAT_HOST=example.net
tinker
>>> config('wombatdialer.url')
And we're done with the config
, having implemented functional and flexible configuration methods for the package.
Now... choose a method and set our private WombatDialer host
address in the Laravel Application.
same as edit/trunk.
Were going to create two (2)
configuration files.
src/config/default.php
src/config/wombatdialer.php
DO NOT use the invite-comm.jp
address anywhere in the public repository.
return [
'admin' => [
'user' => env('WOMBAT_USER', 'demoadmin'),
'pass' => env('WOMBAT_PASS', 'demo'),
],
];
We will comment out the admin
settings. This file
will be installed in the Laravel Application. Will show you how in later task.
return [
/*
|--------------------------------------------------------------------------
| Add Comments
|--------------------------------------------------------------------------
|
| Explain these settings
|
*/
'url' => [
'scheme' => env('WOMBAT_SCHEME' , 'http'),
'host' => env('WOMBAT_HOST', 'localhost'),
'port' => env('WOMBAT_PORT' , '8080'),
'path' => env('WOMBAT_PATH', '/wombat/api/'),
],
/*
|--------------------------------------------------------------------------
| Add Comments
|--------------------------------------------------------------------------
|
| Explain these settings
|
*/
// 'admin' => [
// 'user' => env('WOMBAT_USER', 'demoadmin'),
// 'pass' => env('WOMBAT_PASS', 'demo'),
// ],
];
We use two (2)
files, so we can hide some settings. Allow the user to change default values, uncomment and change others.
We will apply the admin
settings from the default, the user has to uncomment the setting to change it.
I have added .styleci.yml
to the project.
Please run the package source against styleci and apply the recommended code fixes.
This will check the code, find issues and provide fixes.
Do not do this in the poing/laravel-wombatdialer-api
repo.
We want to create a new Laravel project in your valet
directory.
cd ~/Documents/dev/valet
composer create-project --prefer-dist laravel/laravel project_name
The project_name
can be anything you're not already using.
You will not run tinker
in the package directory, you can't. Use the Laravel Application just created when you want to run tinker
.
Before we can add our package to the Application, we have to modify composer.json
.
cd ~/Documents/dev/valet/project_name
bbedit composer.json
We want to add the following section to composer.json
for the Laravel Application.
Not the composer.json
you were just working with!
This will tell composer
to check the poing
directory in the parent directory (valet
) for packages from the poing
vendor.
"repositories": {
"poing": {
"type": "path",
"url": "../poing/**",
"options": {
"symlink": true
}
}
}
Once composer.json
has been updated. You can add the package to your Laravel Application.
cd ~/Documents/dev/valet/project_name
composer require poing/laravel-wombatdialer-api
Watch the output, should say it's being symlinked.
You can verify it was installed, by checking vendor/poing
.
ls vendor/poing
ls ~/Documents/dev/valet/project_name/vendor/poing
And we should be able to access package from tinker
>>> \WombatDialer\WombatdialerServiceProvider::test()
hello world
The first thing we need to do, is initialize the package with composer
.
cd ~/Documents/dev/valet/poing/laravel-wombatdialer-api
git branch 0.0.0
git checkout 0.0.0
composer init
Since the Laravel HTTP Client was introduced in version 7.0, we need set the minimal version of the laravel/framework
.
You'll be prompted to enter a number of variables, enter to accept the [default]. Other variables shown below.
Package name (<vendor>/<name>) [poing/laravel-wombatdialer-api]:
Description []: WombatDialer API Library for Laravel
Minimum Stability []:
Package Type (e.g. library, project, metapackage, composer-plugin) []: library
License []: GPL
Would you like to define your dependencies (require) interactively [yes]?
Search for a package: laravel/framework
Enter the version constraint to require (or leave blank to use the latest version): >=7.0
Search for a package:
Would you like to define your dev dependencies (require-dev) interactively [yes]? no
Do you confirm generation [yes]?
Would you like to install dependencies now [yes]? no
This will generate the following composer.json
:
{
"name": "poing/laravel-wombat-api",
"description": "WombatDialer API Library for Laravel",
"type": "library",
"require": {
"laravel/framework": ">=7.0"
},
"license": "GPL",
"authors": [
{
"name": "Komal Raja",
"email": "[email protected]"
}
]
}
We're going to make some schema changes. Add the properties shown below. Most are administrative.
{
"name": "poing/laravel-wombat-api",
"description": "WombatDialer API Library for Laravel",
"type": "library",
"require": {
"laravel/framework": ">=7.0"
},
"license": "GPL",
"authors": [
+ {
+ "name": "poing",
+ "email": "[email protected]"
+ },
{
"name": "Komal Raja",
"email": "[email protected]"
}
- ]
+ ],
+ "homepage": "https://github.com/poing/laravel-wombatdialer-api",
+ "support": {
+ "issues": "https://github.com/poing/laravel-wombatdialer-api/issues",
+ "irc": "irc://irc.freenode.org/poing"
+ },
+ "autoload": {
+ "psr-4": {
+ "WombatDialer\\": "src/"
+ }
+ }
}
The key item is the PSR-4 autoload
directive. This defines the namespace
and tells PHP
where to find the files. It's how composer
loads packages, you've seen it when installing Laravel.
We're going to use WombatDialer
as the root PHP
namespace
. Note the CamelCase
.
All the files for the namespace
will located in a directory
named src/
. You'll need to create the direcroty
.
mkdir ~/Documents/dev/valet/poing/laravel-wombatdialer-api/src/`
While creating a new record for the API'S
in Reschedule Rules
and in Disposition Rules
. The status were repeated .
See #42(GitLab) for image.
$asterisk = new \WombatDialer\Controllers\Edit\Asterisk;
$asterisk->show($value);
$asterisk->show($value); // Fails
Start with sysup
and abstract Wombat
. Then work down the list of completed API
's. Moving/copying them from wombat-api to this project. Check off each one as you complete it. There are some we have not addressed yet.
.
├── addkey
├── callinfo
├── calls
├── campaigns
├── dialer
├── edit
│ ├── asterisk
│ ├── campaign
│ │ ├── disposition
│ │ ├── ep
│ │ ├── list
│ │ ├── oh
│ │ ├── reschedule
│ │ └── trunk
│ ├── ep
│ ├── list
│ │ ├── logs
│ │ └── record
│ ├── oh
│ └── trunk
├── inspect_dialer
├── lists
├── live
│ ├── calls
│ └── runs
├── recallinfo
├── reports
│ ├── logs
│ ├── runs
│ └── stats
├── reserve
├── runlists
├── runs
└── sysup
└── jmx
Please sanitize Wombat
and CampaignTraits
. Removing any invite-comm.jp
links or addresses.
For the to('address')
please make it a config
setting.
For the trait
use example.com
bash-3.2$ grep -r invite .
./Controllers/Edit/Wombat.php: $message->to('[email protected]')
./Concerns/CampaignTraits.php: 'httpNotify' => 'https://worker.alpha.invite-comm.jp/wombat/wxyz123',
The first step, before cloning this repository...
We're going to need the clone
in a specific location.
mkdir ~/Documents/dev/valet/poing
cd ~/Documents/dev/valet/poing
git clone [email protected]:poing/laravel-wombatdialer-api.git
This will allow you to work locally and install the package from the same local
source that I will use. So we can collaborate.
The package will be named poing/laravel-wombatdialer-api
. Allowing me to manage the package, along with my other packages. The reason for the path
will become clear later.
Create a file named: WombatdialerServiceProvider.php
in ~/Documents/dev/valet/poing/laravel-wombatdialer-api/src/
We'll use this for a simple test, later it will have different content.
namespace WombatDialer;
class WombatdialerServiceProvider
{
function test()
{
return 'hello world';
}
}
We can't use this yet! But we'll get there.
What's the status on DB
to list, using the API
?
I did mention, that we need to chunk the data. AND that I wanted to see a chunk_size
variable added to the configuration file. #41(GitLab)
Please test and document adding numbers to a list.
Please test using the Sample Model
(w/ chunking) and also want you to try with a table
that has 50,000
records in it. Update the seeder to make a larger table.
Now we can add the configuration directives to the Service Provider.
We'll use the publishes()
helper, to instruct the Laravel Application how to create config/wombatdialer.php
.
It goes in the boot()
section of WombatdialerServiceProvider.php
.
It does not create the config file, the user needs to run artisan
commands to create the config file for the Laravel Application.
public function boot()
{
// Publish Configuration Files
$this->publishes([
__DIR__ . '/config/wombatdialer.php' => config_path('wombatdialer.php'),
], 'wombatdialer-config');
}
We'll actually create our own artisan
command to handle publishing the config file later..
We'll use the mergeConfigFrom()
helper in the register()
section of WombatdialerServiceProvider.php
.
public function register()
{
// Default Package Configuration
$this->mergeConfigFrom(__DIR__ . '/config/wombatdialer.php', 'wombatdialer');
$this->mergeConfigFrom(__DIR__ . '/config/default.php', 'wombatdialer');
}
This will make the configuration variables from the package available to the Laravel Application.
composer dumpautoload
tinker
>>> config('wombatdialer.url')
>>> config('wombatdialer.admin')
Same thing, just like issue #20
You can find an example of an artisan
command here.
BTW: I am referencing this package, that I created, to provide you with examples.
You're going to want to create a similar file in src/Commands
.
The handle()
portion should look like this:
public function handle()
{
$this->comment('Publishing WombatDialer Configuration...');
$this->callSilent('vendor:publish', ['--tag' => 'wombatdialer-config']); // tag set in publishes()
$this->info('WombatDialer installed successfully.');
}
Then we need to tell the Laravel Application to make the command available, by adding it to the boot()
method of the service provider. Only need to load it, when running artisan
(aka console).
public function boot()
{
// ...
// Load Commands
if ($this->app->runningInConsole()) {
$this->commands([
WombatdialerInstall::class,
]);
}
// ...
cd valet/project_name
composer dumpautoload
php artisan
...
vendor
vendor:publish Publish any publishable assets from vendor packages
view
view:cache Compile all of the application's Blade templates
view:clear Clear all compiled view files
wombatdialer Some description
wombatdialer:install Another description
php artisan wombatdialer:install
If sucessful, you'll see config/wombatdialer.php
was added to the Laravel Application.
Please merge latest changes into master
and create a new release from master
.
Are you able to [draft new release:(https://github.com/poing/laravel-wombatdialer-api/releases)?
Then start a new working branch from master
.
The new release should show up here.
This will allow anyone to install the package in a Laravel Application without adding the repositories
section to composer.json
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.