· 6 years ago · Feb 04, 2020, 03:36 AM
1<?php
2
3error_reporting(-1);
4ini_set('display_errors', 1);
5
6require __DIR__ . '/../vendor/autoload.php';
7require __DIR__ . '/../config.php';
8
9use Shotstack\Client\Api\EndpointsApi;
10use Shotstack\Client\Configuration;
11use Shotstack\Client\ObjectSerializer;
12
13// https://dev.ttbabes.com/application/third_party/shotstack-sdk-php/examples/status.php?id=9bbfe291-7f96-4ede-ae80-0ae69a1536a7
14
15//header("Content-Type: plain/text");
16
17class StatusDemo
18{
19 protected $apiKey;
20 protected $apiUrl = 'https://api.shotstack.io/stage';
21
22 public function __construct()
23 {
24 //if (empty(getenv('SHOTSTACK_KEY'))) {
25 // die("API Key is required. Set using: export SHOTSTACK_KEY=your_key_here\n");
26 //}
27
28 //if (!empty(getenv('SHOTSTACK_HOST'))) {
29 // $this->apiUrl = getenv('SHOTSTACK_HOST');
30 //}
31
32 //$this->apiKey = getenv('SHOTSTACK_KEY');
33
34 if ( !defined('SHOTSTACK_HOST') ) {
35 die("API Key is required");
36 }
37
38 if ( !defined('SHOTSTACK_KEY') ) {
39 die("API Key is required");
40 }
41
42 if( !empty(SHOTSTACK_HOST) ){
43 $this->apiUrl = SHOTSTACK_HOST;
44 }
45
46 $this->apiKey = SHOTSTACK_KEY;
47
48 }
49
50 public function render($id)
51 {
52 $config = Configuration::getDefaultConfiguration()
53 ->setHost($this->apiUrl)
54 ->setApiKey('x-api-key', $this->apiKey);
55
56 /*$client = new EndpointsApi(null, $config);
57
58 try {
59 $response = $client->getRender($id)->getResponse();
60 } catch (Exception $e) {
61
62 die('Request failed or not found: ' . $e->getMessage());
63 }
64
65 echo "\nStatus: " . strtoupper($response->getStatus()) . "\n\n";
66
67 if ($response->getStatus() == 'done') {
68 echo ">> Video URL: " . $response->getUrl() . "\n";
69 } else if ($response->getStatus() == 'failed') {
70 echo ">> Something went wrong, rendering has terminated and will not continue.\n";
71 } else {
72 echo ">> Rendering in progress, please try again shortly.\n>> Note: Rendering may take up to 1 minute to complete.\n";
73 }
74
75*/
76
77 $client = new \GuzzleHttp\Client();
78
79 // Define array of request body.
80 $request_body = array();
81
82 try {
83
84 $response = $client->request('GET','https://api.shotstack.io/stage/render/' . $id , array(
85 'headers' => array(
86
87 'application/json',
88 'Accept' => 'application/json',
89 'x-api-key' => SHOTSTACK_KEY,
90 ),
91 ));
92 print_r($response->getBody()->getContents());
93 }
94 catch (\GuzzleHttp\Exception\BadResponseException $e) {
95 // handle exception or api errors.
96 print_r($e->getMessage());
97
98 print_r( json_decode( $e->getResponse()->getBody()->getContents() , true ) );
99 }
100
101
102 }
103}
104
105$id = ( isset($argv) && is_array($argv) && isset($argv[1]) ? $argv[1] : null );
106
107if( is_null($id) || empty($id) ){
108 $id = ( isset($_REQUEST['id']) ? $_REQUEST['id'] : null );
109}
110
111if ( empty($id) || is_null($id) ) {
112 echo ">> Please provide the UUID of the render task (i.e. php examples/status.php 2abd5c11-0f3d-4c6d-ba20-235fc9b8e8b7)\n";
113 return;
114}
115
116$demo = new StatusDemo();
117$demo->render( $id );