Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
A helper class to access microsoft live resources using the api. More...
Public Member Functions | |
__construct ($clientid, $clientsecret, $returnurl) | |
Construct a skydrive request object. More... | |
build_post_data ($params) | |
Given an array of name value pairs - build a valid HTTP POST application/x-www-form-urlencoded string. More... | |
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_file ($id, $path) | |
Downloads a file to a file from skydrive using authenticated request. 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_list ($path='') | |
Returns a list of files the user has formated for files api. More... | |
get_folder_name ($folderid) | |
Returns a folder name property for a given folderid. More... | |
get_info () | |
Get curl information. 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... | |
getResponse () | |
Get HTTP Response Headers. 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... | |
options ($url, $options=array()) | |
HTTP OPTIONS method. More... | |
patch ($url, $params='', $options=array()) | |
HTTP PATCH method. More... | |
post ($url, $params='', $options=array()) | |
Post request. 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. | |
set_security ($securityobject) | |
Sets the curl security helper. More... | |
setHeader ($header) | |
Set HTTP Request Header. More... | |
setopt ($options=array()) | |
Set curl options. 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 | |
cache_session | $foldernamecache = null |
cache of foldernames | |
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 | |
string const | API = 'https://apis.live.net/v5.0' |
Base url to access API. | |
string const | SCOPE = 'wl.skydrive' |
OAuth 2.0 scope. | |
Protected Member Functions | |
auth_url () | |
Returns the auth url for OAuth 2.0 request. 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... | |
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... | |
A helper class to access microsoft live resources using the api.
This uses the microsfot API defined in http://msdn.microsoft.com/en-us/library/hh243648.aspx
microsoft_skydrive::__construct | ( | $clientid, | |
$clientsecret, | |||
$returnurl | |||
) |
Construct a skydrive request object.
string | $clientid | client id for OAuth 2.0 provided by microsoft |
string | $clientsecret | secret for OAuth 2.0 provided by microsoft |
moodle_url | $returnurl | url to return to after succseful auth |
|
protected |
Returns the auth url for OAuth 2.0 request.
string | the auth url |
Reimplemented from oauth2_client.
|
inherited |
Given an array of name value pairs - build a valid HTTP POST application/x-www-form-urlencoded string.
array | $params | Name / value pairs. |
string | POST data. |
|
staticinherited |
Callback url where the request is returned to.
moodle_url | url of callback |
Reimplemented in core_badges\oauth2\client.
|
inherited |
HTTP DELETE method.
string | $url | |
array | $param | |
array | $options |
bool |
|
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') ));
array | $requests | An 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 | $options | An array of options to set |
array | An array of results |
microsoft_skydrive::download_file | ( | $id, | |
$path | |||
) |
Downloads a file to a file from skydrive using authenticated request.
string | $id | id of file |
string | $path | path to save file to |
array | stucture for repository download_file |
|
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
string | $url | |
array | null | $params | key-value pairs to be added to $url as query string |
array | $options | request options. Must include either 'file' or 'filepath' |
bool|string | true on success or error string on failure |
|
inherited |
HTTP GET method.
string | $url | |
array | $params | |
array | $options |
bool |
|
inherited |
Get access token.
This is just a getter to read the private property.
string |
|
inherited |
An additional array of url params to pass with a login request.
array | of name value pairs. |
Reimplemented in core\oauth2\client.
|
staticinherited |
Get the location of ca certificates.
string | absolute file path or empty if default used |
|
inherited |
Get the client ID.
This is just a getter to read the private property.
string |
|
inherited |
Get the client secret.
This is just a getter to read the private property.
string |
|
inherited |
Get curl error code.
int |
microsoft_skydrive::get_file_list | ( | $path = '' | ) |
Returns a list of files the user has formated for files api.
string | $path | the path which we are in |
mixed | Array of files formated for fileapoi |
microsoft_skydrive::get_folder_name | ( | $folderid | ) |
Returns a folder name property for a given folderid.
string | $folderid | the folder id which is passed |
mixed | folder name or false in case of error |
|
inherited |
Get curl information.
string |
|
inherited |
Returns the login link for this oauth request.
moodle_url | login url |
Reimplemented in core_badges\oauth2\client.
|
inherited |
Get raw HTTP Response Headers.
array | of strings |
|
inherited |
Get a refresh token!!!
string |
|
inherited |
Returns the current curl security helper.
core::files::curl_security_helper | instance. |
|
protectedinherited |
Retrieve a token stored.
stdClass|null | token object |
Reimplemented in core_badges\oauth2\client, and core\oauth2\client.
|
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.
string | tokenname for prefernce storage |
Reimplemented in core\oauth2\client.
|
inherited |
Get HTTP Response Headers.
array | of arrays |
|
inherited |
|
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.
boolean | true if logged in |
Reimplemented in core_badges\oauth2\client.
|
inherited |
Logs out of a oauth request, clearing any stored tokens.
Reimplemented in boxnet_client.
|
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.
string | $response |
|
protectedinherited |
Multiple HTTP Requests This function could run multi-requests in parallel.
array | $requests | An array of files to request |
array | $options | An array of options to set |
array | An array of results |
Reimplemented from curl.
|
inherited |
HTTP OPTIONS method.
string | $url | |
array | $options |
bool |
|
inherited |
HTTP PATCH method.
string | $url | |
array | string | $params | |
array | $options |
bool |
microsoft_skydrive::post | ( | $url, | |
$params = '' , |
|||
$options = array() |
|||
) |
Post request.
Overridden to convert the data to a string, else curl will set the wrong headers.
string | $url | The URL. |
array | string | $params | The parameters. |
array | $options | The options. |
bool |
Reimplemented from curl.
|
inherited |
HTTP PUT method.
string | $url | |
array | $params | |
array | $options |
bool |
|
protectedinherited |
Single HTTP Request.
string | $url | The URL to request |
array | $options |
bool |
|
protectedinherited |
Make a HTTP request, adding the access token we have.
string | $url | The URL to request |
array | $options | |
mixed | $acceptheader | mimetype (as string) or false to skip sending an accept header. |
bool |
Reimplemented in google_oauth.
|
protectedinherited |
Helper function to reset the request state vars.
void. |
|
inherited |
Sets the curl security helper.
core::files::curl_security_helper | $securityobject | instance/subclass of the base curl_security_helper class. |
bool | true if the security helper could be set, false otherwise. |
|
inherited |
Set HTTP Request Header.
array | $header |
|
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.
array | $options | If array is null, this function will reset the options to default value. |
void |
coding_exception | If an option uses constant value instead of option name. |
|
protectedinherited |
Store a token between requests.
Currently uses session named by get_tokenname
stdClass | null | $token | token object to store or null to clear |
Reimplemented in core_badges\oauth2\client, and core\oauth2\client.
|
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.
string | $input | Input HTTP response |
string | HTTP response with additional headers stripped if any |
|
protected |
Returns the token url for OAuth 2.0 request.
string | the auth url |
Reimplemented from oauth2_client.
|
inherited |
HTTP TRACE method.
string | $url | |
array | $options |
bool |
|
inherited |
Upgrade a authorization token from oauth 2.0 to an access token.
string | $code | the code returned from the oauth authenticaiton |
boolean | true if token is upgraded succesfully |
|
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).
bool | true if GET should be used |
|
inherited |
Perform redirects at PHP level instead of relying on native cURL functionality.
Always true now.