Skip to content

Commit

Permalink
Merge pull request #26 from aplazame/refactor
Browse files Browse the repository at this point in the history
v2.0.0 Component refactor
  • Loading branch information
Maks3w authored Jul 26, 2016
2 parents 6d24f73 + 3f16fee commit d937faa
Show file tree
Hide file tree
Showing 46 changed files with 855 additions and 1,437 deletions.
3 changes: 2 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ branches:
- release

build:
image: php
image: composer/composer
commands:
- 'make syntax.checker'
# Build release
- 'make style.req style'
- 'apt-get update'
- 'apt-get -y install zip'
- 'make zip'
Expand Down
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

[**.php]
indent_size = 4
continuation_indent_size = 4
insert_final_newline = true

[**.xml]
indent_size = 4

[**.yml]
indent_size = 2

[*.{js,json}]
indent_size = 2

[composer.{json,lock}]
indent_size = 4

[Makefile]
indent_style = tab
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/vendor/
aplazame/config.xml
.php_cs.cache
composer.lock
docker-compose.override.yml
latest.zip
25 changes: 25 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->fixers(
array(
'-concat_without_spaces',
'-empty_return',
'-phpdoc_indent',
'-phpdoc_no_empty_return',
'-phpdoc_params',
'-phpdoc_to_comment',
'-psr0',
'-unneeded_control_parentheses',
'long_array_syntax',
'concat_with_spaces',
'ereg_to_preg',
'ordered_use',
)
)
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in('aplazame')
)
;
12 changes: 11 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## Change Log

#### [v2.0.0](https://github.com/aplazame/prestashop/tree/v2.0.0) (2016-07-26)

IMPORTANT: Credit slips are the way of issue refunds to Aplazame. For `partial
refunds` this is automatic, for `standard refunds` you must to check the option.

* Module refactor
* Added translations
* Simplify lot of logic
* Fix many reported issues

#### [v1.0.11](https://github.com/aplazame/prestashop/tree/v1.0.11) (2016-04-21)

* Update changelog entries in HISTORY.md
Expand All @@ -18,7 +28,7 @@

#### [v1.0.7](https://github.com/aplazame/prestashop/tree/v1.0.7) (2016-04-07)

[Full Changelog ](https://github.com/aplazame/prestashop/compare/v1.0.6...v1.0.7)
[Full Changelog v1.0.7](https://github.com/aplazame/prestashop/compare/v1.0.6...v1.0.7)

* Php < 5.3 compatibility, static methods.
* Product price context var.
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
errors = $(shell find . -type f -name "*.php" -exec php -l "{}" \;| grep "Errors parsing ";)
errors = $(shell find aplazame -type f -name "*.php" -exec php -l "{}" \;| grep "Errors parsing ";)
branch_name = $(shell git symbolic-ref --short HEAD)

test:
@php ./test/Aplazame.php

syntax.checker:
@if [ "$(errors)" ];then exit 2;fi

style.req:
@composer install --no-interaction --quiet --ignore-platform-reqs

style:
@vendor/bin/php-cs-fixer fix -v

zip:
@rm latest.zip
@zip -r latest.zip aplazame

push:
Expand Down
85 changes: 85 additions & 0 deletions aplazame/api/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

class Aplazame_Client
{
/**
* @var string
*/
private $apiBaseUri;

/**
* @var string
*/
private $accessToken;

/**
* @var bool
*/
private $sandbox;

public function __construct($apiBaseUri, $accessToken, $sandbox)
{
$this->apiBaseUri = $apiBaseUri;
$this->accessToken = $accessToken;
$this->sandbox = $sandbox;
}

public function callToRest($method, $path, array $values = null)
{
$url = $this->apiBaseUri . $path;
$headers = array(
'Authorization: Bearer ' . $this->accessToken,
'Accept: application/vnd.aplazame.' . ($this->sandbox ? 'sandbox.' : '') . 'v1+json',
);

$versions = array(
'PHP/' . PHP_VERSION,
'Prestashop/' . _PS_VERSION_,
'AplazamePrestashop/' . Aplazame::VERSION,
);
$headers[] = 'User-Agent: ' . implode(', ', $versions);

if ($values) {
$headers[] = 'Content-type: application/json';
$values = json_encode($values);
}

$result = $this->doCurlRequest($method, $url, $headers, $values);
$result['is_error'] = ($result['code'] >= 400);
$result['payload'] = json_decode($result['payload'], true);

return $result;
}

protected function doCurlRequest($method, $url, $headers, $values)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if ($values) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $values);
}

$responseBody = curl_exec($ch);

if (false === $responseBody) {
$message = curl_error($ch);
$code = curl_errno($ch);

curl_close($ch);

throw new RuntimeException($message, $code);
}

$result = array(
'payload' => $responseBody,
'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
);

curl_close($ch);

return $result;
}
}
Loading

0 comments on commit d937faa

Please sign in to comment.