From 16d4efb7800f27df28c5ff863388e2851f726181 Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Sun, 8 Mar 2015 15:21:44 -0300 Subject: [PATCH] implements Extra::userinfo() --- README.md | 8 +++++ src/BoletoSimples/Extra.php | 10 ++++++ src/BoletoSimples/Resources/BaseResource.php | 24 +++++++------- tests/BoletoSimples/ExtraTest.php | 21 ++++++++++++ tests/fixtures/extra/userinfo | 34 ++++++++++++++++++++ 5 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/BoletoSimples/Extra.php create mode 100644 tests/BoletoSimples/ExtraTest.php create mode 100644 tests/fixtures/extra/userinfo diff --git a/README.md b/README.md index d1ca753..03f0088 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,14 @@ foreach($transactions as $transaction) { } ``` +### Extras + +```php +// Dados do usuário logado +$userinfo = BoletoSimples\Extra::userinfo(); +``` + + ## Desenvolvendo Instale as dependências diff --git a/src/BoletoSimples/Extra.php b/src/BoletoSimples/Extra.php new file mode 100644 index 0000000..613eb05 --- /dev/null +++ b/src/BoletoSimples/Extra.php @@ -0,0 +1,10 @@ +json(); + } +} \ No newline at end of file diff --git a/src/BoletoSimples/Resources/BaseResource.php b/src/BoletoSimples/Resources/BaseResource.php index 2e86fa2..55d7edc 100644 --- a/src/BoletoSimples/Resources/BaseResource.php +++ b/src/BoletoSimples/Resources/BaseResource.php @@ -114,7 +114,7 @@ public static function methodFor($action) { return $methods[$action]; } - public static function _find($id) { + private static function _find($id) { if (!$id) { throw new \Exception("Couldn't find ".get_called_class()." without an ID."); } @@ -124,14 +124,14 @@ public static function _find($id) { return $object; } - public static function _create($attributes = array()) { + private static function _create($attributes = array()) { $class = get_called_class(); $object = new $class($attributes); $object->save(); return $object; } - public static function _all($params = array()) { + private static function _all($params = array()) { $class = get_called_class(); $response = self::sendRequest('GET', $class::element_name_plural(), ['query' => $params]); $collection = []; @@ -141,15 +141,7 @@ public static function _all($params = array()) { return $collection; } - public static function element_name() { - return Util::underscorize(get_called_class()); - } - - public static function element_name_plural() { - return Util::pluralize(self::element_name()); - } - - public static function sendRequest($method, $path, $options = []) { + private static function _sendRequest($method, $path, $options = []) { $options = array_merge(self::$default_options, $options); $request = self::$client->createRequest($method, $path, $options); $response = self::$client->send($request); @@ -160,6 +152,14 @@ public static function sendRequest($method, $path, $options = []) { return $response; } + public static function element_name() { + return Util::underscorize(get_called_class()); + } + + public static function element_name_plural() { + return Util::pluralize(self::element_name()); + } + public static function __callStatic($name, $arguments) { self::configure(); return call_user_func_array("self::_".$name, $arguments); diff --git a/tests/BoletoSimples/ExtraTest.php b/tests/BoletoSimples/ExtraTest.php new file mode 100644 index 0000000..c4835fa --- /dev/null +++ b/tests/BoletoSimples/ExtraTest.php @@ -0,0 +1,21 @@ + 'sandbox']); + } + + /** + * @vcr extra/userinfo + * ATENÇÃO: Após apagar a fixture extra/userinfo e rodar o teste denovo, + * edite o arquivo e remova o token do login_url por questão de segurança. + */ + public function testUserinfo() { + $this->subject = BoletoSimples\Extra::userinfo(); + $this->assertEquals(array_keys($this->subject), ["id","login_url","email","account_type","first_name","middle_name","last_name","full_name","cpf","date_of_birth","mother_name","father_name","account_level","phone_number","address_street_name","address_number","address_complement","address_neighborhood","address_postal_code","address_city_name","address_state","business_name","business_cnpj","business_legal_name"]); + } +} \ No newline at end of file diff --git a/tests/fixtures/extra/userinfo b/tests/fixtures/extra/userinfo new file mode 100644 index 0000000..6df79ac --- /dev/null +++ b/tests/fixtures/extra/userinfo @@ -0,0 +1,34 @@ + +- + request: + method: GET + url: 'https://sandbox.boletosimples.com.br/api/v1/userinfo' + headers: + Host: sandbox.boletosimples.com.br + Accept-Encoding: null + Content-Type: application/json + User-Agent: 'BoletoSimples PHP Client v0.0.2 (contato@boletosimples.com.br)' + Authorization: 'Bearer BOLETOSIMPLES_ACCESS_TOKEN' + Accept: null + response: + status: + http_version: '1.1' + code: '200' + message: OK + headers: + Server: Cowboy + Connection: keep-alive + Strict-Transport-Security: max-age=2592000 + Content-Type: 'application/json; charset=utf-8' + X-Ratelimit-Limit: '500' + X-Ratelimit-Remaining: '496' + Etag: 'W/"2d2f54e118a16fc72383e7533ebcfeb1"' + Cache-Control: 'must-revalidate, private, max-age=0' + X-Request-Id: f3a2b980-ba43-4b51-a61f-81b5f5159c29 + X-Runtime: '0.072303' + Date: 'Sun, 08 Mar 2015 18:14:55 GMT' + X-Rack-Cache: miss + Vary: Accept-Encoding + Transfer-Encoding: chunked + Via: '1.1 vegur' + body: '{"id":53,"login_url":"https://sandbox.boletosimples.com.br/welcome?email=user1%40example.com\u0026token=xxx","email":"user1@example.com","account_type":null,"first_name":null,"middle_name":null,"last_name":null,"full_name":null,"cpf":null,"date_of_birth":null,"mother_name":null,"father_name":null,"account_level":2,"phone_number":null,"address_street_name":null,"address_number":null,"address_complement":null,"address_neighborhood":null,"address_postal_code":null,"address_city_name":null,"address_state":null,"business_name":null,"business_cnpj":null,"business_legal_name":null}'