code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function startUploadSession($dropboxFile, $chunkSize = -1, $close = false) { //Make Dropbox File with the given chunk size $dropboxFile = $this->makeDropboxFile($dropboxFile, $chunkSize); //Set the close param $params = [ 'close' => $close ? true : false, 'file' => $dropboxFile ]; //Upload File $file = $this->postToContent('/files/upload_session/start', $params); $body = $file->getDecodedBody(); //Cannot retrieve Session ID if (!isset($body['session_id'])) { throw new DropboxClientException("Could not retrieve Session ID."); } //Return the Session ID return $body['session_id']; }
Start an Upload Session @param string|DropboxFile $dropboxFile DropboxFile object or Path to file @param int $chunkSize Size of file chunk to upload @param boolean $close Closes the session for "appendUploadSession" @return string Unique identifier for the upload session @throws \Kunnu\Dropbox\Exceptions\DropboxClientException @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start
startUploadSession
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function postToContent($endpoint, array $params = [], $accessToken = null, DropboxFile $responseFile = null) { return $this->sendRequest("POST", $endpoint, 'content', $params, $accessToken, $responseFile); }
Make a HTTP POST Request to the Content endpoint type @param string $endpoint Content Endpoint to send Request to @param array $params Request Query Params @param string $accessToken Access Token to send with the Request @param DropboxFile $responseFile Save response to the file @return \Kunnu\Dropbox\DropboxResponse @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
postToContent
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function appendUploadSession($dropboxFile, $sessionId, $offset, $chunkSize, $close = false) { //Make Dropbox File $dropboxFile = $this->makeDropboxFile($dropboxFile, $chunkSize, $offset); //Session ID, offset, chunkSize and path cannot be null if (is_null($sessionId) || is_null($offset) || is_null($chunkSize)) { throw new DropboxClientException("Session ID, offset and chunk size cannot be null"); } $params = []; //Set the File $params['file'] = $dropboxFile; //Set the Cursor: Session ID and Offset $params['cursor'] = ['session_id' => $sessionId, 'offset' => $offset]; //Set the close param $params['close'] = $close ? true : false; //Since this endpoint doesn't have //any return values, we'll disable the //response validation for this request. $params['validateResponse'] = false; //Upload File $this->postToContent('/files/upload_session/append_v2', $params); //Make and Return the Model return $sessionId; }
Append more data to an Upload Session @param string|DropboxFile $dropboxFile DropboxFile object or Path to file @param string $sessionId Session ID returned by `startUploadSession` @param int $offset The amount of data that has been uploaded so far @param int $chunkSize The amount of data to upload @param boolean $close Closes the session for futher "appendUploadSession" calls @return string Unique identifier for the upload session @throws \Kunnu\Dropbox\Exceptions\DropboxClientException @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append_v2
appendUploadSession
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function finishUploadSession($dropboxFile, $sessionId, $offset, $remaining, $path, array $params = []) { //Make Dropbox File $dropboxFile = $this->makeDropboxFile($dropboxFile, $remaining, $offset); //Session ID, offset, remaining and path cannot be null if (is_null($sessionId) || is_null($path) || is_null($offset) || is_null($remaining)) { throw new DropboxClientException("Session ID, offset, remaining and path cannot be null"); } $queryParams = []; //Set the File $queryParams['file'] = $dropboxFile; //Set the Cursor: Session ID and Offset $queryParams['cursor'] = ['session_id' => $sessionId, 'offset' => $offset]; //Set the path $params['path'] = $path; //Set the Commit $queryParams['commit'] = $params; //Upload File $file = $this->postToContent('/files/upload_session/finish', $queryParams); $body = $file->getDecodedBody(); //Make and Return the Model return new FileMetadata($body); }
Finish an upload session and save the uploaded data to the given file path @param string|DropboxFile $dropboxFile DropboxFile object or Path to file @param string $sessionId Session ID returned by `startUploadSession` @param int $offset The amount of data that has been uploaded so far @param int $remaining The amount of data that is remaining @param string $path Path to save the file to, on Dropbox @param array $params Additional Params @return \Kunnu\Dropbox\Models\FileMetadata @throws \Kunnu\Dropbox\Exceptions\DropboxClientException @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish
finishUploadSession
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function simpleUpload($dropboxFile, $path, array $params = []) { //Make Dropbox File $dropboxFile = $this->makeDropboxFile($dropboxFile); //Set the path and file $params['path'] = $path; $params['file'] = $dropboxFile; //Upload File $file = $this->postToContent('/files/upload', $params); $body = $file->getDecodedBody(); //Make and Return the Model return new FileMetadata($body); }
Upload a File to Dropbox in a single request @param string|DropboxFile $dropboxFile DropboxFile object or Path to file @param string $path Path to upload the file to @param array $params Additional Params @link https://www.dropbox.com/developers/documentation/http/documentation#files-upload @return \Kunnu\Dropbox\Models\FileMetadata @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
simpleUpload
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function getThumbnail($path, $size = 'small', $format = 'jpeg') { //Path cannot be null if (is_null($path)) { throw new DropboxClientException("Path cannot be null."); } //Invalid Format if (!in_array($format, ['jpeg', 'png'])) { throw new DropboxClientException("Invalid format. Must either be 'jpeg' or 'png'."); } //Thumbnail size $size = $this->getThumbnailSize($size); //Get Thumbnail $response = $this->postToContent('/files/get_thumbnail', ['path' => $path, 'format' => $format, 'size' => $size]); //Get file metadata from response headers $metadata = $this->getMetadataFromResponseHeaders($response); //File Contents $contents = $response->getBody(); //Make and return a Thumbnail model return new Thumbnail($metadata, $contents); }
Get a thumbnail for an image @param string $path Path to the file you want a thumbnail to @param string $size Size for the thumbnail image ['thumb','small','medium','large','huge'] @param string $format Format for the thumbnail image ['jpeg'|'png'] @return \Kunnu\Dropbox\Models\Thumbnail @throws \Kunnu\Dropbox\Exceptions\DropboxClientException @link https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail
getThumbnail
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
protected function getThumbnailSize($size) { $thumbnailSizes = [ 'thumb' => 'w32h32', 'small' => 'w64h64', 'medium' => 'w128h128', 'large' => 'w640h480', 'huge' => 'w1024h768' ]; return isset($thumbnailSizes[$size]) ? $thumbnailSizes[$size] : $thumbnailSizes['small']; }
Get thumbnail size @param string $size Thumbnail Size @return string
getThumbnailSize
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
protected function getMetadataFromResponseHeaders(DropboxResponse $response) { //Response Headers $headers = $response->getHeaders(); //Empty metadata for when //metadata isn't returned $metadata = []; //If metadata is available if (isset($headers[static::METADATA_HEADER])) { //File Metadata $data = $headers[static::METADATA_HEADER]; //The metadata is present in the first index //of the metadata response header array if (is_array($data) && isset($data[0])) { $data = $data[0]; } //Since the metadata is returned as a json string //it needs to be decoded into an associative array $metadata = json_decode((string)$data, true); } //Return the metadata return $metadata; }
Get metadata from response headers @param DropboxResponse $response @return array
getMetadataFromResponseHeaders
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function download($path, $dropboxFile = null) { //Path cannot be null if (is_null($path)) { throw new DropboxClientException("Path cannot be null."); } //Make Dropbox File if target is specified $dropboxFile = $dropboxFile ? $this->makeDropboxFile($dropboxFile, null, null, DropboxFile::MODE_WRITE) : null; //Download File $response = $this->postToContent('/files/download', ['path' => $path], null, $dropboxFile); //Get file metadata from response headers $metadata = $this->getMetadataFromResponseHeaders($response); //File Contents $contents = $dropboxFile ? $this->makeDropboxFile($dropboxFile) : $response->getBody(); //Make and return a File model return new File($metadata, $contents); }
Download a File @param string $path Path to the file you want to download @param null|string|DropboxFile $dropboxFile DropboxFile object or Path to target file @return \Kunnu\Dropbox\Models\File @throws \Kunnu\Dropbox\Exceptions\DropboxClientException @link https://www.dropbox.com/developers/documentation/http/documentation#files-download
download
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function getCurrentAccount() { //Get current account $response = $this->postToAPI('/users/get_current_account', []); $body = $response->getDecodedBody(); //Make and return the model return new Account($body); }
Get Current Account @link https://www.dropbox.com/developers/documentation/http/documentation#users-get_current_account @return \Kunnu\Dropbox\Models\Account @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getCurrentAccount
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function getAccount($account_id) { //Get account $response = $this->postToAPI('/users/get_account', ['account_id' => $account_id]); $body = $response->getDecodedBody(); //Make and return the model return new Account($body); }
Get Account @param string $account_id Account ID of the account to get details for @link https://www.dropbox.com/developers/documentation/http/documentation#users-get_account @return \Kunnu\Dropbox\Models\Account @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getAccount
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function getAccounts(array $account_ids = []) { //Get account $response = $this->postToAPI('/users/get_account_batch', ['account_ids' => $account_ids]); $body = $response->getDecodedBody(); //Make and return the model return new AccountList($body); }
Get Multiple Accounts in one call @param array $account_ids IDs of the accounts to get details for @link https://www.dropbox.com/developers/documentation/http/documentation#users-get_account_batch @return \Kunnu\Dropbox\Models\AccountList @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getAccounts
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function getSpaceUsage() { //Get space usage $response = $this->postToAPI('/users/get_space_usage', []); $body = $response->getDecodedBody(); //Return the decoded body return $body; }
Get Space Usage for the current user's account @link https://www.dropbox.com/developers/documentation/http/documentation#users-get_space_usage @return array @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getSpaceUsage
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Dropbox.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php
MIT
public function __construct($clientId, $clientSecret, $accessToken = null) { $this->clientId = $clientId; $this->clientSecret = $clientSecret; $this->accessToken = $accessToken; }
Create a new Dropbox instance @param string $clientId Application Client ID @param string $clientSecret Application Client Secret @param string $accessToken Access Token
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxApp.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxApp.php
MIT
public function getClientId() { return $this->clientId; }
Get the App Client ID @return string
getClientId
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxApp.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxApp.php
MIT
public function getClientSecret() { return $this->clientSecret; }
Get the App Client Secret @return string
getClientSecret
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxApp.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxApp.php
MIT
public function getAccessToken() { return $this->accessToken; }
Get the Access Token @return string
getAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxApp.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxApp.php
MIT
public function __construct(DropboxHttpClientInterface $httpClient) { //Set the HTTP Client $this->setHttpClient($httpClient); }
Create a new DropboxClient instance @param DropboxHttpClientInterface $httpClient
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
public function getHttpClient() { return $this->httpClient; }
Get the HTTP Client @return \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface $httpClient
getHttpClient
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
public function setHttpClient(DropboxHttpClientInterface $httpClient) { $this->httpClient = $httpClient; return $this; }
Set the HTTP Client @param \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface $httpClient @return \Kunnu\Dropbox\DropboxClient
setHttpClient
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
public function getBasePath() { return static::BASE_PATH; }
Get the API Base Path. @return string API Base Path
getBasePath
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
public function getContentPath() { return static::CONTENT_PATH; }
Get the API Content Path. @return string API Content Path
getContentPath
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
protected function buildAuthHeader($accessToken = "") { return ['Authorization' => 'Bearer '. $accessToken]; }
Get the Authorization Header with the Access Token. @param string $accessToken Access Token @return array Authorization Header
buildAuthHeader
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
protected function buildContentTypeHeader($contentType = "") { return ['Content-Type' => $contentType]; }
Get the Content Type Header. @param string $contentType Request Content Type @return array Content Type Header
buildContentTypeHeader
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
protected function buildUrl($endpoint = '', $type = 'api') { //Get the base path $base = $this->getBasePath(); //If the endpoint type is 'content' if ($type === 'content') { //Get the Content Path $base = $this->getContentPath(); } //Join and return the base and api path/endpoint return $base . $endpoint; }
Build URL for the Request @param string $endpoint Relative API endpoint @param string $type Endpoint Type @link https://www.dropbox.com/developers/documentation/http/documentation#formats Request and response formats @return string The Full URL to the API Endpoints
buildUrl
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
public function sendRequest(DropboxRequest $request, DropboxResponse $response = null) { //Method $method = $request->getMethod(); //Prepare Request list($url, $headers, $requestBody) = $this->prepareRequest($request); $options = []; if ($response instanceof DropboxResponseToFile) { $options['sink'] = $response->getSteamOrFilePath(); } //Send the Request to the Server through the HTTP Client //and fetch the raw response as DropboxRawResponse $rawResponse = $this->getHttpClient()->send($url, $method, $requestBody, $headers, $options); //Create DropboxResponse from DropboxRawResponse $response = $response ?: new DropboxResponse($request); $response->setHttpStatusCode($rawResponse->getHttpResponseCode()); $response->setHeaders($rawResponse->getHeaders()); if (!$response instanceof DropboxResponseToFile) { $response->setBody($rawResponse->getBody()); } //Return the DropboxResponse return $response; }
Send the Request to the Server and return the Response @param DropboxRequest $request @param DropboxResponse $response @return \Kunnu\Dropbox\DropboxResponse @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
sendRequest
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
protected function prepareRequest(DropboxRequest $request) { //Build URL $url = $this->buildUrl($request->getEndpoint(), $request->getEndpointType()); //The Endpoint is content if ($request->getEndpointType() === 'content') { //Dropbox requires the parameters to be passed //through the 'Dropbox-API-Arg' header $request->setHeaders(['Dropbox-API-Arg' => json_encode($request->getParams())]); //If a File is also being uploaded if ($request->hasFile()) { //Content Type $request->setContentType("application/octet-stream"); //Request Body (File Contents) $requestBody = $request->getStreamBody()->getBody(); } else { //Empty Body $requestBody = null; } } else { //The endpoint is 'api' //Request Body (Parameters) $requestBody = $request->getJsonBody()->getBody(); } //Empty body if (is_null($requestBody)) { //Content Type needs to be kept empty $request->setContentType(""); } //Build headers $headers = array_merge( $this->buildAuthHeader($request->getAccessToken()), $this->buildContentTypeHeader($request->getContentType()), $request->getHeaders() ); //Return the URL, Headers and Request Body return [$url, $headers, $requestBody]; }
Prepare a Request before being sent to the HTTP Client @param \Kunnu\Dropbox\DropboxRequest $request @return array [Request URL, Request Headers, Request Body]
prepareRequest
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxClient.php
MIT
public function __construct($filePath, $mode = self::MODE_READ) { $this->path = $filePath; $this->mode = $mode; }
Create a new DropboxFile instance @param string $filePath Path of the file to upload @param string $mode The type of access
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public static function createByStream($fileName, $resource, $mode = self::MODE_READ) { // create a new stream and set it to the dropbox file $stream = \GuzzleHttp\Psr7\Utils::streamFor($resource); if (!$stream) { throw new DropboxClientException('Failed to create DropboxFile instance. Unable to open the given resource.'); } // Try to get the file path from the stream (we'll need this for uploading bigger files) $filePath = $stream->getMetadata('uri'); if (!is_null($filePath)) { $fileName = $filePath; } $dropboxFile = new self($fileName, $mode); $dropboxFile->setStream($stream); return $dropboxFile; }
Create a new DropboxFile instance using a file stream @param $fileName @param $resource @param string $mode @return DropboxFile @throws DropboxClientException
createByStream
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public static function createByPath($filePath, $mode) { return new self($filePath, $mode); }
Create a new DropboxFile instance using a file path This behaves the same as the constructor but was added in order to match the syntax of the static createByStream function @see DropboxFile::createByStream() @param $filePath @param $mode @return DropboxFile
createByPath
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function setOffset($offset) { $this->offset = $offset; }
Set the offset to start reading the data from the stream @param int $offset
setOffset
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function setMaxLength($maxLength) { $this->maxLength = $maxLength; }
Set the Max Length till where to read the data from the stream. @param int $maxLength
setMaxLength
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function getContents() { $stream = $this->getStream(); // If an offset is provided if ($this->offset !== -1) { // Seek to the offset $stream->seek($this->offset); } // If a max length is provided if ($this->maxLength !== -1) { // Read from the offset till the maxLength return $stream->read($this->maxLength); } return $stream->getContents(); }
Return the contents of the file @return string @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getContents
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function getStream() { if (!$this->stream) { $this->open(); } return $this->stream; }
Get the Open File Stream @return \GuzzleHttp\Psr7\Stream @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getStream
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function setStream($stream) { $this->isStream = true; $this->stream = $stream; }
Manually set the stream for this DropboxFile instance @param $stream
setStream
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function open() { // File was created from a stream so don't open it again if ($this->isCreatedFromStream()) { return; } // File is not a remote file if (!$this->isRemoteFile($this->path)) { // File is not Readable if ($this->isNotReadable()) { throw new DropboxClientException('Failed to create DropboxFile instance. Unable to read resource: ' . $this->path . '.'); } // File is not Writable if ($this->isNotWritable()) { throw new DropboxClientException('Failed to create DropboxFile instance. Unable to write resource: ' . $this->path . '.'); } } // Create a stream $this->stream = \GuzzleHttp\Psr7\Utils::streamFor(fopen($this->path, $this->mode)); // Unable to create stream if (!$this->stream) { throw new DropboxClientException('Failed to create DropboxFile instance. Unable to open resource: ' . $this->path . '.'); } }
Opens the File Stream @throws DropboxClientException @return void
open
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
protected function isRemoteFile($pathToFile) { return preg_match('/^(https?|ftp):\/\/.*/', $pathToFile) === 1; }
Returns true if the path to the file is remote @param string $pathToFile @return boolean
isRemoteFile
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function getFileName() { return basename($this->path); }
Get the name of the file @return string
getFileName
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function getFilePath() { return $this->path; }
Get the path of the file @return string
getFilePath
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function getMode() { return $this->mode; }
Get the mode of the file stream @return string
getMode
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function getSize() { return $this->getStream()->getSize(); }
Get the size of the file @return int @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getSize
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function getMimetype() { return \GuzzleHttp\Psr7\mimetype_from_filename($this->path) ?: 'text/plain'; }
Get mimetype of the file @return string
getMimetype
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxFile.php
MIT
public function __construct($method, $endpoint, $accessToken, $endpointType = "api", array $params = [], array $headers = [], $contentType = null) { $this->setMethod($method); $this->setEndpoint($endpoint); $this->setAccessToken($accessToken); $this->setEndpointType($endpointType); $this->setParams($params); $this->setHeaders($headers); if ($contentType) { $this->setContentType($contentType); } }
Create a new DropboxRequest instance @param string $method HTTP Method of the Request @param string $endpoint API endpoint of the Request @param string $accessToken Access Token for the Request @param string $endpointType Endpoint type ['api'|'content'] @param mixed $params Request Params @param array $headers Headers to send along with the Request
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getMethod() { return $this->method; }
Get the Request Method @return string
getMethod
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setMethod($method) { $this->method = $method; return $this; }
Set the Request Method @param string @return \Kunnu\Dropbox\DropboxRequest
setMethod
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getAccessToken() { return $this->accessToken; }
Get Access Token for the Request @return string
getAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setAccessToken($accessToken) { $this->accessToken = $accessToken; return $this; }
Set Access Token for the Request @param string @return \Kunnu\Dropbox\DropboxRequest
setAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getEndpoint() { return $this->endpoint; }
Get the Endpoint of the Request @return string
getEndpoint
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setEndpoint($endpoint) { $this->endpoint = $endpoint; return $this; }
Set the Endpoint of the Request @param string @return \Kunnu\Dropbox\DropboxRequest
setEndpoint
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getEndpointType() { return $this->endpointType; }
Get the Endpoint Type of the Request @return string
getEndpointType
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setEndpointType($endpointType) { $this->endpointType = $endpointType; return $this; }
Set the Endpoint Type of the Request @param string @return \Kunnu\Dropbox\DropboxRequest
setEndpointType
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getContentType() { return $this->contentType; }
Get the Content Type of the Request @return string
getContentType
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setContentType($contentType) { $this->contentType = $contentType; return $this; }
Set the Content Type of the Request @param string @return \Kunnu\Dropbox\DropboxRequest
setContentType
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setHeaders(array $headers) { $this->headers = array_merge($this->headers, $headers); return $this; }
Set Request Headers @param array @return \Kunnu\Dropbox\DropboxRequest
setHeaders
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getJsonBody() { return new RequestBodyJsonEncoded($this->getParams()); }
Get JSON Encoded Request Body @return \Kunnu\Dropbox\Http\RequestBodyJsonEncoded
getJsonBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getParams() { return $this->params; }
Get the Request Params @return array
getParams
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setParams(array $params = []) { //Process Params $params = $this->processParams($params); //Set the params $this->params = $params; return $this; }
Set the Request Params @param array @return \Kunnu\Dropbox\DropboxRequest
setParams
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getStreamBody() { return new RequestBodyStream($this->getFile()); }
Get Stream Request Body @return \Kunnu\Dropbox\Http\RequestBodyStream
getStreamBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function getFile() { return $this->file; }
Get the File to be sent with the Request @return \Kunnu\Dropbox\DropboxFile
getFile
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function setFile(DropboxFile $file) { $this->file = $file; return $this; }
Set the File to be sent with the Request @param \Kunnu\Dropbox\DropboxFile @return \Kunnu\Dropbox\DropboxRequest
setFile
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function hasFile() { return !is_null($this->file) ? true : false; }
Returns true if Request has file to be uploaded @return boolean
hasFile
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function validateResponse() { return $this->validateResponse; }
Whether to validate response or not @return boolean
validateResponse
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
protected function processParams(array $params) { //If a file needs to be uploaded if (isset($params['file']) && $params['file'] instanceof DropboxFile) { //Set the file property $this->setFile($params['file']); //Remove the file item from the params array unset($params['file']); } //Whether the response needs to be validated //against being a valid JSON response if (isset($params['validateResponse'])) { //Set the validateResponse $this->validateResponse = $params['validateResponse']; //Remove the validateResponse from the params array unset($params['validateResponse']); } return $params; }
Process Params for the File parameter @param array $params Request Params @return array
processParams
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxRequest.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxRequest.php
MIT
public function __construct(DropboxRequest $request, $body = null, $httpStatusCode = null, array $headers = []) { $this->request = $request; $this->body = $body; $this->httpStatusCode = $httpStatusCode; $this->headers = $headers; }
Create a new DropboxResponse instance @param DropboxRequest $request @param string|null $body @param int|null $httpStatusCode @param array $headers
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
public function getRequest() { return $this->request; }
Get the Request Request @return \Kunnu\Dropbox\DropboxRequest
getRequest
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
public function getBody() { return $this->body; }
Get the Response Body @return string
getBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
public function getDecodedBody() { if (empty($this->decodedBody) || $this->decodedBody === null) { //Decode the Response Body $this->decodeBody(); } return $this->decodedBody; }
Get the Decoded Body @return array @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getDecodedBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
public function getAccessToken() { return $this->getRequest()->getAccessToken(); }
Get Access Token for the Request @return string
getAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
public function getHttpStatusCode() { return $this->httpStatusCode; }
Get the HTTP Status Code @return int
getHttpStatusCode
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
protected function decodeBody() { $body = $this->getBody(); if (isset($this->headers['Content-Type']) && in_array('application/json', $this->headers['Content-Type'])) { $this->decodedBody = (array) json_decode((string) $body, true); } // If the response needs to be validated if ($this->getRequest()->validateResponse()) { //Validate Response $this->validateResponse(); } }
Decode the Body @throws DropboxClientException @return void
decodeBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
protected function validateResponse() { // If JSON cannot be decoded if ($this->decodedBody === null) { throw new DropboxClientException("Invalid Response"); } }
Validate Response @return void @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
validateResponse
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponse.php
MIT
public function __construct(DropboxRequest $request, DropboxFile $file, $httpStatusCode = null, array $headers = []) { parent::__construct($request, null, $httpStatusCode, $headers); $this->file = $file; }
Create a new DropboxResponse instance @param DropboxRequest $request @param DropboxFile $file @param int|null $httpStatusCode @param array $headers
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/DropboxResponseToFile.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/DropboxResponseToFile.php
MIT
public function __construct( OAuth2Client $oAuth2Client, RandomStringGeneratorInterface $randomStringGenerator = null, PersistentDataStoreInterface $persistentDataStore = null ) { $this->oAuth2Client = $oAuth2Client; $this->randomStringGenerator = $randomStringGenerator; $this->persistentDataStore = $persistentDataStore; }
Create a new DropboxAuthHelper instance @param \Kunnu\Dropbox\Authentication\OAuth2Client $oAuth2Client @param \Kunnu\Dropbox\Security\RandomStringGeneratorInterface $randomStringGenerator @param \Kunnu\Dropbox\Store\PersistentDataStoreInterface $persistentDataStore
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
public function getRandomStringGenerator() { return $this->randomStringGenerator; }
Get the Random String Generator @return \Kunnu\Dropbox\Security\RandomStringGeneratorInterface
getRandomStringGenerator
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
public function getPersistentDataStore() { return $this->persistentDataStore; }
Get the Persistent Data Store @return \Kunnu\Dropbox\Store\PersistentDataStoreInterface
getPersistentDataStore
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
public function getAuthUrl($redirectUri = null, array $params = [], $urlState = null, $tokenAccessType = null) { // If no redirect URI // is provided, the // CSRF validation // is being handled // explicitly. $state = null; // Redirect URI is provided // thus, CSRF validation // needs to be handled. if (!is_null($redirectUri)) { //Get CSRF State Token $state = $this->getCsrfToken(); //Set the CSRF State Token in the Persistent Data Store $this->getPersistentDataStore()->set('state', $state); //Additional User Provided State Data if (!is_null($urlState)) { $state .= "|"; $state .= $urlState; } } //Get OAuth2 Authorization URL return $this->getOAuth2Client()->getAuthorizationUrl($redirectUri, $state, $params, $tokenAccessType); }
Get Authorization URL @param string $redirectUri Callback URL to redirect to after authorization @param array $params Additional Params @param string $urlState Additional User Provided State Data @param string $tokenAccessType Either `offline` or `online` or null @link https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize @return string
getAuthUrl
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
protected function decodeState($state) { $csrfToken = $state; $urlState = null; $splitPos = strpos($state, "|"); if ($splitPos !== false) { $csrfToken = substr($state, 0, $splitPos); $urlState = substr($state, $splitPos + 1); } return ['csrfToken' => $csrfToken, 'urlState' => $urlState]; }
Decode State to get the CSRF Token and the URL State @param string $state State @return array
decodeState
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
protected function validateCSRFToken($csrfToken) { $tokenInStore = $this->getPersistentDataStore()->get('state'); //Unable to fetch CSRF Token if (!$tokenInStore || !$csrfToken) { throw new DropboxClientException("Invalid CSRF Token. Unable to validate CSRF Token."); } //CSRF Token Mismatch if ($tokenInStore !== $csrfToken) { throw new DropboxClientException("Invalid CSRF Token. CSRF Token Mismatch."); } //Clear the state store $this->getPersistentDataStore()->clear('state'); }
Validate CSRF Token @param string $csrfToken CSRF Token @throws DropboxClientException @return void
validateCSRFToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
public function getAccessToken($code, $state = null, $redirectUri = null) { // No state provided // Should probably be // handled explicitly if (!is_null($state)) { //Decode the State $state = $this->decodeState($state); //CSRF Token $csrfToken = $state['csrfToken']; //Set the URL State $this->urlState = $state['urlState']; //Validate CSRF Token $this->validateCSRFToken($csrfToken); } //Fetch Access Token $accessToken = $this->getOAuth2Client()->getAccessToken($code, $redirectUri); //Make and return the model return new AccessToken($accessToken); }
Get Access Token @param string $code Authorization Code @param string $state CSRF & URL State @param string $redirectUri Redirect URI used while getAuthUrl @return \Kunnu\Dropbox\Models\AccessToken @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
public function getRefreshedAccessToken($accessToken, $grantType = 'refresh_token') { $newToken = $this->getOAuth2Client()->getAccessToken($accessToken->refresh_token, null, $grantType); return new AccessToken( array_merge( $accessToken->getData(), $newToken ) ); }
Get new Access Token by using the refresh token @param \Kunnu\Dropbox\Models\AccessToken $accessToken - Current access token object @param string $grantType ['refresh_token']
getRefreshedAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
public function revokeAccessToken() { $this->getOAuth2Client()->revokeAccessToken(); }
Revoke Access Token @return void @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
revokeAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/DropboxAuthHelper.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/DropboxAuthHelper.php
MIT
public function __construct(DropboxApp $app, DropboxClient $client, RandomStringGeneratorInterface $randStrGenerator = null) { $this->app = $app; $this->client = $client; $this->randStrGenerator = $randStrGenerator; }
Create a new DropboxApp instance @param \Kunnu\Dropbox\DropboxApp $app @param \Kunnu\Dropbox\DropboxClient $client @param \Kunnu\Dropbox\Security\RandomStringGeneratorInterface $randStrGenerator
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/OAuth2Client.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/OAuth2Client.php
MIT
protected function buildUrl($endpoint = '', array $params = []) { $queryParams = http_build_query($params, '', '&'); return static::BASE_URL . $endpoint . '?' . $queryParams; }
Build URL @param string $endpoint @param array $params Query Params @return string
buildUrl
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/OAuth2Client.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/OAuth2Client.php
MIT
public function getApp() { return $this->app; }
Get the Dropbox App @return \Kunnu\Dropbox\DropboxApp
getApp
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/OAuth2Client.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/OAuth2Client.php
MIT
public function getClient() { return $this->client; }
Get the Dropbox Client @return \Kunnu\Dropbox\DropboxClient
getClient
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/OAuth2Client.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/OAuth2Client.php
MIT
public function getAccessToken($code, $redirectUri = null, $grant_type = 'authorization_code') { //Request Params $params = [ 'code' => $code, 'grant_type' => $grant_type, 'client_id' => $this->getApp()->getClientId(), 'client_secret' => $this->getApp()->getClientSecret(), 'redirect_uri' => $redirectUri, ]; if ($grant_type === 'refresh_token') { // $params = [ 'refresh_token' => $code, 'grant_type' => $grant_type, 'client_id' => $this->getApp()->getClientId(), 'client_secret' => $this->getApp()->getClientSecret(), ]; } $params = http_build_query($params, '', '&'); $apiUrl = static::AUTH_TOKEN_URL; $uri = $apiUrl . "?" . $params; //Send Request through the DropboxClient //Fetch the Response (DropboxRawResponse) $response = $this->getClient() ->getHttpClient() ->send($uri, "POST", null); //Fetch Response Body $body = $response->getBody(); //Decode the Response body to associative array //and return return json_decode((string) $body, true); }
Get Access Token @param string $code Authorization Code | Refresh Token @param string $redirectUri Redirect URI used while getAuthorizationUrl @param string $grant_type Grant Type ['authorization_code' | 'refresh_token'] @return array @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
getAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/OAuth2Client.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/OAuth2Client.php
MIT
public function revokeAccessToken() { //Access Token $accessToken = $this->getApp()->getAccessToken(); //Request $request = new DropboxRequest("POST", "/auth/token/revoke", $accessToken); // Do not validate the response // since the /token/revoke endpoint // doesn't return anything in the response. // See: https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke $request->setParams(['validateResponse' => false]); //Revoke Access Token $this->getClient()->sendRequest($request); }
Disables the access token @return void @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
revokeAccessToken
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Authentication/OAuth2Client.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Authentication/OAuth2Client.php
MIT
public function __construct($headers, $body, $statusCode = null) { if (is_numeric($statusCode)) { $this->httpResponseCode = (int) $statusCode; } $this->headers = $headers; $this->body = $body; }
Create a new GraphRawResponse instance @param array $headers Response headers @param string $body Raw response body @param int|null $statusCode HTTP response code
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/DropboxRawResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/DropboxRawResponse.php
MIT
public function getHeaders() { return $this->headers; }
Get the response headers @return array
getHeaders
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/DropboxRawResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/DropboxRawResponse.php
MIT
public function getBody() { return $this->body; }
Get the response body @return string
getBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/DropboxRawResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/DropboxRawResponse.php
MIT
public function getHttpResponseCode() { return $this->httpResponseCode; }
Get the HTTP response code @return int
getHttpResponseCode
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/DropboxRawResponse.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/DropboxRawResponse.php
MIT
public function __construct(array $params = []) { $this->params = $params; }
Create a new RequestBodyJsonEncoded instance @param array $params Request Params
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/RequestBodyJsonEncoded.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/RequestBodyJsonEncoded.php
MIT
public function getBody() { //Empty body if (empty($this->params)) { return null; } return json_encode($this->params); }
Get the Body of the Request @return string|null
getBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/RequestBodyJsonEncoded.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/RequestBodyJsonEncoded.php
MIT
public function __construct(DropboxFile $file) { $this->file = $file; }
Create a new RequestBodyStream instance @param \Kunnu\Dropbox\DropboxFile $file
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/RequestBodyStream.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/RequestBodyStream.php
MIT
public function getBody() { return $this->file->getContents(); }
Get the Body of the Request @return string
getBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/RequestBodyStream.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/RequestBodyStream.php
MIT
public function __construct(Client $client = null) { //Set the client $this->client = $client ?: new Client(); }
Create a new DropboxGuzzleHttpClient instance. @param Client $client GuzzleHttp Client
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
MIT
public function send($url, $method, $body, $headers = [], $options = []) { //Create a new Request Object $request = new Request($method, $url, $headers, $body); try { //Send the Request $rawResponse = $this->client->send($request, $options); } catch (BadResponseException $e) { throw new DropboxClientException($e->getResponse()->getBody(), $e->getCode(), $e); } catch (RequestException $e) { $rawResponse = $e->getResponse(); if (! $rawResponse instanceof ResponseInterface) { throw new DropboxClientException($e->getMessage(), $e->getCode()); } } //Something went wrong if ($rawResponse->getStatusCode() >= 400) { throw new DropboxClientException($rawResponse->getBody()); } if (array_key_exists('sink', $options)) { //Response Body is saved to a file $body = ''; } else { //Get the Response Body $body = $this->getResponseBody($rawResponse); } $rawHeaders = $rawResponse->getHeaders(); $httpStatusCode = $rawResponse->getStatusCode(); //Create and return a DropboxRawResponse object return new DropboxRawResponse($rawHeaders, $body, $httpStatusCode); }
Send request to the server and fetch the raw response. @param string $url URL/Endpoint to send the request to @param string $method Request Method @param string|resource|StreamInterface $body Request Body @param array $headers Request Headers @param array $options Additional Options @return \Kunnu\Dropbox\Http\DropboxRawResponse Raw response from the server @throws \Kunnu\Dropbox\Exceptions\DropboxClientException
send
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
MIT
protected function getResponseBody($response) { //Response must be string $body = $response; if ($response instanceof ResponseInterface) { //Fetch the body $body = $response->getBody(); } if ($body instanceof StreamInterface) { $body = $body->getContents(); } return (string) $body; }
Get the Response Body. @param string|\Psr\Http\Message\ResponseInterface $response Response object @return string
getResponseBody
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
MIT
public static function make($handler) { //No handler specified if (!$handler) { return new DropboxGuzzleHttpClient(); } //Custom Implementation, maybe. if ($handler instanceof DropboxHttpClientInterface) { return $handler; } //Handler is a custom configured Guzzle Client if ($handler instanceof Guzzle) { return new DropboxGuzzleHttpClient($handler); } //Invalid handler throw new InvalidArgumentException('The http client handler must be an instance of GuzzleHttp\Client or an instance of Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface.'); }
Make HTTP Client @param \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface|\GuzzleHttp\Client|null $handler @return \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface
make
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Http/Clients/DropboxHttpClientFactory.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Http/Clients/DropboxHttpClientFactory.php
MIT
public function __construct(array $data) { parent::__construct($data); $this->token = $this->getDataProperty('access_token'); $this->tokenType = $this->getDataProperty('token_type'); $this->bearer = $this->getDataProperty('bearer'); $this->uid = $this->getDataProperty('uid'); $this->accountId = $this->getDataProperty('account_id'); $this->teamId = $this->getDataProperty('team_id'); $this->expiryTime = $this->getDataProperty('expires_in'); $this->refreshToken = $this->getDataProperty('refresh_token'); }
Create a new AccessToken instance @param array $data
__construct
php
kunalvarma05/dropbox-php-sdk
src/Dropbox/Models/AccessToken.php
https://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Models/AccessToken.php
MIT