Commit c0e0b669 authored by Dzulfqar Ridha's avatar Dzulfqar Ridha

update new postman collection

parent 56e5681a
<?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\CreateDefaultApplicationRequest;
class ApplicationController extends BaseController
{
public function createDefault(CreateDefaultApplicationRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$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' => ''
]
]);
$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 createApp(CreateDefaultApplicationRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
$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') . '-WebApp',
'username' => $request->get('username'),
'description' => '',
'type' => '',
'commercial' => false,
'ads' => false,
'adsSystem' => '',
'usageModel' => '',
'tags' => '',
'notes' => '',
'howDidYouHear' => '',
'preferredProtocol' => '',
'preferredOutput' => '',
'externalId' => '',
'uri' => '',
'oauthRedirectUri' => ''
]
]);
$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
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController
{
//
}
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}
<?php
namespace App\Http\Controllers;
use GuzzleHttp\Client;
use Closure;
Class MasheryAPIClient extends Controller
{
private $client = null;
public $API_URL = 'https://api.mashery.com/v3/';
private $auth_key;
private $auth_secret;
public $accessToken;
public function __construct($key, $secret)
{
$this->auth_key = $key;
$this->auth_secret = $secret;
$this->client = new Client([
'base_uri' => $this->API_URL,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => 'Basic eTRhNXJ6NWNjdjM3NHF1MzM1NThmNjViOnl1WlJudkt2WVk='
],
'auth' => [$this->auth_key, $this->auth_secret],
]);
}
public function prepareAccessToken()
{
$url = 'token';
$body = [
'grant_type' => 'password',
'username' => 'marketplace.dev',
'password' => 'Marketplace123',
'scope' => '71338066-f062-4feb-84b7-6547f0dc4e82'
];
$response = $this->client->request('POST', $url, [
'body' => json_encode($body)
]);
$result = json_decode($response->getBody()->getContents());
$this->accessToken = $result->access_token;
return $this->accessToken;
}
}
\ No newline at end of file
......@@ -72,92 +72,4 @@ class MasheryController extends Controller
return response()->json($mResponse, $statusCode);
}
public function getUser(Request $request)
{
$token = $request->get('token');
$mashUsername = $request->get('username');
$mResponse = new MResponse();
$statusCode = 200;
try {
$client = new Client([
'base_uri' => 'https://api.mashery.com/v3/',
'headers' => [
'Authorization' => 'Bearer ' . $token,
],
'http_errors' => true
]);
$response = $client->request('GET', 'rest/members?filter=username:' . $mashUsername);
$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 createUser(Request $request)
{
$token = $request->get('token');
$username = $request->get('username');
$email = $request->get('email');
$dname = $request->get('dname');
$pass = $request->get('pass');
$mResponse = new MResponse();
$statusCode = 200;
try {
$client = new Client([
'base_uri' => 'https://api.mashery.com/v3/',
'headers' => [
'Authorization' => 'Bearer ' . $token,
],
'http_errors' => false
]);
$response = $client->request('POST', 'rest/members', [
'json' => [
'username' => $username,
'email' => $email,
'displayName' => $dname,
'areaStatus' => 'active',
'externalId' => '',
'passwdNew' => $pass
]
]);
$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
namespace App\Http\Controllers;
require vendor/autoload.php;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
class MasheryGetTokenController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
public function getToken(){
$api_key = 'y4a5rz5ccv374qu33558f65b';
$api_secret = 'yuZRnvKvYY';
$cw_api = new MasheryAPIClient($api_key,$api_secret);
$token = $cw_api->prepare_access_token();
var_dump($token);
}
}
<?php
namespace App\Http\Controllers;
use GuzzleHttp\Client;
use App\Http\Controllers\MasheryAPIClient;
use Closure;
Class MasheryGetUserController extends controller
{
private $client = null;
private $name = 'marketplace.dev';
private $token = null;
public function __construct()
{
}
public function getUser()
{
$url = 'rest/members?filter=username:' . $this->name;
$this->client = new Client([
'base_uri' => $this->API_URL,
'headers' => [
'Authorization' => 'Bearer ' . $this->token,
'Content-Type' => 'application/json',
]
]);
$response = $this->client->request('GET', $url);
$result = json_decode($response->getBody()->getContents());
return response()->json($result);
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ namespace App\Http\Controllers;
use App\Classes\MResponse;
use App\Http\Request\UserByUsernameRequest;
use App\Http\Request\CreateUserRequest;
class UserController extends BaseController
{
......@@ -42,4 +43,39 @@ class UserController extends BaseController
return response()->json($mResponse, $statusCode);
}
public function createUser(CreateUserRequest $request)
{
$mResponse = new MResponse();
$statusCode = 200;
try {
$response = $this->masheryClient()->request('POST', 'https://api.mashery.com/v3/rest/members', [
'json' => [
'username' => $request->get('username'),
'email' => $request->get('email'),
'displayName' => $request->get('name'),
'areaStatus' => 'active',
'externalId' => '',
'passwdNew' => $request->get('password')
]
]);
$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 CreateDefaultApplicationRequest 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 CreateUserRequest extends FormRequestErrors
{
protected function validationData()
{
return $this->all();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'username' => 'required',
'email' => 'required',
'name' => 'required',
'password' => 'required'
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [];
}
protected function modifyData()
{
$data = $this->validationData();
return $data;
}
}
......@@ -1759,16 +1759,16 @@
},
{
"name": "nesbot/carbon",
"version": "2.16.2",
"version": "2.16.3",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "720a9c36927396efeeb48a972e9d129d44b6dc28"
"reference": "373d9f0d58651af366435148c39beb702c2b7ef4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/720a9c36927396efeeb48a972e9d129d44b6dc28",
"reference": "720a9c36927396efeeb48a972e9d129d44b6dc28",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/373d9f0d58651af366435148c39beb702c2b7ef4",
"reference": "373d9f0d58651af366435148c39beb702c2b7ef4",
"shasum": ""
},
"require": {
......@@ -1815,7 +1815,7 @@
"datetime",
"time"
],
"time": "2019-03-29T12:23:12+00:00"
"time": "2019-04-06T17:09:23+00:00"
},
{
"name": "nikic/fast-route",
......@@ -4619,16 +4619,16 @@
},
{
"name": "theseer/tokenizer",
"version": "1.1.1",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/theseer/tokenizer.git",
"reference": "06b6ce404ee574e9c1787fb67bb9980ca4387c34"
"reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/06b6ce404ee574e9c1787fb67bb9980ca4387c34",
"reference": "06b6ce404ee574e9c1787fb67bb9980ca4387c34",
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/1c42705be2b6c1de5904f8afacef5895cab44bf8",
"reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8",
"shasum": ""
},
"require": {
......@@ -4655,7 +4655,7 @@
}
],
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"time": "2019-04-03T18:37:40+00:00"
"time": "2019-04-04T09:56:43+00:00"
},
{
"name": "webmozart/assert",
......
......@@ -31,5 +31,13 @@ $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->post('create', 'UserController@createUser');
});
$router->group(['prefix' => 'application'], function () use ($router) {
$router->post('create-default', 'ApplicationController@createDefault');
$router->post('create', 'ApplicationController@createApp');
});
});
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