Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit b37f8c8

Browse files
author
Jim
committed
Successfully tested the library. Found and fixed a few issues. Once Dropbox moves out of beta with their API this will be clear to merge into the master branch.
1 parent cd31fa2 commit b37f8c8

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

libraries/dropbox.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class dropbox
3535
const HTTP_1 = '1.1';
3636
const LINE_END = "\r\n";
3737

38-
const DEBUG = false;
38+
const DEBUG = true;
3939

4040
//Array that should contain the consumer secret and
4141
//key which should be passed into the constructor.
@@ -266,14 +266,14 @@ public function revisions($path, array $params = array(), $root='dropbox')
266266
* Restore a file or folder to a previous revision.
267267
*
268268
* @param string $path The path to the file or folder in question
269-
* @param string $revision The revision to revert to.
269+
* @param string $revision The rev hash to revert to.
270270
* @param string $root (optional) Either 'dropbox' or 'sandbox'
271271
* @return a response object
272272
**/
273273
public function restore($path, $revision, $root='dropbox')
274274
{
275275
$path = str_replace(' ', '%20', $path);
276-
return $this->_post_request("/restore/{$root}/{$path}", array('rev'=>$revision));
276+
return $this->_post_request("/restore/{$root}/{$path}?rev={$revision}");
277277
}
278278

279279
/**
@@ -377,7 +377,7 @@ public function move($from, $to, $root='dropbox')
377377
// Below are the private methods used to create and send the requests to the dropbox api server.
378378
////////////////////////////////////////////////////////////////////////////////////////////////
379379

380-
private function _post_request($uri, array $data, $specialhost = false)
380+
private function _post_request($uri, $data = false, $specialhost = false)
381381
{
382382
$request = "POST {$uri} HTTP/".self::HTTP_1.self::LINE_END;
383383
$host = self::HOST;
@@ -392,7 +392,7 @@ private function _post_request($uri, array $data, $specialhost = false)
392392
$header = $this->_build_header($url, 'POST', $request, self::LINE_END, $extra);
393393
if(self::DEBUG)error_log($header);
394394

395-
$response = $this->_connect($url, $header, $data);
395+
$response = $this->_connect($url, $header, 'POST', $data);
396396
return json_decode($response);
397397
}
398398

@@ -406,7 +406,7 @@ private function _content_request($uri, $destination)
406406
$header = $this->_build_header($url, 'GET', $request, self::LINE_END, array('Host'=>$specialhost));
407407
if(self::DEBUG)error_log($header);
408408

409-
$this->_connect($url, $header, false, $destination);
409+
$this->_connect($url, $header, 'GET', false, $destination);
410410
}
411411

412412
private function _response_request($uri)
@@ -418,7 +418,7 @@ private function _response_request($uri)
418418
$header = $this->_build_header($url, 'GET', $request, self::LINE_END);
419419
if(self::DEBUG)error_log($header);
420420

421-
$response = $this->_connect($url, $header, false);
421+
$response = $this->_connect($url, $header, 'GET');
422422
return json_decode($response);
423423
}
424424

@@ -436,14 +436,15 @@ private function _build_header($url, $method, $prepend, $append, $overwrite = ar
436436
return $str;
437437
}
438438

439-
private function _connect($url, $header, $postdata = false, $destination = false)
439+
private function _connect($url, $header, $request, $postdata = false, $destination = false)
440440
{
441441
$ch = curl_init($url);
442442
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
443443
curl_setopt($ch, CURLOPT_SSLVERSION,3);
444444
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
445445
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
446446
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
447+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
447448
curl_setopt($ch, CURLOPT_HTTPHEADER, explode(self::LINE_END, $header));
448449
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
449450

@@ -454,6 +455,13 @@ private function _connect($url, $header, $postdata = false, $destination = false
454455
}
455456

456457
$response = curl_exec($ch);
458+
459+
if(self::DEBUG)
460+
{
461+
error_log(print_r(curl_getinfo($ch), true));
462+
error_log($response);
463+
}
464+
457465
//If the specified a destination and the request went OK write the file.
458466
if($destination !== false && curl_getinfo($ch, CURLINFO_HTTP_CODE) == '200')
459467
{

0 commit comments

Comments
 (0)