Skip to content

Commit

Permalink
Initial Release Ready for testing (#1)
Browse files Browse the repository at this point in the history
* Updated Functions

* Updated Readme

* Updated changelog
  • Loading branch information
cybersai committed May 2, 2020
1 parent a8e05f3 commit c795b89
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 62 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: php

php:
- '7.2'
- '7.3'
- '7.4'

sudo: false

cache:
directories:
- $HOME/.composer/cache

before_script:
- travis_retry composer self-update
- travis_retry composer update --no-interaction --prefer-dist

script:
- vendor/bin/phpunit
21 changes: 18 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# Changelog

All notable changes to `Ussd` will be documented in this file.
All notable changes to `laravel Ussd` will be documented in this file.

## Version 1.0
## [Unreleased]

## [v0.1.0] - 2020-05-02
### Added
- Everything
- Ussd Package Project with README, contributing, changelog, license, etc.
- State class to define what should occur at various stages when user navigates
- Artisan command to create State classes
- Machine class to run all linked States
- HasManipulators traits to help Machine Class with common functions
- Menu class to be used create user menus in the various states
- Decision class to decide on how to link the various states after accepting user's input
- Record class to save data
- Ussd Class to provide access other classes
- Ussd facade to proxy to the Ussd class
- Ussd config to allow developers customize behaviour
- Ussd service Provider class to allow laravel know how to integrate the package

[Unreleased]: ../../compare/v0.1.0...HEAD
[v0.1.0]: ../../releases/tag/v0.1.0
23 changes: 18 additions & 5 deletions config/ussd.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@

'class_namespace' => 'App\\Http\\Ussd',

/*
|--------------------------------------------------------------------------
| Store
|--------------------------------------------------------------------------
|
| This value sets the default store to use for the ussd record.
| The store can be found in your cache stores config
|
*/

'store' => null,


/*
|--------------------------------------------------------------------------
| Time to live
Expand All @@ -24,17 +37,17 @@
|
*/

'cache_ttl' => 0,
'cache_ttl' => null,

/*
|--------------------------------------------------------------------------
| Store
| Default value
|--------------------------------------------------------------------------
|
| This value sets the default store to use for the ussd record.
| The store can be found in your cache stores config
| This value return the default store value when a given cache key
| is not found
|
*/

'store' => null,
'cache_default' => null,
];
51 changes: 43 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,53 @@
[![Total Downloads][ico-downloads]][link-downloads]
[![Build Status][ico-travis]][link-travis]

This is where your description should go. Take a look at [contributing.md](contributing.md) to see a to do list.
Create ussd with ease. Take a look at [contributing.md](contributing.md) to see a to do list.

## Installation

Via Composer

``` bash
$ composer require sparors/ussd
$ composer require sparors/laravel-ussd
```

Ussd is meant to provide zero configuration out of the box. But optional you can publish the configuration to customize it to suit you.

``` bash
$ php artisan vendor:publish --provider="Sparors\Ussd\UssdServiceProvider" --tag=config
```

## Usage

Create your ussd states by running the command

``` bash
php artisan ussd:state Welcome
````

After creating your states, you can link them to one another and just create a machine to run it.

``` php
<?php
use App\Ussd\Welcome;
use Illuminate\Support\Facades\Route;
use Sparors\Ussd\Facades\Ussd;
Route::get('/', function () {
$ussd = Ussd::machine()
->setInput('1')
->setNetwork('MTN')
->setSessionId('12350')
->setPhoneNumber('0545112466')
->setInitialState(Welcome::class);
return response()->json($ussd->run());
});
```
That all the magic you need to make it run
## Change log
Please see the [changelog](changelog.md) for more information on what has changed recently.
Expand Down Expand Up @@ -43,12 +78,12 @@ If you discover any security related issues, please email isaacsai030@gmail.com
MIT. Please see the [license file](license.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/sparors/ussd.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/sparors/ussd.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/sparors/ussd/master.svg?style=flat-square
[ico-version]: https://img.shields.io/packagist/v/sparors/laravel-ussd.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/sparors/laravel-ussd.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/sparors/laravel-ussd/master.svg?style=flat-square
[link-packagist]: https://packagist.org/packages/sparors/ussd
[link-downloads]: https://packagist.org/packages/sparors/ussd
[link-travis]: https://travis-ci.org/sparors/ussd
[link-packagist]: https://packagist.org/packages/sparors/laravel-ussd
[link-downloads]: https://packagist.org/packages/sparors/laravel-ussd
[link-travis]: https://travis-ci.org/sparors/laravel-ussd
[link-author]: https://github.com/sparors
[link-contributors]: ../../contributors
4 changes: 2 additions & 2 deletions src/Commands/state.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use Sparors\Ussd\State;

class [class] extends State
{
protected function prepareMenu(): void
protected function beforeRendering(): void
{
//
}

protected function prepareDecision(string $argument): void
protected function afterRendering(string $argument): void
{
//
}
Expand Down
53 changes: 53 additions & 0 deletions src/Decision.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

class Decision
{
/** @var boolean */
protected $decided;

protected $argument;

/** @var string */
protected $output;

public function __construct($argument = null)
Expand Down Expand Up @@ -38,11 +40,20 @@ private function setOutputForCondition($condition, $output)
return $this;
}

/**
* @return string
*/
public function outcome()
{
return $this->output;
}

/**
* @param mixed $argument
* @param string $output
* @param boolean $strict
* @return Decision
*/
public function equal($argument, $output, $strict = false)
{
return $this->setOutputForCondition(function () use ($argument, $strict) {
Expand All @@ -53,61 +64,103 @@ public function equal($argument, $output, $strict = false)
}, $output);
}

/**
* @param string $output
* @return Decision
*/
public function numeric($output)
{
return $this->setOutputForCondition(function () {
return is_numeric($this->argument);
}, $output);
}

/**
* @param string $output
* @return Decision
*/
public function integer($output)
{
return $this->setOutputForCondition(function () {
return is_integer($this->argument);
}, $output);
}

/**
* @param string $output
* @return Decision
*/
public function amount($output)
{
return $this->setOutputForCondition(function () {
return preg_match("/^[0-9]+(?:\.[0-9]{1,2})?$/", $this->argument);
}, $output);
}

/**
* @param mixed $argument
* @param string $output
* @return Decision
*/
public function length($argument, $output)
{
return $this->setOutputForCondition(function () use ($argument) {
return strlen($this->argument) === $argument;
}, $output);
}

/**
* @param string $output
* @return Decision
*/
public function phoneNumber($output)
{
return $this->setOutputForCondition(function () {
return preg_match("/^[0][0-9]{9}$/", $this->argument);
}, $output);
}

/**
* @param int $start
* @param int $end
* @param string $output
* @return Decision
*/
public function between($start, $end, $output)
{
return $this->setOutputForCondition(function () use ($start, $end) {
return $this->argument >= $start && $this->argument <= $end;
}, $output);
}

/**
* @param array $array
* @param string $output
* @param bool $strict
* @return Decision
*/
public function in($array, $output, $strict = false)
{
return $this->setOutputForCondition(function () use ($array, $strict) {
return in_array($array, $this->argument, $strict);
}, $output);
}

/**
* @param callable $function
* @param string $output
* @return Decision
*/
public function custom($function, $output)
{
$func = function () use ($function) { return $function($this->argument); };
return $this->setOutputForCondition($func, $output);
}

/**
* @param string $output
* @return Decision
*/
public function any($output)
{
return $this->setOutputForCondition(function () {
Expand Down

0 comments on commit c795b89

Please sign in to comment.