Skip to content

Commit

Permalink
sms global middleware / beta 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Raheel Hasan committed Sep 29, 2021
0 parents commit 6eb3418
Show file tree
Hide file tree
Showing 84 changed files with 11,284 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
13 changes: 13 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
php:
preset: laravel
disabled:
- unused_use
finder:
not-name:
- index.php
- server.php
js:
finder:
not-name:
- webpack.mix.js
css: true
41 changes: 41 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
55 changes: 55 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*
* @throws \Throwable
*/
public function report(Throwable $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
}
31 changes: 31 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

protected $GET=[], $POST=[];

function __construct()
{
#/ identify and set incoming requests
if(\Request::isMethod('post'))
{
$req_all = \Request::instance()->request->all();

$this->POST = $req_all; //Request::input(); will pollute POST with GET
$this->GET = $_GET; //laravel is ignoring GET if there is POST
}

if(\Request::isMethod('get'))
{
$this->GET = \Request::input();
}
}
}
154 changes: 154 additions & 0 deletions app/Http/Controllers/api/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
namespace App\Http\Controllers\api;

#/ Core
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;

#/ Abstract Parent
use App\Http\Controllers\apiAbstractController;

#/ Helper
use App\Http\Helpers\SMSGlobal;

/**
* @OA\Post(
* path="api/v1/message",
* summary="Post Message via SMSGlobal",
* description="Post message via SMSGlobal API",
* tags={"Messages"},
*
* @OA\Parameter(
* description="Your SMSGlobal REST API Key",
* in="header",
* name="API key",
* required=true
* ),
*
* @OA\Parameter(
* description="Your SMSGlobal REST API Secret",
* in="header",
* name="API Secret",
* required=true
* ),
*
* @OA\RequestBody(
* required=true,
* description="POST your message and destination number",
* @OA\JsonContent(
* required={"message", "destination"},
* @OA\Property(property="message", type="string", format="", example="Test Message"),
* @OA\Property(property="destination", type="string", format="", example="04xxxxxxxx"),
* ),
* ),
*
* @OA\Response(
* response=403,
* description="Unable to determine API Key or Secret!",
* ),
* @OA\Response(
* response=400,
* description="Unable to locate Message or Destination in the payload!",
* ),
* @OA\Response(
* response=200,
* description="Your message has been dispatched successfully.",
* )
* ),
*
* ------------------------------------------------------
*
* @OA\Get(
* path="api/v1/message",
* summary="Get list of sent Message via SMSGlobal",
* description="Get list of sent via SMSGlobal API",
* tags={"Messages"},
*
* @OA\Parameter(
* description="Your SMSGlobal REST API Key",
* in="header",
* name="API key",
* required=true
* ),
*
* @OA\Parameter(
* description="Your SMSGlobal REST API Secret",
* in="header",
* name="API Secret",
* required=true
* ),
*
* @OA\Response(
* response=403,
* description="Unable to determine API Key or Secret!",
* ),
* @OA\Response(
* response=200,
* description="List of messages",
* ),
* @OA\Response(
* response=400,
* description="Unable to locate messages!",
* ),
* ) *
*/


class messages extends apiAbstractController
{
private $apiObj;

function __construct(Request $request)
{
//die('1'); //test connection
parent::__construct();

$this->apiObj = new SMSGlobal($request);
}

private function error_return($msg, $code=500)
{
return response()
->json(['error'=> $msg], $code)
->withHeaders([
'Content-Type'=>'application/json',
]);
}

///////////////////////////////////////////////////////////////// PUBLIC Methods below

public function get()
{
#/ Check for initial errors from api
if(!empty($this->apiObj->errorMsg))
return $this->error_return($this->apiObj->errorMsg, 403);

#/ pull messages from api
$messages_list = $this->apiObj->get_messages();
var_dump($messages_list); exit;
}

public function post()
{
#/ Check for initial errors from api
if(!empty($this->apiObj->errorMsg))
return $this->error_return($this->apiObj->errorMsg, 403);

#/ send message
$this->apiObj->post_message($this->POST);

#/ check for error
if(!empty($this->apiObj->errorMsg))
return $this->error_return($this->apiObj->errorMsg);


#/ return success
return response()
->json(['success'=> 'Your message has been dispatched successfully.'], 200)
->withHeaders([
'Content-Type'=>'application/json',
]);
}
}
?>
29 changes: 29 additions & 0 deletions app/Http/Controllers/api/ping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Controllers\api;

#/ Core
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class ping extends Controller
{
function __construct(Request $request)
{
//die('1'); //test connection
parent::__construct();
}

///////////////////////////////////////////////////////////////// PUBLIC Methods below

public function pong()
{
return response()
->json(['ping'=>'pong'], 200)
->withHeaders([
'Content-Type'=>'application/json',
]);
}
}
?>
19 changes: 19 additions & 0 deletions app/Http/Controllers/apiAbstractController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

/**
* @OA\Info(
* title="SMSGlobal Intgration Testing via API",
* version="1.0.0",
* )
*/

abstract class apiAbstractController extends Controller {

function __construct()
{
parent::__construct();
}
}
Loading

0 comments on commit 6eb3418

Please sign in to comment.