Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
 - Retire host + protocol in favor of one endpoint property,
  allow passing that on to the Request object.
 - Improve readme (getting started)
 - Don't rely on globally installed phpunit when we can ship it via Composer
  • Loading branch information
kvz committed Jan 23, 2014
1 parent c61ca9f commit 9067c60
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SHELL := /bin/bash

phpunit = phpunit --colors --verbose $(1)
phpunit = vendor/phpunit/phpunit/phpunit.php --colors --verbose $(1)

test: test-simple
test-all: test-simple test-system
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Creates a new Transloadit assembly form including the hidden 'params' and
'signature' fields. A closing form tag is not included.

`$options` is an array of `TransloaditRequest` properties to be used.
For example: `"params"`, `"expires"`, `"protocol"`, etc..
For example: `"params"`, `"expires"`, `"endpoint"`, etc..

In addition to that, you can also pass an `"attributes"` key, which allows
you to set custom form attributes. For example:
Expand Down Expand Up @@ -317,27 +317,22 @@ The auth key of your Transloadit account.

The auth secret of your Transloadit account.

#### $TransloaditRequest->protocol = 'http';

The protocol to use when making this request. Valid values are `'http'` and
`'https'`.

#### $TransloaditRequest->method = 'GET';

Inherited from `CurlRequest`. Can be used to set the type of request to be
made.

#### $TransloaditRequest->host = 'api2.transloadit.com';
#### $TransloaditRequest->endpoint = 'https://api2.transloadit.com';

The host to send this request to.
The endpoint to send this request to.

#### $TransloaditRequest->path = null;

The url path to request.

#### $TransloaditRequest->url = null;

Inherited from `CurlRequest`. Lets you overwrite the above host / path
Inherited from `CurlRequest`. Lets you overwrite the above endpoint / path
properties with a fully custom url alltogether.

#### $TransloaditRequest->fields = array();
Expand Down Expand Up @@ -436,6 +431,15 @@ For more information on SemVer, please visit http://semver.org/.

diff: https://github.com/transloadit/php-sdk/compare/v1.0.1...master

### [v2.0.0](https://github.com/transloadit/php-sdk/tree/v2.0.0)

- Retire host + protocol in favor of one endpoint property,
allow passing that on to the Request object.
- Improve readme (getting started)
- Don't rely on globally installed phpunit when we can ship it via Composer

diff: https://github.com/transloadit/php-sdk/compare/v1.0.1...v2.0.0

### [v1.0.1](https://github.com/transloadit/php-sdk/tree/v1.0.1)

- Fix broken examples
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Transloadit SDK",
"keywords": ["transloadit","video","encoding","thumbnails","image","resizing","audio", "waveform", "document","processing","file","uploading"],
"homepage": "https://github.com/transloadit/php-sdk",
"license": "MIT",
"license": "MIT",
"require": {
"php": ">=5.3.0"
},
Expand Down
38 changes: 20 additions & 18 deletions lib/transloadit/Transloadit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
namespace transloadit;

class Transloadit{
public $key = null;
public $secret = null;
public $key = null;
public $secret = null;
public $endpoint = 'https://api2.transloadit.com';

public function __construct($attributes = array()) {
foreach ($attributes as $key => $val) {
Expand All @@ -13,8 +14,9 @@ public function __construct($attributes = array()) {

public function request($options = array(), $execute = true) {
$options = $options + array(
'key' => $this->key,
'secret' => $this->secret,
'key' => $this->key,
'secret' => $this->secret,
'endpoint' => $this->endpoint,
);
$request = new TransloaditRequest($options);
return ($execute)
Expand Down Expand Up @@ -54,13 +56,13 @@ public function createAssemblyForm($options = array()) {

$assembly = $this->request($options + array(
'method' => 'POST',
'path' => '/assemblies',
'path' => '/assemblies',
), false);
$assembly->prepare();

$formAttributes = array(
'action' => $assembly->url,
'method' => $assembly->method,
'action' => $assembly->url,
'method' => $assembly->method,
'enctype' => 'multipart/form-data',
) + $customFormAttributes;

Expand Down Expand Up @@ -89,7 +91,7 @@ public function createAssembly($options) {
// can help to get our assembly executed faster.
$boredInstance = $this->request(array(
'method' => 'GET',
'path' => '/instances/bored',
'path' => '/instances/bored',
), true);

$error = $boredInstance->error();
Expand All @@ -98,32 +100,32 @@ public function createAssembly($options) {
}

return $this->request($options + array(
'method' => 'POST',
'path' => '/assemblies',
'host' => $boredInstance->data['api2_host'],
'method' => 'POST',
'path' => '/assemblies',
'endpoint' => 'https://' . $boredInstance->data['api2_host'],
));
}

public function deleteAssembly($assembly_id) {
// Look up the host for this assembly
$response = $this->request(array(
'method' => 'GET',
'path' => '/assemblies/'.$assembly_id,
'path' => '/assemblies/'.$assembly_id,
), true);

$error = $response->error();
if ($error) {
return $error;
}

$url = parse_url($response->data['assembly_url']);

$response = $this->request(array(
'method' => 'DELETE',
'path' => $url['path'],
'host' => $url['host'],
'path' => $url['path'],
'host' => $url['host'],
));

$error = $response->error();
if ($error) {
return $error;
Expand Down
23 changes: 10 additions & 13 deletions lib/transloadit/TransloaditRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
namespace transloadit;

class TransloaditRequest extends CurlRequest{
public $key = null;
public $secret = null;
public $key = null;
public $secret = null;

public $protocol = 'http';
public $host = 'api2.transloadit.com';
public $path = null;
public $endpoint = 'https://api2.transloadit.com';
public $path = null;

public $params = array();
public $expires = '+2 hours';
public $params = array();
public $expires = '+2 hours';

public $headers = array(
public $headers = array(
'Expect:',
'User-Agent: Transloadit PHP SDK 0.10.0',
);
Expand All @@ -30,7 +29,7 @@ public function getParamsString() {
}

$params['auth'] = $params['auth'] + array(
'key' => $this->key,
'key' => $this->key,
'expires' => gmdate('Y/m/d H:i:s+00:00', strtotime($this->expires)),
);
return json_encode($params);
Expand Down Expand Up @@ -62,9 +61,8 @@ public function configureUrl() {
}

$this->url = sprintf(
'%s://%s%s',
$this->protocol,
$this->host,
'%s%s',
$this->endpoint,
$this->path
);
}
Expand All @@ -79,4 +77,3 @@ public function execute($response = null) {
return $response;
}
}
?>
13 changes: 4 additions & 9 deletions test/simple/TransloaditRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public function testConstructor() {
}

public function testAttributes() {
$this->assertEquals($this->request->protocol, 'http');
$this->assertEquals($this->request->host, 'api2.transloadit.com');
$this->assertEquals($this->request->endpoint, 'https://api2.transloadit.com');
$this->assertEquals($this->request->path, null);
$this->assertEquals($this->request->key, null);
$this->assertEquals($this->request->secret, null);
Expand Down Expand Up @@ -97,15 +96,11 @@ public function testPrepare() {
}

public function testConfigureUrl() {
$PROTOCOL = $this->request->protocol = 'ftp';
$PATH = $this->request->path = '/foo';
$HOST = $this->request->host = 'bar.com';
$PATH = $this->request->path = '/foo';
$ENDPOINT = $this->request->endpoint = 'ftp://bar.com';
$this->request->configureUrl();

$this->assertEquals(
sprintf('%s://%s%s', $PROTOCOL, $HOST, $PATH),
$this->request->url
);
$this->assertEquals('ftp://bar.com/foo', $this->request->url);

$URL = $this->request->url = 'http://custom.org/manual';
$this->request->configureUrl();
Expand Down
8 changes: 4 additions & 4 deletions test/simple/TransloaditTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

date_default_timezone_set('UTC');
use transloadit\Transloadit;

class TransloaditTest extends \PHPUnit_Framework_TestCase{
Expand Down Expand Up @@ -46,9 +46,9 @@ public function testCreateAssembly() {
->expects($this->at(1))
->method('request')
->with($this->equalTo($options + array(
'method' => 'POST',
'path' => '/assemblies',
'host' => $boredInstance->data['api2_host'],
'method' => 'POST',
'path' => '/assemblies',
'endpoint' => 'https://' . $boredInstance->data['api2_host'],
)))
->will($this->returnValue($assembly));

Expand Down

0 comments on commit 9067c60

Please sign in to comment.