GithubHelp home page GithubHelp logo

poing / laravel-wombatdialer-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 259.8 MB

WombatDialer API Library for Laravel

License: GNU General Public License v3.0

PHP 96.59% Dockerfile 0.87% Java 0.08% Shell 2.45%

laravel-wombatdialer-api's People

Contributors

komalraja avatar poing avatar

Watchers

 avatar  avatar

laravel-wombatdialer-api's Issues

Chunk Issue with API

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 Provider

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!

edit/trunk: Check and Document

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:

Edit\Trunk::class

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 trunk
  • create($data)
    • $data is an array containing data to create a new trunk.
    • $data must not contain trunkId.
    • Missing values will be provided by $this->default.
  • update($data)
    • $data is an array containing the data for the trunk you want to update.
    • Requires trunkId of the trunk to update.
  • destroy($id)
    • $id the trunkId value of a specific trunk delete.
Default Values:
$default = [
	'astId' => [
		'id' => 101,
	],
	'name' => 'Gamma',
	'dialstring' => 'Local/${num}@from-internal/n',
	'capacity'  =>  10,
	'securityKey' => '',
];

Usage

Using your own Default Values

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' => '',
  ];
}

Master Checklist

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

Opening Hours: All Verbs

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

Update the readme, add the following.

  • How to install
  • How to install config file
  • How to use
  • How design pattern mirrors WombatDialer
  • Link to WombatDialer manual
  • Add the styleci badge to the top of the readme.

Controller Structure?

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;

How would you like to do it?

Lesser API's

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:

  • addkey
  • callinfo
  • calls
  • inspect_dialer
  • recallinfo
  • reserve
  • runlists
  • runs
  • sysup/jmx

Authentication

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');


Also...

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.

Laravel Application: Config File Installed

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.

Configuration Files

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.


default.php
return [
   'admin' => [
        'user' => env('WOMBAT_USER', 'demoadmin'),
        'pass' => env('WOMBAT_PASS', 'demo'),
    ],
];
wombatdialer.php

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.

Style Check

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.

New Laravel Application

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

Composer Init

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/`

Second use of instance fails

$asterisk = new \WombatDialer\Controllers\Edit\Asterisk;
$asterisk->show($value);
$asterisk->show($value); // Fails

Migrate wombat-api work

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

Sanitize: Wombat and CampaignTraits

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',

Getting Started

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.

Our First Class

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.

List: Add Numbers

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.

Service Provider: Configuration

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')

Command: Install Config File

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.

Merge into Master and Create Release

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.