Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  chg: fix refresh token issue
  chg: improve how to handle different errors keys
  chg: support error and errors log
  new: handle multiple errors from moltin when authenticating
  chg: remove duplicated method result of a conflict when merging
  Adds test for encrypted field type
  Adds encrypted field type to Flows
  Enable JSON_BIGINT_AS_STRING on json_decode
  CS Fixes
  Added CHANGELOG
  Dropped 5.3 support and introduced CS

Conflicts:
	src/Facade/Address.php
	src/SDK.php
  • Loading branch information
Jmz committed May 17, 2016
2 parents afae152 + 1222604 commit 4a2c352
Show file tree
Hide file tree
Showing 49 changed files with 1,675 additions and 1,565 deletions.
48 changes: 48 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__ . '/src')->in(__DIR__ . '/tests')
;

return Symfony\CS\Config\Config::create()
->finder($finder)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers([
'blankline_after_open_tag',
'double_arrow_multiline_whitespaces',
'duplicate_semicolon',
'empty_return',
'extra_empty_lines',
'function_typehint_space',
'include',
'join_function',
'list_commas',
'multiline_array_trailing_comma',
'namespace_no_leading_whitespace',
'new_with_braces',
'no_blank_lines_after_class_opening',
'object_operator',
'operators_spaces',
'remove_leading_slash_use',
'remove_lines_between_uses',
'return',
'self_accessor',
'single_array_no_trailing_comma',
'single_blank_line_before_namespace',
'spaces_before_semicolon',
'spaces_cast',
'standardize_not_equal',
'ternary_spaces',
'trim_array_spaces',
'unalign_double_arrow',
'unalign_equals',
'unused_use',
'whitespacy_lines',
'align_double_arrow',
'align_equals',
'concat_with_spaces',
'trailing_spaces',
'encoding',
'ordered_use',
'short_array_syntax',
]);
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
Expand Down
103 changes: 61 additions & 42 deletions src/Authenticate/ClientCredentials.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
<?php

/**
* This file is part of Moltin PHP-SDK, a PHP package which
* provides convinient and rapid access to the API.
*
* Copyright (c) 2013 Moltin Ltd.
* http://github.com/moltin/php-sdk
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package moltin/php-sdk
* @author Jamie Holdroyd <[email protected]>
* @copyright 2013 Moltin Ltd.
* @version dev
* @link http://github.com/moltin/php-sdk
*
*/

* This file is part of Moltin PHP-SDK, a PHP package which
* provides convinient and rapid access to the API.
*
* Copyright (c) 2013 Moltin Ltd.
* http://github.com/moltin/php-sdk
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Jamie Holdroyd <[email protected]>
* @copyright 2013 Moltin Ltd.
*
* @version dev
*
* @link http://github.com/moltin/php-sdk
*/
namespace Moltin\SDK\Authenticate;

use Moltin\SDK\Exception\InvalidResponseException as InvalidResponse;
use Moltin\SDK\Exception\InvalidAuthenticationRequestException as InvalidAuthRequest;
use Moltin\SDK\Exception\InvalidResponseException;
use Moltin\SDK\Exception\InvalidAuthenticationRequestException;

class ClientCredentials implements \Moltin\SDK\AuthenticateInterface
{
protected $data = array(
'token' => null,
protected $data = [
'token' => null,
'refresh' => null,
'expires' => null
);
'expires' => null,
];

public function authenticate($args, \Moltin\SDK\SDK $parent)
{
// Validate
if ( ( $valid = $this->validate($args) ) !== true ) {
throw new InvalidAuthRequest('Missing required params: '.implode(', ', $valid));
if (($valid = $this->validate($args)) !== true) {
throw new InvalidAuthenticationRequestException('Missing required params: '.implode(', ', $valid));
}

// Variables
$url = $parent->url . 'oauth/access_token';
$data = array(
'grant_type' => 'client_credentials',
'client_id' => $args['client_id'],
'client_secret' => $args['client_secret']
);
$url = $parent->url.'oauth/access_token';
$data = [
'grant_type' => 'client_credentials',
'client_id' => $args['client_id'],
'client_secret' => $args['client_secret'],
];

// Make request
$parent->request->setup($url, 'POST', $data);
Expand All @@ -53,13 +52,31 @@ public function authenticate($args, \Moltin\SDK\SDK $parent)
// Check response
$result = json_decode($result, true);

// Check JSON for error
if (isset($result['error'])) {
throw new InvalidResponse($result['error']);
// Fix backward compatibility with new services
if (!isset($result['errors']) && isset($result['error'])) {
$result['errors'] = $result['error'];
unset($result['error']);
}

// Check JSON for errors
if (isset($result['errors'])) {
$exception = null;
if (is_array($result['errors'])) {
foreach($result['errors'] as $k => $v) {
if (isset($exception)) {
$exception = new InvalidResponseException($v[0], 0, $exception);
} else {
$exception = new InvalidResponseException($v[0]);
}
}
} else {
$exception = $result['errors'];
}
throw new InvalidResponseException($exception);
}

// Set data
$this->data['token'] = $result['access_token'];
$this->data['token'] = $result['access_token'];
$this->data['refresh'] = null;
$this->data['expires'] = $result['expires'];
}
Expand All @@ -71,7 +88,7 @@ public function refresh($args, \Moltin\SDK\SDK $parent)

public function get($key)
{
if ( ! isset($this->data[$key])) {
if (!isset($this->data[$key])) {
return;
}

Expand All @@ -81,16 +98,18 @@ public function get($key)
protected function validate($args)
{
// Variables
$required = array('client_id', 'client_secret');
$keys = array_keys($args);
$diff = array_diff($required, $keys);
$required = ['client_id', 'client_secret'];
$keys = array_keys($args);
$diff = array_diff($required, $keys);

// Check for empty values
foreach ( $required as $key => $value ) {
if ( strlen($value) <= 0 ) $diff[] = $key;
foreach ($required as $key => $value) {
if (strlen($value) <= 0) {
$diff[] = $key;
}
}

// Perform check
return ( empty($diff) ? true : $diff );
return (empty($diff) ? true : $diff);
}
}
79 changes: 48 additions & 31 deletions src/Authenticate/Implicit.php
Original file line number Diff line number Diff line change
@@ -1,64 +1,81 @@
<?php

/**
* This file is part of Moltin PHP-SDK, a PHP package which
* provides convinient and rapid access to the API.
*
* Copyright (c) 2013 Moltin Ltd.
* http://github.com/moltin/php-sdk
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package moltin/php-sdk
* @author Jamie Holdroyd <[email protected]>
* @copyright 2013 Moltin Ltd.
* @version dev
* @link http://github.com/moltin/php-sdk
*
*/

* This file is part of Moltin PHP-SDK, a PHP package which
* provides convinient and rapid access to the API.
*
* Copyright (c) 2013 Moltin Ltd.
* http://github.com/moltin/php-sdk
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Jamie Holdroyd <[email protected]>
* @copyright 2013 Moltin Ltd.
*
* @version dev
*
* @link http://github.com/moltin/php-sdk
*/
namespace Moltin\SDK\Authenticate;

use Moltin\SDK\Exception\InvalidResponseException as InvalidResponse;
use Moltin\SDK\Exception\InvalidResponseException;

class Implicit implements \Moltin\SDK\AuthenticateInterface
{
protected $data = array(
'token' => null,
protected $data = [
'token' => null,
'refresh' => null,
'expires' => null
);
'expires' => null,
];

public function authenticate($args, \Moltin\SDK\SDK $parent)
{
// Variables
$url = $parent->url . 'oauth/access_token';
$data = array(
$url = $parent->url.'oauth/access_token';
$data = [
'grant_type' => 'implicit',
'client_id' => $args['client_id']
);
'client_id' => $args['client_id'],
];

$parent->request->setup($url, 'POST', $data);
$result = $parent->request->make();

// Check response
$result = json_decode($result, true);

// Check JSON for error
if (isset($result['error'])) {
throw new InvalidResponse($result['error']);
// Fix backward compatibility with new services
if (!isset($result['errors']) && isset($result['error'])) {
$result['errors'] = $result['error'];
unset($result['error']);
}

// Check JSON for errors
if (isset($result['errors'])) {
$exception = null;
if (is_array($result['errors'])) {
foreach($result['errors'] as $k => $v) {
if (isset($exception)) {
$exception = new InvalidResponseException($v[0], 0, $exception);
} else {
$exception = new InvalidResponseException($v[0]);
}
}
} else {
$exception = $result['errors'];
}
throw new InvalidResponseException($exception);
}

// Set data
$this->data['token'] = $result['access_token'];
$this->data['token'] = $result['access_token'];
$this->data['refresh'] = $result['refresh_token'];
$this->data['expires'] = $result['expires'];
}

public function get($key)
{
if ( ! isset($this->data[$key])) {
if (!isset($this->data[$key])) {
return;
}

Expand Down
Loading

0 comments on commit 4a2c352

Please sign in to comment.