Skip to content

Commit 978b57d

Browse files
Update Tinify SDK (tinify#44)
* Remove webdriver and yaml * Run update
1 parent 8676ee3 commit 978b57d

File tree

6 files changed

+103
-51
lines changed

6 files changed

+103
-51
lines changed

composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "~4.6",
21-
"facebook/webdriver": "1.1.3",
2221
"mikey179/vfsstream": "~1.5",
2322
"mockery/mockery": "~0.9",
2423
"phpdocumentor/reflection-docblock": "~2.0",
25-
"symfony/yaml": "~2.8",
2624
"squizlabs/php_codesniffer": "~2.2",
2725
"tinify/tinify": "dev-create-key",
2826
"wp-coding-standards/wpcs": "0.11"

composer.lock

Lines changed: 72 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vendor/tinify/Tinify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Tinify;
44

5-
const VERSION = "1.5.2";
5+
const VERSION = "1.6.2";
66

77
class Tinify {
88
const AUTHENTICATED = true;

src/vendor/tinify/Tinify/Client.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function __construct($key, $appIdentifier = NULL, $proxy = NULL) {
3434
$userAgent = join(" ", array_filter(array(self::userAgent(), $appIdentifier)));
3535

3636
$this->options = array(
37-
CURLOPT_BINARYTRANSFER => true,
3837
CURLOPT_RETURNTRANSFER => true,
3938
CURLOPT_HEADER => true,
4039
CURLOPT_USERPWD => $key ? ("api:" . $key) : NULL,
@@ -114,7 +113,7 @@ function request($method, $url, $body = NULL) {
114113
$headers = self::parseHeaders(substr($response, 0, $headerSize));
115114
$responseBody = substr($response, $headerSize);
116115

117-
if (isset($headers["compression-count"])) {
116+
if ( isset($headers["compression-count"] ) ) {
118117
Tinify::setCompressionCount(intval($headers["compression-count"]));
119118
}
120119

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

128+
$details = json_decode($responseBody);
129+
if (!$details) {
130+
$message = sprintf("Error while parsing response: %s (#%d)",
131+
PHP_VERSION_ID >= 50500 ? json_last_error_msg() : "Error",
132+
json_last_error());
133+
$details = (object) array(
134+
"message" => $message,
135+
"error" => "ParseError"
136+
);
137+
}
138+
129139
if ( isset( $headers["email-address"] ) ) {
130140
Tinify::setEmailAddress( $headers["email-address"] );
131141
}

src/vendor/tinify/Tinify/ResultMeta.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ public function height() {
2020
public function location() {
2121
return isset($this->meta["location"]) ? $this->meta["location"] : null;
2222
}
23+
24+
public function extension() {
25+
if (isset($this->meta["content-type"])) {
26+
$parts = explode("/", $this->meta["content-type"]);
27+
return end($parts);
28+
}
29+
return null;
30+
}
2331
}

src/vendor/tinify/Tinify/Source.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public function store($options) {
4242
return new Result($response->headers, $response->body);
4343
}
4444

45+
public function convert($options) {
46+
$commands = array_merge($this->commands, array("convert" => $options));
47+
return new self($this->url, $commands);
48+
}
49+
50+
public function transform($options) {
51+
$commands = array_merge($this->commands, array("transform" => $options));
52+
return new self($this->url, $commands);
53+
}
54+
4555
public function result() {
4656
$response = Tinify::getClient()->request("get", $this->url, $this->commands);
4757
return new Result($response->headers, $response->body);

0 commit comments

Comments
 (0)