This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Keys): adds method to get public key from moip account
- Loading branch information
1 parent
d547d8a
commit fc2143a
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Moip\Resource; | ||
|
||
use Requests; | ||
use stdClass; | ||
|
||
/** | ||
* Class Keys. | ||
*/ | ||
class Keys extends MoipResource | ||
{ | ||
/** | ||
* @const string | ||
*/ | ||
const PATH = 'keys'; | ||
|
||
/** | ||
* Initializes new instances. | ||
*/ | ||
public function initialize() | ||
{ | ||
$this->data = new stdClass(); | ||
} | ||
|
||
/** | ||
* Mount keys structure. | ||
* | ||
* @param \stdClass $response | ||
* | ||
* @return $this | ||
*/ | ||
protected function populate(stdClass $response) | ||
{ | ||
$keys = clone $this; | ||
|
||
$resp = $response->keys; | ||
$keys->data->basicAuth = $this->getIfSet('basicAuth', $resp); | ||
$keys->data->encryption = $this->getIfSet('encryption', $resp); | ||
|
||
return $keys; | ||
} | ||
|
||
/** | ||
* Get encryption. | ||
* | ||
* @return string | ||
*/ | ||
public function getEncryption() | ||
{ | ||
return $this->getIfSet('encryption'); | ||
} | ||
|
||
/** | ||
* Get Basic Auth. | ||
* | ||
* @return stdClass | ||
*/ | ||
public function getBasicAuth() | ||
{ | ||
return $this->getIfSet('basicAuth'); | ||
} | ||
|
||
/** | ||
* Get keys. | ||
* | ||
* @return stdClass | ||
*/ | ||
public function get() | ||
{ | ||
return $this->getByPath(sprintf('/%s/%s', MoipResource::VERSION, self::PATH)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Moip\Tests\Resource; | ||
|
||
use Moip\Tests\TestCase; | ||
|
||
class KeyTest extends TestCase | ||
{ | ||
public function testGetKey() | ||
{ | ||
$this->mockHttpSession($this->body_keys); | ||
|
||
$keys = $this->moip->keys()->get(); | ||
|
||
$this->assertNotNull($keys->getBasicAuth()->token); | ||
$this->assertNotNull($keys->getBasicAuth()->secret); | ||
$this->assertNotNull($keys->getEncryption()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"keys":{"basicAuth":{"secret":"ABABABABABABABABABABABABABABABABABABABAB","token":"01010101010101010101010101010101"},"encryption":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoBttaXwRoI1Fbcond5mS\n7QOb7X2lykY5hvvDeLJelvFhpeLnS4YDwkrnziM3W00UNH1yiSDU+3JhfHu5G387\nO6uN9rIHXvL+TRzkVfa5iIjG+ap2N0\/toPzy5ekpgxBicjtyPHEgoU6dRzdszEF4\nItimGk5ACx\/lMOvctncS5j3uWBaTPwyn0hshmtDwClf6dEZgQvm\/dNaIkxHKV+9j\nMn3ZfK\/liT8A3xwaVvRzzuxf09xJTXrAd9v5VQbeWGxwFcW05oJulSFjmJA9Hcmb\nDYHJT+sG2mlZDEruCGAzCVubJwGY1aRlcs9AQc1jIm\/l8JwH7le2kpk3QoX+gz0w\nWwIDAQAB\n-----END PUBLIC KEY-----\n"}} |