Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
feat(Keys): adds method to get public key from moip account
Browse files Browse the repository at this point in the history
  • Loading branch information
caiogaspar committed Oct 4, 2017
1 parent d547d8a commit fc2143a
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Moip.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Moip\Resource\Account;
use Moip\Resource\Customer;
use Moip\Resource\Entry;
use Moip\Resource\Keys;
use Moip\Resource\Multiorders;
use Moip\Resource\NotificationPreferences;
use Moip\Resource\Orders;
Expand Down Expand Up @@ -213,6 +214,16 @@ public function webhooks()
return new WebhookList($this);
}

/**
* Create a new Keys instance.
*
* @return Keys
*/
public function keys()
{
return new Keys($this);
}

/**
* Get the endpoint.
*
Expand Down
73 changes: 73 additions & 0 deletions src/Resource/Keys.php
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));
}
}
19 changes: 19 additions & 0 deletions tests/Resource/KeyTest.php
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());
}
}
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public function __construct()
$this->body_get_pay = $this->readJsonFile('jsons/payment/get');

$this->body_get_multipay = $this->readJsonFile('jsons/multipayment/get');

$this->body_keys = $this->readJsonFile('jsons/keys/get');
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/jsons/keys/get.json
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"}}

0 comments on commit fc2143a

Please sign in to comment.