Skip to content

Commit cd0d9d6

Browse files
committed
Fix autoload issue by putting Coconut_Job into Job.php
1 parent c588c62 commit cd0d9d6

File tree

5 files changed

+74
-67
lines changed

5 files changed

+74
-67
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Here is the PHP code to submit the config file:
4545
```php
4646
<?php
4747

48-
$job = Coconut_Job::create(array(
48+
require_once('vendor/autoload.php');
49+
50+
$job = Coconut\Job::create(array(
4951
'api_key' => 'k-api-key',
5052
'conf' => 'coconut.conf',
5153
'source' => 'http://yoursite.com/media/video.mp4',
@@ -67,10 +69,12 @@ You can also create a job without a config file. To do that you will need to giv
6769
```php
6870
<?php
6971

72+
require_once('vendor/autoload.php');
73+
7074
$vid = 1234;
7175
$s3 = 's3://accesskey:secretkey@mybucket';
7276

73-
$job = Coconut_Job::create(array(
77+
$job = Coconut\Job::create(array(
7478
'api_key' => 'k-api-key',
7579
'source' => 'http://yoursite.com/media/video.mp4',
7680
'webhook' => 'http://mysite.com/webhook/coconut?videoId=' . $vid,
@@ -89,13 +93,13 @@ Other example usage:
8993
```php
9094
<?php
9195
// Getting info about a job
92-
$job = Coconut_Job::get(18370773);
96+
$job = Coconut\Job::get(18370773);
9397

9498
// Retrieving metadata
95-
Coconut_Job::getAllMetadata(18370773);
99+
Coconut\Job::getAllMetadata(18370773);
96100

97101
// Retrieving the source file metadata only
98-
Coconut_Job::getMetadataFor(18370773, 'source');
102+
Coconut\Job::getMetadataFor(18370773, 'source');
99103
?>
100104
```
101105

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "opencoconut/coconut",
33
"type": "library",
4-
"version": "2.6.0",
4+
"version": "2.8.0",
55
"description": "Coconut is a Cloud Video Encoding Service built for developers",
66
"keywords": ["video", "encoding", "transcoding", "web service", "h264", "cloud"],
77
"homepage": "http://coconut.co",
@@ -19,6 +19,6 @@
1919
}
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "4.3"
22+
"phpunit/phpunit": "7"
2323
}
2424
}

src/Coconut.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -142,39 +142,4 @@ public static function config($options=array()) {
142142

143143
return join("\n", $new_conf);
144144
}
145-
}
146-
147-
class Coconut_Job {
148-
public static function create($options=array()) {
149-
$api_key = self::getApiKey($options);
150-
151-
return Coconut::submit(Coconut::config($options), $api_key);
152-
}
153-
154-
public static function get($jid, $options=array()) {
155-
$api_key = self::getApiKey($options);
156-
157-
return Coconut::get('/v1/jobs/' . $jid, $api_key);
158-
}
159-
160-
public static function getAllMetadata($jid, $options=array()) {
161-
$api_key = self::getApiKey($options);
162-
163-
return Coconut::get('/v1/metadata/jobs/' . $jid, $api_key);
164-
}
165-
166-
public static function getMetadataFor($jid, $source_or_output, $options=array()) {
167-
$api_key = self::getApiKey($options);
168-
169-
return Coconut::get('/v1/metadata/jobs/' . $jid . '/' . $source_or_output, $api_key);
170-
}
171-
172-
173-
private static function getApiKey($options=array()) {
174-
$api_key = null;
175-
if(isset($options['api_key'])) {
176-
$api_key = $options['api_key'];
177-
}
178-
return $api_key;
179-
}
180-
}
145+
}

src/Job.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Coconut;
4+
5+
class Job {
6+
public static function create($options=array()) {
7+
$api_key = self::getApiKey($options);
8+
9+
return Coconut::submit(Coconut::config($options), $api_key);
10+
}
11+
12+
public static function get($jid, $options=array()) {
13+
$api_key = self::getApiKey($options);
14+
15+
return Coconut::get('/v1/jobs/' . $jid, $api_key);
16+
}
17+
18+
public static function getAllMetadata($jid, $options=array()) {
19+
$api_key = self::getApiKey($options);
20+
21+
return Coconut::get('/v1/metadata/jobs/' . $jid, $api_key);
22+
}
23+
24+
public static function getMetadataFor($jid, $source_or_output, $options=array()) {
25+
$api_key = self::getApiKey($options);
26+
27+
return Coconut::get('/v1/metadata/jobs/' . $jid . '/' . $source_or_output, $api_key);
28+
}
29+
30+
31+
private static function getApiKey($options=array()) {
32+
$api_key = null;
33+
if(isset($options['api_key'])) {
34+
$api_key = $options['api_key'];
35+
}
36+
return $api_key;
37+
}
38+
}

tests/CoconutTest.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
<?php
2-
use Coconut\Coconut;
3-
use Coconut\Coconut_Job;
42

5-
class CoconutTest extends PHPUnit_Framework_TestCase {
3+
use PHPUnit\Framework\TestCase;
4+
5+
class CoconutTest extends TestCase {
66

77
/*
88
To run these tests, you need to set your API key with the
99
environment variable `COCONUT_API_KEY`
1010
*/
1111

1212
public function testSubmitJob() {
13-
$config = Coconut::config(array(
13+
$config = Coconut\Coconut::config(array(
1414
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
1515
'webhook' => 'http://mysite.com/webhook',
1616
'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4')
1717
));
1818

19-
$job = Coconut::submit($config);
19+
$job = Coconut\Coconut::submit($config);
2020
$this->assertEquals('processing', $job->{'status'});
2121
$this->assertTrue($job->{'id'} > 0);
2222
}
2323

2424
public function testSubmitBadConfig() {
25-
$config = Coconut::config(array(
25+
$config = Coconut\Coconut::config(array(
2626
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4'
2727
));
2828

29-
$job = Coconut::submit($config);
29+
$job = Coconut\Coconut::submit($config);
3030
$this->assertEquals('error', $job->{'status'});
3131
$this->assertEquals('config_not_valid', $job->{'error_code'});
3232
}
3333

3434
public function testSubmitConfigWithAPIKey() {
35-
$config = Coconut::config(array(
35+
$config = Coconut\Coconut::config(array(
3636
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4'
3737
));
3838

39-
$job = Coconut::submit($config, 'k-4d204a7fd1fc67fc00e87d3c326d9b75');
39+
$job = Coconut\Coconut::submit($config, 'k-4d204a7fd1fc67fc00e87d3c326d9b75');
4040
$this->assertEquals('error', $job->{'status'});
4141
$this->assertEquals('authentication_failed', $job->{'error_code'});
4242
}
4343

4444
public function testGenerateFullConfigWithNoFile() {
45-
$config = Coconut::config(array(
45+
$config = Coconut\Coconut::config(array(
4646
'vars' => array(
4747
'vid' => 1234,
4848
'user' => 5098,
@@ -78,7 +78,7 @@ public function testGenerateConfigWithFile() {
7878
fwrite($file, 'var s3 = s3://a:s@bucket/video' . "\n" . 'set webhook = http://mysite.com/webhook?vid=$vid&user=$user' . "\n" . '-> mp4 = $s3/$vid.mp4');
7979
fclose($file);
8080

81-
$config = Coconut::config(array(
81+
$config = Coconut\Coconut::config(array(
8282
'conf' => 'coconut.conf',
8383
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
8484
'vars' => array('vid' => 1234, 'user' => 5098)
@@ -105,7 +105,7 @@ public function testSubmitFile() {
105105
fwrite($file, 'var s3 = s3://a:s@bucket/video' . "\n" . 'set webhook = http://mysite.com/webhook?vid=$vid&user=$user' . "\n" . '-> mp4 = $s3/$vid.mp4');
106106
fclose($file);
107107

108-
$job = Coconut_Job::create(array(
108+
$job = Coconut\Job::create(array(
109109
'conf' => 'coconut.conf',
110110
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
111111
'vars' => array('vid' => 1234, 'user' => 5098)
@@ -118,7 +118,7 @@ public function testSubmitFile() {
118118
}
119119

120120
public function testSetApiKeyInJobOptions() {
121-
$job = Coconut_Job::create(array(
121+
$job = Coconut\Job::create(array(
122122
'api_key' => 'k-4d204a7fd1fc67fc00e87d3c326d9b75',
123123
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4'
124124
));
@@ -128,53 +128,53 @@ public function testSetApiKeyInJobOptions() {
128128
}
129129

130130
public function testGetJobInfo() {
131-
$config = Coconut::config(array(
131+
$config = Coconut\Coconut::config(array(
132132
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
133133
'webhook' => 'http://mysite.com/webhook',
134134
'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4')
135135
));
136136

137-
$job = Coconut::submit($config);
138-
$info = Coconut_Job::get($job->{"id"});
137+
$job = Coconut\Coconut::submit($config);
138+
$info = Coconut\Job::get($job->{"id"});
139139

140140
$this->assertEquals($info->{"id"}, $job->{"id"});
141141
}
142142

143143
public function testGetNotFoundJobReturnsNull() {
144-
$info = Coconut_Job::get(1000);
144+
$info = Coconut\Job::get(1000);
145145
$this->assertNull($info);
146146
}
147147

148148
public function testGetAllMetadata() {
149-
$config = Coconut::config(array(
149+
$config = Coconut\Coconut::config(array(
150150
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
151151
'webhook' => 'http://mysite.com/webhook',
152152
'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4')
153153
));
154154

155-
$job = Coconut::submit($config);
155+
$job = Coconut\Coconut::submit($config);
156156
sleep(4);
157157

158-
$metadata = Coconut_Job::getAllMetadata($job->{"id"});
158+
$metadata = Coconut\Job::getAllMetadata($job->{"id"});
159159
$this->assertNotNull($metadata);
160160
}
161161

162162
public function testGetMetadataForSource() {
163-
$config = Coconut::config(array(
163+
$config = Coconut\Coconut::config(array(
164164
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
165165
'webhook' => 'http://mysite.com/webhook',
166166
'outputs' => array('mp4' => 's3://a:s@bucket/video.mp4')
167167
));
168168

169-
$job = Coconut::submit($config);
169+
$job = Coconut\Coconut::submit($config);
170170
sleep(4);
171171

172-
$metadata = Coconut_Job::getMetadataFor($job->{"id"}, 'source');
172+
$metadata = Coconut\Job::getMetadataFor($job->{"id"}, 'source');
173173
$this->assertNotNull($metadata);
174174
}
175175

176176
public function testSetAPIVersion() {
177-
$config = Coconut::config(array(
177+
$config = Coconut\Coconut::config(array(
178178
'source' => 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
179179
'webhook' => 'http://mysite.com/webhook?vid=$vid&user=$user',
180180
'api_version' => 'beta',

0 commit comments

Comments
 (0)