Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
repository_dropbox\dropbox Class Reference

Dropbox V2 API. More...

Inheritance diagram for repository_dropbox\dropbox:
oauth2_client curl

Public Member Functions

 __construct ($key, $secret, $callback)
 Create the DropBox API Client. More...
 
 build_post_data ($params)
 Given an array of name value pairs - build a valid HTTP POST application/x-www-form-urlencoded string. More...
 
 callback ()
 Process the callback.
 
 cleanopt ()
 Reset http method.
 
 delete ($url, $param=array(), $options=array())
 HTTP DELETE method. More...
 
 download ($requests, $options=array())
 Download multiple files in parallel. More...
 
 download_one ($url, $params, $options=array())
 Downloads one file and writes it to the specified file handler. More...
 
 get ($url, $params=array(), $options=array())
 HTTP GET method. More...
 
 get_accesstoken ()
 Get access token. More...
 
 get_additional_login_parameters ()
 An additional array of url params to pass with a login request. More...
 
 get_clientid ()
 Get the client ID. More...
 
 get_clientsecret ()
 Get the client secret. More...
 
 get_errno ()
 Get curl error code. More...
 
 get_file_share_info ($id)
 Fetch a valid public share link for the specified file. More...
 
 get_info ()
 Get curl information. More...
 
 get_listing ($path='')
 Get file listing from dropbox. More...
 
 get_login_url ()
 Returns the login link for this oauth request. More...
 
 get_raw_response ()
 Get raw HTTP Response Headers. More...
 
 get_refresh_token ()
 Get a refresh token!!! More...
 
 get_security ()
 Returns the current curl security helper. More...
 
 get_thumbnail ($path)
 Retrieves the thumbnail for the content, as supplied by dropbox. More...
 
 getResponse ()
 Get HTTP Response Headers. More...
 
 has_additional_results ($result)
 Whether the supplied result is paginated and not the final page. More...
 
 head ($url, $options=array())
 HTTP HEAD method. More...
 
 is_logged_in ()
 Is the user logged in? Note that if this is called after the first part of the authorisation flow the token is upgraded to an accesstoken. More...
 
 log_out ()
 Logs out of a oauth request, clearing any stored tokens. More...
 
 logout ()
 Revoke the current access token. More...
 
 options ($url, $options=array())
 HTTP OPTIONS method. More...
 
 patch ($url, $params='', $options=array())
 HTTP PATCH method. More...
 
 post ($url, $params='', $options=array())
 HTTP POST method. More...
 
 put ($url, $params=array(), $options=array())
 HTTP PUT method. More...
 
 resetcookie ()
 Reset Cookie.
 
 resetHeader ()
 Resets the HTTP Request headers (to prepare for the new request)
 
 resetopt ()
 Resets the CURL options that have already been set.
 
 search ($query='')
 Get file search results from dropbox. More...
 
 set_security ($securityobject)
 Sets the curl security helper. More...
 
 setHeader ($header)
 Set HTTP Request Header. More...
 
 setopt ($options=array())
 Set curl options. More...
 
 supports_thumbnail ($entry)
 Whether the entry is expected to have a thumbnail. More...
 
 trace ($url, $options=array())
 HTTP TRACE method. More...
 
 upgrade_token ($code)
 Upgrade a authorization token from oauth 2.0 to an access token. More...
 

Static Public Member Functions

static callback_url ()
 Callback url where the request is returned to. More...
 
static get_cacert ()
 Get the location of ca certificates. More...
 
static mock_response ($response)
 For use only in unit tests - we can pre-set the next curl response. More...
 
static strip_double_headers ($input)
 When using a proxy, an additional HTTP response code may appear at the start of the header. More...
 

Public Attributes

bool $cache = false
 Caches http request contents.
 
bool $emulateredirects = null
 Perform redirects at PHP level instead of relying on native cURL functionality. More...
 
int $errno
 error code
 
string $error
 error
 
array $header = array()
 http header
 
string $info
 cURL information
 
bool $proxy = null
 Uses proxy, null means automatic based on URL.
 
array $rawresponse = array()
 Raw response headers, needed for BC in download_file_content().
 
array $response = array()
 http's response
 
string $version = '0.4 dev'
 library version
 

Protected Member Functions

 auth_url ()
 Returns the auth url for OAuth 2.0 request. More...
 
 check_and_handle_api_errors ($data)
 Check for an attempt to handle API errors. More...
 
 fetch_dropbox_content ($endpoint, $data=[])
 Fetch content from the specified endpoint with the supplied data. More...
 
 fetch_dropbox_data ($endpoint, $data=[], string $resultnode='entries')
 Make an API call against the specified endpoint with supplied data. More...
 
 get_api_endpoint ($endpoint)
 Return the constructed API endpoint URL. More...
 
 get_content_endpoint ($endpoint)
 Return the constructed content endpoint URL. More...
 
 get_endpoint_for_continue (string $endpoint)
 Get the continue endpoint for the provided endpoint. More...
 
 get_stored_token ()
 Retrieve a token stored. More...
 
 get_tokenname ()
 Returns the tokenname for the access_token to be stored through multiple requests. More...
 
 multi ($requests, $options=array())
 Multiple HTTP Requests This function could run multi-requests in parallel. More...
 
 normalize_file_share_info ($entry)
 Normalize the file share info. More...
 
 request ($url, $options=array())
 Single HTTP Request. More...
 
 request ($url, $options=array(), $acceptheader='application/json')
 Make a HTTP request, adding the access token we have. More...
 
 reset_request_state_vars ()
 Helper function to reset the request state vars. More...
 
 store_token ($token)
 Store a token between requests. More...
 
 token_url ()
 Returns the token url for OAuth 2.0 request. More...
 
 use_http_get ()
 Should HTTP GET be used instead of POST? Some APIs do not support POST and want oauth to use GET instead (with the auth_token passed as a GET param). More...
 

Protected Attributes

stdClass $accesstoken = null
 $accesstoken access token object
 
bool $basicauth = false
 basicauth
 
string $refreshtoken = ''
 $refreshtoken refresh token string
 
string $scope = ''
 $scope of the authentication request
 

Detailed Description

Dropbox V2 API.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

repository_dropbox\dropbox::__construct (   $key,
  $secret,
  $callback 
)

Create the DropBox API Client.

Parameters
string$keyThe API key
string$secretThe API secret
string$callbackThe callback URL

Member Function Documentation

◆ auth_url()

repository_dropbox\dropbox::auth_url ( )
protected

Returns the auth url for OAuth 2.0 request.

Return values
stringthe auth url

Reimplemented from oauth2_client.

◆ build_post_data()

oauth2_client::build_post_data (   $params)
inherited

Given an array of name value pairs - build a valid HTTP POST application/x-www-form-urlencoded string.

Parameters
array$paramsName / value pairs.
Return values
stringPOST data.

◆ callback_url()

static oauth2_client::callback_url ( )
staticinherited

Callback url where the request is returned to.

Return values
moodle_urlurl of callback

Reimplemented in core_badges\oauth2\client.

◆ check_and_handle_api_errors()

repository_dropbox\dropbox::check_and_handle_api_errors (   $data)
protected

Check for an attempt to handle API errors.

This function attempts to deal with errors as per https://www.dropbox.com/developers/documentation/http/documentation#error-handling.

Parameters
mixed$dataThe returned content.
Exceptions
moodle_exception

◆ delete()

curl::delete (   $url,
  $param = array(),
  $options = array() 
)
inherited

HTTP DELETE method.

Parameters
string$url
array$param
array$options
Return values
bool

◆ download()

curl::download (   $requests,
  $options = array() 
)
inherited

Download multiple files in parallel.

Calls multi() with specific download headers

$c = new curl(); $file1 = fopen('a', 'wb'); $file2 = fopen('b', 'wb'); $c->download(array( array('url'=>'http://localhost/', 'file'=>$file1), array('url'=>'http://localhost/20/', 'file'=>$file2) )); fclose($file1); fclose($file2);

or

$c = new curl(); $c->download(array( array('url'=>'http://localhost/', 'filepath'=>'/tmp/file1.tmp'), array('url'=>'http://localhost/20/', 'filepath'=>'/tmp/file2.tmp') ));

Parameters
array$requestsAn array of files to request { url => url to download the file [required] file => file handler, or filepath => file path } If 'file' and 'filepath' parameters are both specified in one request, the open file handle in the 'file' parameter will take precedence and 'filepath' will be ignored.
array$optionsAn array of options to set
Return values
arrayAn array of results

◆ download_one()

curl::download_one (   $url,
  $params,
  $options = array() 
)
inherited

Downloads one file and writes it to the specified file handler.

$c = new curl(); $file = fopen('savepath', 'w'); $result = $c->download_one('http://localhost/', null, array('file' => $file, 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3)); fclose($file); $download_info = $c->get_info(); if ($result === true) { // file downloaded successfully } else { $error_text = $result; $error_code = $c->get_errno(); }

$c = new curl(); $result = $c->download_one('http://localhost/', null, array('filepath' => 'savepath', 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3)); // ... see above, no need to close handle and remove file if unsuccessful

Parameters
string$url
array | null$paramskey-value pairs to be added to $url as query string
array$optionsrequest options. Must include either 'file' or 'filepath'
Return values
bool|stringtrue on success or error string on failure

◆ fetch_dropbox_content()

repository_dropbox\dropbox::fetch_dropbox_content (   $endpoint,
  $data = [] 
)
protected

Fetch content from the specified endpoint with the supplied data.

Parameters
string$endpointThe endpoint to be contacted
array$dataAny data to pass to the endpoint
Return values
stringThe returned data

◆ fetch_dropbox_data()

repository_dropbox\dropbox::fetch_dropbox_data (   $endpoint,
  $data = [],
string  $resultnode = 'entries' 
)
protected

Make an API call against the specified endpoint with supplied data.

Parameters
string$endpointThe endpoint to be contacted
array$dataAny data to pass to the endpoint
string$resultnodeThe name of the node that contains the data
Return values
objectContent decoded from the endpoint

◆ get()

curl::get (   $url,
  $params = array(),
  $options = array() 
)
inherited

HTTP GET method.

Parameters
string$url
array$params
array$options
Return values
bool

◆ get_accesstoken()

oauth2_client::get_accesstoken ( )
inherited

Get access token.

This is just a getter to read the private property.

Return values
string

◆ get_additional_login_parameters()

oauth2_client::get_additional_login_parameters ( )
inherited

An additional array of url params to pass with a login request.

Return values
arrayof name value pairs.

Reimplemented in core\oauth2\client.

◆ get_api_endpoint()

repository_dropbox\dropbox::get_api_endpoint (   $endpoint)
protected

Return the constructed API endpoint URL.

Parameters
string$endpointThe endpoint to be contacted
Return values
moodle_urlThe constructed API URL

◆ get_cacert()

static curl::get_cacert ( )
staticinherited

Get the location of ca certificates.

Return values
stringabsolute file path or empty if default used

◆ get_clientid()

oauth2_client::get_clientid ( )
inherited

Get the client ID.

This is just a getter to read the private property.

Return values
string

◆ get_clientsecret()

oauth2_client::get_clientsecret ( )
inherited

Get the client secret.

This is just a getter to read the private property.

Return values
string

◆ get_content_endpoint()

repository_dropbox\dropbox::get_content_endpoint (   $endpoint)
protected

Return the constructed content endpoint URL.

Parameters
string$endpointThe endpoint to be contacted
Return values
moodle_urlThe constructed content URL

◆ get_endpoint_for_continue()

repository_dropbox\dropbox::get_endpoint_for_continue ( string  $endpoint)
protected

Get the continue endpoint for the provided endpoint.

Parameters
string$endpointThe original endpoint
Return values
string::$endpointThe generated/mapped continue link

◆ get_errno()

curl::get_errno ( )
inherited

Get curl error code.

Return values
int

◆ get_file_share_info()

repository_dropbox\dropbox::get_file_share_info (   $id)

Fetch a valid public share link for the specified file.

Parameters
string$idThe file path or file id of the file to fetch information for.
Return values
objectAn object containing the id, path, size, and URL of the entry

◆ get_info()

curl::get_info ( )
inherited

Get curl information.

Return values
string

◆ get_listing()

repository_dropbox\dropbox::get_listing (   $path = '')

Get file listing from dropbox.

Parameters
string$pathThe path to query
Return values
objectThe returned directory listing, or null on failure

◆ get_login_url()

oauth2_client::get_login_url ( )
inherited

Returns the login link for this oauth request.

Return values
moodle_urllogin url

Reimplemented in core_badges\oauth2\client.

◆ get_raw_response()

curl::get_raw_response ( )
inherited

Get raw HTTP Response Headers.

Return values
arrayof strings

◆ get_refresh_token()

oauth2_client::get_refresh_token ( )
inherited

Get a refresh token!!!

Return values
string

◆ get_security()

curl::get_security ( )
inherited

Returns the current curl security helper.

Return values
core::files::curl_security_helperinstance.

◆ get_stored_token()

oauth2_client::get_stored_token ( )
protectedinherited

Retrieve a token stored.

Return values
stdClass|nulltoken object

Reimplemented in core_badges\oauth2\client, and core\oauth2\client.

◆ get_thumbnail()

repository_dropbox\dropbox::get_thumbnail (   $path)

Retrieves the thumbnail for the content, as supplied by dropbox.

Parameters
string$pathThe path to fetch a thumbnail for
Return values
stringThumbnail image content

◆ get_tokenname()

oauth2_client::get_tokenname ( )
protectedinherited

Returns the tokenname for the access_token to be stored through multiple requests.

The default implentation is to use the classname combiend with the scope.

Return values
stringtokenname for prefernce storage

Reimplemented in core\oauth2\client.

◆ getResponse()

curl::getResponse ( )
inherited

Get HTTP Response Headers.

Return values
arrayof arrays

◆ has_additional_results()

repository_dropbox\dropbox::has_additional_results (   $result)

Whether the supplied result is paginated and not the final page.

Parameters
object$resultThe result of an operation
Return values
boolean

◆ head()

curl::head (   $url,
  $options = array() 
)
inherited

HTTP HEAD method.

See also
request()
Parameters
string$url
array$options
Return values
bool

◆ is_logged_in()

oauth2_client::is_logged_in ( )
inherited

Is the user logged in? Note that if this is called after the first part of the authorisation flow the token is upgraded to an accesstoken.

Return values
booleantrue if logged in

Reimplemented in core_badges\oauth2\client.

◆ log_out()

oauth2_client::log_out ( )
inherited

Logs out of a oauth request, clearing any stored tokens.

Reimplemented in boxnet_client.

◆ logout()

repository_dropbox\dropbox::logout ( )

Revoke the current access token.

Return values
string

◆ mock_response()

static curl::mock_response (   $response)
staticinherited

For use only in unit tests - we can pre-set the next curl response.

This is useful for unit testing APIs that call external systems.

Parameters
string$response

◆ multi()

oauth2_client::multi (   $requests,
  $options = array() 
)
protectedinherited

Multiple HTTP Requests This function could run multi-requests in parallel.

Parameters
array$requestsAn array of files to request
array$optionsAn array of options to set
Return values
arrayAn array of results

Reimplemented from curl.

◆ normalize_file_share_info()

repository_dropbox\dropbox::normalize_file_share_info (   $entry)
protected

Normalize the file share info.

Parameters
object$entryInformation retrieved from share endpoints
Return values
objectNormalized entry information to store as repository information

◆ options()

curl::options (   $url,
  $options = array() 
)
inherited

HTTP OPTIONS method.

Parameters
string$url
array$options
Return values
bool

◆ patch()

curl::patch (   $url,
  $params = '',
  $options = array() 
)
inherited

HTTP PATCH method.

Parameters
string$url
array | string$params
array$options
Return values
bool

◆ post()

curl::post (   $url,
  $params = '',
  $options = array() 
)
inherited

HTTP POST method.

Parameters
string$url
array | string$params
array$options
Return values
bool

Reimplemented in microsoft_skydrive.

◆ put()

curl::put (   $url,
  $params = array(),
  $options = array() 
)
inherited

HTTP PUT method.

Parameters
string$url
array$params
array$options
Return values
bool

◆ request() [1/2]

curl::request (   $url,
  $options = array() 
)
protectedinherited

Single HTTP Request.

Parameters
string$urlThe URL to request
array$options
Return values
bool

◆ request() [2/2]

oauth2_client::request (   $url,
  $options = array(),
  $acceptheader = 'application/json' 
)
protectedinherited

Make a HTTP request, adding the access token we have.

Parameters
string$urlThe URL to request
array$options
mixed$acceptheadermimetype (as string) or false to skip sending an accept header.
Return values
bool

Reimplemented in google_oauth.

◆ reset_request_state_vars()

curl::reset_request_state_vars ( )
protectedinherited

Helper function to reset the request state vars.

Return values
void.

◆ search()

repository_dropbox\dropbox::search (   $query = '')

Get file search results from dropbox.

Parameters
string$queryThe search query
Return values
objectThe returned directory listing, or null on failure

◆ set_security()

curl::set_security (   $securityobject)
inherited

Sets the curl security helper.

Parameters
core::files::curl_security_helper$securityobjectinstance/subclass of the base curl_security_helper class.
Return values
booltrue if the security helper could be set, false otherwise.

◆ setHeader()

curl::setHeader (   $header)
inherited

Set HTTP Request Header.

Parameters
array$header

◆ setopt()

curl::setopt (   $options = array())
inherited

Set curl options.

Do not use the curl constants to define the options, pass a string corresponding to that constant. Ie. to set CURLOPT_MAXREDIRS, pass array('CURLOPT_MAXREDIRS' => 10) or array('maxredirs' => 10) to this method.

Parameters
array$optionsIf array is null, this function will reset the options to default value.
Return values
void
Exceptions
coding_exceptionIf an option uses constant value instead of option name.

◆ store_token()

oauth2_client::store_token (   $token)
protectedinherited

Store a token between requests.

Currently uses session named by get_tokenname

Parameters
stdClass | null$tokentoken object to store or null to clear

Reimplemented in core_badges\oauth2\client, and core\oauth2\client.

◆ strip_double_headers()

static curl::strip_double_headers (   $input)
staticinherited

When using a proxy, an additional HTTP response code may appear at the start of the header.

For example, when using https over a proxy there may be 'HTTP/1.0 200 Connection Established'. Other codes are also possible and some may come with their own headers.

If using the return value containing all headers, this function can be called to remove unwanted doubles.

Note that it is not possible to distinguish this situation from valid data unless you know the actual response part (below the headers) will not be included in this string, or else will not 'look like' HTTP headers. As a result it is not safe to call this function for general data.

Parameters
string$inputInput HTTP response
Return values
stringHTTP response with additional headers stripped if any

◆ supports_thumbnail()

repository_dropbox\dropbox::supports_thumbnail (   $entry)

Whether the entry is expected to have a thumbnail.

See docs at https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail.

Parameters
object$entryThe file entry received from the DropBox API
Return values
booleanWhether dropbox has a thumbnail available

◆ token_url()

repository_dropbox\dropbox::token_url ( )
protected

Returns the token url for OAuth 2.0 request.

Return values
stringthe auth url

Reimplemented from oauth2_client.

◆ trace()

curl::trace (   $url,
  $options = array() 
)
inherited

HTTP TRACE method.

Parameters
string$url
array$options
Return values
bool

◆ upgrade_token()

oauth2_client::upgrade_token (   $code)
inherited

Upgrade a authorization token from oauth 2.0 to an access token.

Parameters
string$codethe code returned from the oauth authenticaiton
Return values
booleantrue if token is upgraded succesfully

◆ use_http_get()

oauth2_client::use_http_get ( )
protectedinherited

Should HTTP GET be used instead of POST? Some APIs do not support POST and want oauth to use GET instead (with the auth_token passed as a GET param).

Return values
booltrue if GET should be used

Member Data Documentation

◆ $emulateredirects

bool curl::$emulateredirects = null
inherited

Perform redirects at PHP level instead of relying on native cURL functionality.

Always true now.


The documentation for this class was generated from the following file: