Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Tinify SDK #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"facebook/webdriver": "1.1.3",
"mikey179/vfsstream": "~1.5",
"mockery/mockery": "~0.9",
"phpdocumentor/reflection-docblock": "~2.0",
"symfony/yaml": "~2.8",
"squizlabs/php_codesniffer": "~2.2",
"tinify/tinify": "dev-create-key",
"wp-coding-standards/wpcs": "0.11"
Expand Down
118 changes: 72 additions & 46 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/vendor/tinify/Tinify.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tinify;

const VERSION = "1.5.2";
const VERSION = "1.6.2";

class Tinify {
const AUTHENTICATED = true;
Expand Down
14 changes: 12 additions & 2 deletions src/vendor/tinify/Tinify/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function __construct($key, $appIdentifier = NULL, $proxy = NULL) {
$userAgent = join(" ", array_filter(array(self::userAgent(), $appIdentifier)));

$this->options = array(
CURLOPT_BINARYTRANSFER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_USERPWD => $key ? ("api:" . $key) : NULL,
Expand Down Expand Up @@ -114,7 +113,7 @@ function request($method, $url, $body = NULL) {
$headers = self::parseHeaders(substr($response, 0, $headerSize));
$responseBody = substr($response, $headerSize);

if (isset($headers["compression-count"])) {
if ( isset($headers["compression-count"] ) ) {
Tinify::setCompressionCount(intval($headers["compression-count"]));
}

Expand All @@ -126,6 +125,17 @@ function request($method, $url, $body = NULL) {
Tinify::setPayingState( $headers["paying-state"] );
}

$details = json_decode($responseBody);
if (!$details) {
$message = sprintf("Error while parsing response: %s (#%d)",
PHP_VERSION_ID >= 50500 ? json_last_error_msg() : "Error",
json_last_error());
$details = (object) array(
"message" => $message,
"error" => "ParseError"
);
}

if ( isset( $headers["email-address"] ) ) {
Tinify::setEmailAddress( $headers["email-address"] );
}
Expand Down
8 changes: 8 additions & 0 deletions src/vendor/tinify/Tinify/ResultMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ public function height() {
public function location() {
return isset($this->meta["location"]) ? $this->meta["location"] : null;
}

public function extension() {
if (isset($this->meta["content-type"])) {
$parts = explode("/", $this->meta["content-type"]);
return end($parts);
}
return null;
}
}
10 changes: 10 additions & 0 deletions src/vendor/tinify/Tinify/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public function store($options) {
return new Result($response->headers, $response->body);
}

public function convert($options) {
$commands = array_merge($this->commands, array("convert" => $options));
return new self($this->url, $commands);
}

public function transform($options) {
$commands = array_merge($this->commands, array("transform" => $options));
return new self($this->url, $commands);
}

public function result() {
$response = Tinify::getClient()->request("get", $this->url, $this->commands);
return new Result($response->headers, $response->body);
Expand Down