Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@robinbobin/react-native-google-drive-api-wrapper
Advanced tools
This wrapper facilitates the use of the Google Drive API in React Native projects.
This wrapper facilitates the use of the google drive api.
It doesn't provide any authorization mechanism, so another package has to be used. I use @react-native-google-signin/google-signin (thanks for the great work, vonovak!).
npm i --save @robinbobin/react-native-google-drive-api-wrapper
Example:
// = List files, create a binary file and read it = //
import { GoogleSignin } from "@react-native-google-signin/google-signin";
import {
GDrive,
MimeTypes
} from "@robinbobin/react-native-google-drive-api-wrapper";
// = Somewhere in your code = //
GoogleSignin.configure(...);
await GoogleSignin.signIn();
const gdrive = new GDrive();
gdrive.accessToken = (await GoogleSignin.getTokens()).accessToken;
console.log(await gdrive.files.list());
const id = (await gdrive.files.newMultipartUploader()
.setData([1, 2, 3, 4, 5], MimeTypes.BINARY)
.setRequestBody({
name: "multipart_bin"
})
.execute()
).id;
console.log(await gdrive.files.getBinary(id));
Extending GDriveApi, this class gives access to various information.
Name | Description |
---|---|
get(queryParametersOrFields) | Gets various information, returning an About resource if the call succeeds and fetchCoercesTypes is true . queryParametersOrFields can be an object containing the query parameters or a string, containing a fields value. |
Extending GDriveApi, this class is used to manage files in a google drive. The parameter range
for the methods that accept it is specified as here with one exception:
<unit> is always bytes and mustn't be set. E.g.:
await gdrive.files.getBinary(fileId, null, "1-1");
will return the byte at index one.
Name | Type | Description |
---|---|---|
copy(fileId, queryParameters, requestBody = {}) | Method | Creates a copy of a file. Returns a Files resource if the call succeeds and fetchCoercesTypes is true . |
delete(fileId) | Method | Deletes a file. Returns an empty string if the call succeeds and fetchCoercesTypes is true . |
emptyTrash() | Method | Permanently deletes all of the user's trashed files. Returns an empty string if the call succeeds and fetchCoercesTypes is true . |
export(fileId, queryParameters) | Method | Exports a Google Doc to the requested MIME type. Returns a Files resource if the call succeeds and fetchCoercesTypes is true . |
generateIds(queryParameters) | Method | Generates file IDs. Returns an Object if the call succeeds and fetchCoercesTypes is true . |
get(fileId, queryParameters, range) | Method | Gets a file's metadata or content by ID. Returns the result of fetch() if the call succeeds, fetchCoercesTypes is ignored. |
getBinary(fileId, queryParameters, range) | Method | Gets the content of a binary file. Returns Uint8Array if the call succeeds and fetchCoercesTypes is true . |
getContent(fileId, queryParameters, range) | Method | Gets the content of any file. Returns the result of fetch() if the call succeeds, fetchCoercesTypes is ignored. |
getJson(fileId, queryParameters) | Method | Gets the content of a json text file. Returns an Object if the call succeeds and fetchCoercesTypes is true . |
getMetadata(fileId, queryParameters = {}) | Method | Gets a file's metadata. Returns a Files resource if the call succeeds and fetchCoercesTypes is true . |
getText(fileId, queryParameters, range) | Method | Gets the content of a text file. Returns a string if the call succeeds and fetchCoercesTypes is true . |
list(queryParameters) | Method | Lists files. Returns an Object if the call succeeds and fetchCoercesTypes is true .queryParameters.q can be a ListQueryBuilder instance. |
multipartBoundary | String (read/write property) | The boundary string to be used for multipart uploads. The default value is "foo_bar_baz" . |
newMediaUploader() | Method | Creates an Uploader instance with uploadType of media . |
newMetadataOnlyUploader() | Method | Creates a metadata-only Uploader instance. |
newMultipartUploader() | Method | Creates an Uploader instance with uploadType of multipart . |
A GDrive
instance stores your google sign-in token and the class instances you create to utilize the google drive api.
Name | Type | Description |
---|---|---|
about | About instance | The instance to get various information. |
accessToken | access token | The access token to be used in subsequent calls to the api. Get the token from a package you choose to use. |
files | Files instance | The instance to manage files in a google drive. |
permissions | Permissions instance | The instance to manage file permissions. |
The base class for the classes that wrap individual parts of the google drive api.
Name | Type | Description |
---|---|---|
fetchCoercesTypes | Boolean (read/write property) | If true, the data returned from a successful api call is converted to the json, text or byte (Uint8Array ) type. If false , no conversion is performed and the result of fetch() is returned as is. The type, the data is coerced to, is specified in the documentation of each method, that utilizes this property. The default value is true . |
fetchRejectsOnHttpErrors | Boolean (read/write property) | If true, unsuccessful api calls throw an instance of HttpError . If false , the result of fetch() is returned as is. The default value is true . |
An instance of this class is thrown when an api call fails, if fetchRejectsOnHttpErrors is true
for that api. All the properties are read-only.
Name | Type | Description |
---|---|---|
json | Object | An object containing the error. Can be undefined . |
response | Object | The result of fetch() . |
text | String | The error description obtained from the response. |
A helper for building list()
queries.
Example:
// = List files contained in the root folder and named "Untitled" = //
await gdrive.files.list({
q: new ListQueryBuilder()
.e("name", "Untitled")
.and()
.in("root", "parents")
});
Name | Description |
---|---|
and() | and s two subqueries. |
contains(key, value, quoteValueIfString = true) | key contains value |
e(key, value, quoteValueIfString = true) | key = value |
g(key, value, quoteValueIfString = true) | key > value |
in(value, key, quoteValueIfString = true) | value in key |
l(key, value, quoteValueIfString = true) | key < value |
operator(left, operator, right, quoteLeftIfString, quoteRightIfString) | A generic method to build all the other key/value relations. |
or() | or s two subqueries. |
pop() | Adds ) . |
push() | Adds ( . |
toString() | Stringifies the query (called internally by list() ). |
Commonly used MIME types. The class contains only static fields.
Name | Type |
---|---|
BINARY | application/octet-stream |
CSV | text/csv |
FOLDER | application/vnd.google-apps.folder |
JSON | application/json |
JSON_UTF8 | application/json; charset=UTF-8 |
application/pdf | |
TEXT | text/plain |
This class handles file permissions.
Name | Description |
---|---|
create(fileId, queryParameters, requestBody) | Creates a permission, returning a Permissions resource if the call succeeds and fetchCoercesTypes is true . |
delete(fileId, permissionId, queryParameters) | Deletes a permission, returning an empty string if the call succeeds and fetchCoercesTypes is true . |
This class handles the create and update requests. Currently only media
, multipart
and metadata-only requests are supported.
Name | Description |
---|---|
execute() | Executes the request, returning an Object if the call succeeds and fetchCoercesTypes is true . |
setData(data, dataType) | Sets the data and its MIME type. |
setIdOfFileToUpdate(fileId) | If this method is invoked, the request becomes an update request. Otherwise it's a creation request. |
setIsBase64(isBase64) | If it's a multipart request and the data supplied is Base64, this method can be invoked to add the header Content-Transfer-Encoding: base64 which is recognized by Google Drive. |
setQueryParameters(queryParameters) | Sets the query parameters. |
setRequestBody(requestBody) | Sets the request body. |
Version number | Changes |
---|---|
v0.5.0 | ListQueryBuilder added. |
v0.4.0 | Permissions added. |
v0.3.0 | Initial documented release. |
Written with StackEdit.
FAQs
This wrapper facilitates the use of the Google Drive API in React Native projects.
The npm package @robinbobin/react-native-google-drive-api-wrapper receives a total of 2,067 weekly downloads. As such, @robinbobin/react-native-google-drive-api-wrapper popularity was classified as popular.
We found that @robinbobin/react-native-google-drive-api-wrapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.