Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
MP-Tsel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dzulfiqar Ridha
MP-Tsel
Commits
05b7b8a1
Commit
05b7b8a1
authored
Apr 04, 2019
by
Dzulfqar Ridha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated
parent
49789b61
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
8 deletions
+103
-8
MasheryController.php
app/Http/Controllers/MasheryController.php
+95
-4
MasheryGetUserController.php
app/Http/Controllers/MasheryGetUserController.php
+1
-2
web.php
routes/web.php
+7
-2
No files found.
app/Http/Controllers/MasheryController.php
View file @
05b7b8a1
...
@@ -7,13 +7,14 @@
...
@@ -7,13 +7,14 @@
*/
*/
namespace
App\Http\Controllers
;
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
use
App\Classes\MResponse
;
use
App\Classes\MResponse
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Client
;
class
MasheryController
extends
Controller
class
MasheryController
extends
Controller
{
{
public
function
getToken
()
public
function
getToken
()
{
{
$mResponse
=
new
MResponse
();
$mResponse
=
new
MResponse
();
...
@@ -21,16 +22,15 @@ class MasheryController extends Controller
...
@@ -21,16 +22,15 @@ class MasheryController extends Controller
try
{
try
{
$client
=
new
Client
([
$client
=
new
Client
([
'base_uri'
=>
'https://api.mashery.com/'
,
'base_uri'
=>
'https://api.mashery.com/
v3/
'
,
'auth'
=>
[
'y4a5rz5ccv374qu33558f65b'
,
'yuZRnvKvYY'
],
'auth'
=>
[
'y4a5rz5ccv374qu33558f65b'
,
'yuZRnvKvYY'
],
'headers'
=>
[
'headers'
=>
[
'Authorization'
=>
'Basic eTRhNXJ6NWNjdjM3NHF1MzM1NThmNjViOnl1WlJudkt2WVk='
,
'Authorization'
=>
'Basic eTRhNXJ6NWNjdjM3NHF1MzM1NThmNjViOnl1WlJudkt2WVk='
,
'Content-Type'
=>
'application/x-www-form-urlencoded'
],
],
'http_errors'
=>
true
'http_errors'
=>
true
]);
]);
$response
=
$client
->
request
(
'POST'
,
'
https://api.mashery.com/v3/
token'
,
[
$response
=
$client
->
request
(
'POST'
,
'token'
,
[
'form_params'
=>
[
'form_params'
=>
[
'grant_type'
=>
'password'
,
'grant_type'
=>
'password'
,
'username'
=>
'marketplace.dev'
,
'username'
=>
'marketplace.dev'
,
...
@@ -49,6 +49,97 @@ class MasheryController extends Controller
...
@@ -49,6 +49,97 @@ class MasheryController extends Controller
$mResponse
->
message
=
'success'
;
$mResponse
->
message
=
'success'
;
$mResponse
->
data
=
$resBody
;
$mResponse
->
data
=
$resBody
;
}
}
}
catch
(
\Exception
$e
)
{
$statusCode
=
500
;
$mResponse
->
message
=
$e
->
getMessage
();
}
$this
->
token
=
$resBody
[
'access_token'
];
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
)
{
}
catch
(
\Exception
$e
)
{
$statusCode
=
500
;
$statusCode
=
500
;
$mResponse
->
message
=
$e
->
getMessage
();
$mResponse
->
message
=
$e
->
getMessage
();
...
...
app/Http/Controllers/MasheryGetUserController.php
View file @
05b7b8a1
...
@@ -14,8 +14,7 @@ Class MasheryGetUserController extends controller
...
@@ -14,8 +14,7 @@ Class MasheryGetUserController extends controller
public
function
__construct
()
public
function
__construct
()
{
{
$apiClient
=
new
MasheryAPIClient
(
'y4a5rz5ccv374qu33558f65b'
,
'yuZRnvKvYY'
);
$this
->
token
=
$apiClient
->
prepareAccessToken
();
}
}
public
function
getUser
()
public
function
getUser
()
...
...
routes/web.php
View file @
05b7b8a1
...
@@ -15,10 +15,15 @@ $router->get('/', function () use ($router) {
...
@@ -15,10 +15,15 @@ $router->get('/', function () use ($router) {
return
$router
->
app
->
version
();
return
$router
->
app
->
version
();
});
});
$router
->
get
(
'/token'
,
'MasheryGetTokenController@getToken'
);
$router
->
get
(
'/getUser'
,
'MasheryGetUserController@getUser'
);
$router
->
get
(
'/getUser'
,
'MasheryGetUserController@getUser'
);
$router
->
group
([
'prefix'
=>
'mashery'
],
function
()
use
(
$router
)
{
$router
->
group
([
'prefix'
=>
'mashery'
],
function
()
use
(
$router
)
{
//mashery/token
$router
->
get
(
'token'
,
'MasheryController@getToken'
);
$router
->
get
(
'token'
,
'MasheryController@getToken'
);
//mashery/getUser?token={token}&username={mashery_username}
$router
->
get
(
'getUser'
,
'MasheryController@getUser'
);
//mashery/createUser?token={}&username={}&email={}&dname={}&pass={}
$router
->
get
(
'createUser'
,
'MasheryController@createUser'
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment