Commit 7ec3f7a6 authored by Ghitha Dinan's avatar Ghitha Dinan

test request

parent f4ae20a3
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 1:15 PM
*/
namespace App\Classes;
class MResponse
{
public $success = false;
public $message = '';
public $data = [];
}
<?php
/**
* Created by PhpStorm.
* User: gets
* Date: 4/4/2019
* Time: 1:08 PM
*/
namespace App\Http\Controllers;
use App\Classes\MResponse;
use GuzzleHttp\Client;
class MasheryController extends Controller
{
public function getToken()
{
$mResponse = new MResponse();
$statusCode = 200;
try {
$client = new Client([
'base_uri' => 'https://api.mashery.com/',
'auth' => ['y4a5rz5ccv374qu33558f65b', 'yuZRnvKvYY'],
'headers' => [
'Authorization' => 'Basic eTRhNXJ6NWNjdjM3NHF1MzM1NThmNjViOnl1WlJudkt2WVk=',
'Content-Type' => 'application/x-www-form-urlencoded'
],
'http_errors' => true
]);
$response = $client->request('POST', 'https://api.mashery.com/v3/token', [
'form_params' => [
'grant_type' => 'password',
'username' => 'marketplace.dev',
'password' => 'Marketplace123',
'scope' => '71338066-f062-4feb-84b7-6547f0dc4e82'
]
]);
$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);
}
}
......@@ -17,4 +17,8 @@ $router->get('/', function () use ($router) {
$router->get('/token', 'MasheryGetTokenController@getToken');
$router->get('/getUser', 'MasheryGetUserController@getUser');
\ No newline at end of file
$router->get('/getUser', 'MasheryGetUserController@getUser');
$router->group(['prefix' => 'mashery'], function () use ($router) {
$router->get('token', 'MasheryController@getToken');
});
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