Commit 644eeaf7 authored by Dzulfqar Ridha's avatar Dzulfqar Ridha

update application controller

parent efc9e391
......@@ -9,36 +9,23 @@
namespace App\Http\Controllers;
use App\Classes\MResponse;
use App\Http\Request\Application\CreateDefaultApplicationRequest;
use App\Http\Request\Application\CreateRequest;
use App\Http\Request\Application\UpdateRequest;
class ApplicationController extends BaseController
{
public function createDefault(CreateDefaultApplicationRequest $request)
public function create(CreateRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userid') . '/applications';
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userId') . '/applications';
try {
$response = $this->masheryClient()->request('POST', $url, [
'json' => [
'name' => $request->get('marketplace-name') . '-DefaultApp',
'username' => $request->get('username'),
'description' => '',
'type' => '',
'commercial' => false,
'ads' => false,
'adsSystem' => '',
'usageModel' => '',
'tags' => '',
'notes' => '',
'howDidYouHear' => '',
'preferredProtocol' => '',
'preferredOutput' => '',
'externalId' => '',
'uri' => '',
'oauthRedirectUri' => ''
'name' => 'WebApp',
'username' => $request->get('username')
]
]);
......@@ -60,32 +47,18 @@ class ApplicationController extends BaseController
return response()->json($mResponse, $statusCode);
}
public function createApp(CreateDefaultApplicationRequest $request)
public function update(UpdateRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userid') . '/applications';
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userId') . '/applications/' . $request->get('appId');
try {
$response = $this->masheryClient()->request('POST', $url, [
$response = $this->masheryClient()->request('PUT', $url, [
'json' => [
'name' => $request->get('marketplace-name') . '-WebApp',
'username' => $request->get('username'),
'description' => '',
'type' => '',
'commercial' => false,
'ads' => false,
'adsSystem' => '',
'usageModel' => '',
'tags' => '',
'notes' => '',
'howDidYouHear' => '',
'preferredProtocol' => '',
'preferredOutput' => '',
'externalId' => '',
'uri' => '',
'oauthRedirectUri' => ''
'name' => 'UpdateApp',
'description' => 'Update'
]
]);
......@@ -106,4 +79,88 @@ class ApplicationController extends BaseController
return response()->json($mResponse, $statusCode);
}
public function delete(DeleteRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userId') . '/applications/' . $request->get('appId');
try {
$response = $this->masheryClient()->request('DEL', $url);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function getByUserID(GetByUserIdRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userId') . '/applications';
try {
$response = $this->masheryClient()->request('GET', $url);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function getByAppId(GetByAppId $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userId') . '/applications/' . $request->get('appId');
try {
$response = $this->masheryClient()->request('GET', $url);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:24 PM
*/
namespace App\Http\Controllers;
use App\Classes\MResponse;
use App\Http\Request\PackageKey\CreateRequest;
use App\Http\Request\PackageKey\ActivateRequest;
use App\Http\Request\PackageKey\DisableRequest;
use App\Http\Request\PackageKey\DeleteRequest;
use App\Http\Request\PackageKey\GetByUserRequest;
use App\Http\Request\PackageKey\UpdatePlanRequest;
class ApplicationController extends BaseController
{
public function create(CreateRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/applications/' . $request->get('appId') . '/packageKeys';
try {
$response = $this->masheryClient()->request('POST', $url, [
'json' => [
'apikey' => '',
'secret' => '',
'package' => [
'id' => $request->get('pkgId')
],
'plan' => [
'id' => $request->get('planId')
]
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function activate(ActivateRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/packageKeys/' . $request->get('pkgKeyId');
try {
$response = $this->masheryClient()->request('PUT', $url, [
'json' => [
'status' => 'active'
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function disable(DisableRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/packageKeys/' . $request->get('pkgKeyId');
try {
$response = $this->masheryClient()->request('PUT', $url, [
'json' => [
'status' => 'disabled'
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function delete(DeleteRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/applications/' . $request->get('appId') .'/packageKeys/' . $request->get('pkgKeyId');
try {
$response = $this->masheryClient()->request('DEL', $url);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function getByUser(GetByUserRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/members/' . $request->get('userId') . '/packageKeys';
try {
$response = $this->masheryClient()->request('GET', $url, [
'query' => [
'fields' => 'id,apikey,secret,status,application.id,application.name,application.username,package.id,package.name,plan.id,plan.name'
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
public function updatePlan(UpdatePlanRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$url = 'https://api.mashery.com/v3/rest/applications/' . $request->get('appId') . '/packageKeys/' . $request->get('pkgKeyId');
try {
$response = $this->masheryClient()->request('PUT', $url, [
'json' => [
'plan' => [
'id' => $request->get('planId')
]
]
]);
$resBody = json_decode($response->getBody()->getContents(), true);
if ($response->getStatusCode() != 200) {
$statusCode = $response->getStatusCode();
$mResponse->message = $resBody;
} else {
$mResponse->success = true;
$mResponse->message = 'success';
$mResponse->data = $resBody;
}
} catch (\Exception $e) {
$statusCode = 500;
$mResponse->message = $e->getMessage();
}
return response()->json($mResponse, $statusCode);
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class CreateRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'userId' => 'required',
'username' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class DeleteRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'userId' => 'required',
'appId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class GetByAppIdRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'userId' => 'required',
'appId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
......@@ -8,7 +8,7 @@
namespace App\Http\Request;
class CreateDefaultApplicationRequest extends FormRequestErrors
class GetByUserId extends FormRequestErrors
{
protected function validationData()
{
......@@ -23,7 +23,7 @@ class CreateDefaultApplicationRequest extends FormRequestErrors
public function rules()
{
return [
'userid' => 'required'
'userId' => 'required'
];
}
......
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class UpdateRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'userId' => 'required',
'appId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class ActivateRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'pkgKeyId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class CreateRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'appId' => 'required',
'pkgId' => 'required',
'planId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class DeleteRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'appId' => 'required',
'pkgKeyId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class DisableRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'pkgKeyId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class GetByUserRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'userId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 3:45 PM
*/
namespace App\Http\Request;
class UpdatePlanRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'appId' => 'required',
'pkgKeyId' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
......@@ -23,25 +23,31 @@ $router->group(['prefix' => 'mashery'], function () use ($router) {
$router->group(['middleware' => 'client.auth'], function () use ($router) {
$router->group(['prefix' => 'user'], function () use ($router) {
$router->get('by-username', 'UserController@getByUsername');
$router->get('by-id', 'UserController@getById');
$router->get('update', 'UserController@updateUser');
$router->post('create', 'UserController@createUser');
});
$router->group(['prefix' => 'application'], function () use ($router) {
$router->post('create-default', 'ApplicationController@createDefault');
$router->post('create', 'ApplicationController@createApp');
$router->post('create', 'ApplicationController@create');
$router->post('update', 'ApplicationController@update');
$router->post('delete', 'ApplicationController@delete');
$router->post('by-userid', 'ApplicationController@getByUserId');
$router->post('by-appid', 'ApplicationController@getByAppId');
});
$router->group(['prefix' => 'package'], function () use ($router) {
$router->get('package', 'PackagePlanController@getPackage');
$router->get('plan', 'PackagePlanController@getPlan');
$router->get('package-plan', 'PackagePlanController@getPackagePlan');
});
$router->group(['prefix' => 'packageKey'], function () use ($router) {
$router->post('create', 'PackageKeyController@create');
$router->post('activate', 'PackageKeyController@activate');
$router->post('disable', 'PackageKeyController@disable');
$router->post('delete', 'PackageKeyController@delete');
$router->post('by-username', 'PackageKeyController@getByUser');
$router->post('update-plan', 'PackageKeyController@updatePlan');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment