Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
[WEB-9960] Added getMe method to get user profile data.
Browse files Browse the repository at this point in the history
  • Loading branch information
sameeraroshan-serato committed Apr 11, 2024
1 parent 559647d commit 7e1db8b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Profile/Command/GetMe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Serato\SwsSdk\Profile\Command;

use Serato\SwsSdk\CommandBasicAuth;

/**
* Gets user information for the authenticated user.
*
* User is identified by the bearer token
*
* This command can be executed on a `Serato\SwsSdk\Profile\ProfileClient` instance
* using the `ProfileClient::getMe` magic method.
*/
class GetMe extends CommandBasicAuth
{
/**
* {@inheritdoc}
*/
public function getHttpMethod(): string
{
return 'GET';
}

/**
* {@inheritdoc}
*/
public function getUriPath(): string
{
return '/api/v1/me/';
}

/**
* {@inheritdoc}
*/
protected function getArgsDefinition(): array
{
return [];
}
}
3 changes: 3 additions & 0 deletions src/Profile/ProfileClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/**
* Client used to interact with SWS Profile service.
*
* @method \Serato\SwsSdk\Result getMe()
* @method \Serato\SwsSdk\Result getUser(array $args)
* @method \Serato\SwsSdk\Result updateUser(array $args)
* @method \Serato\SwsSdk\Result getUserBetaProgram(array $args)
Expand Down Expand Up @@ -39,6 +40,8 @@ public function getBaseUri(): string
public function getCommandMap(): array
{
return [
# GET /me
'GetMe' => '\\Serato\\SwsSdk\\Profile\\Command\\GetMe',
# GET /users/{user_id}
'GetUser' => '\\Serato\\SwsSdk\\Profile\\Command\\UserGet',
# PUT /users/{user_id}
Expand Down
11 changes: 11 additions & 0 deletions tests/Profile/ProfileClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function testGetBaseUri(): void

/* The remaining tests are smoke tests for each magic method provided by the client */

public function testGetMe(): void
{
$body = '{"var1":"val1"}';
$client = $this->getSdkWithMocked200Response($body)->createProfileClient();
$result = $client->getMe();
$this->assertEquals(
(string)$this->getResponseObjectFromResult($result)->getBody(),
$body
);
}

public function testGetUser(): void
{
$body = '{"var1":"val1"}';
Expand Down

0 comments on commit 7e1db8b

Please sign in to comment.