GithubHelp home page GithubHelp logo

mayurbaldha / react-native-google-drive-api-wrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robinbobin/react-native-google-drive-api-wrapper

0.0 1.0 0.0 19 KB

This wrapper facilitates the use of the google drive api.

JavaScript 100.00%

react-native-google-drive-api-wrapper's Introduction

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 (thanks for the great work guys!).

  1. Installation
  2. Usage
  3. Version history
npm i --save react-native-google-drive-api-wrapper

react-native link react-native-fs

react-native-fs is a package my code depends on and it needs linking.

  1. GDrive
  2. Files
  3. Permissions
  4. About

This is the "entry point" of the wrapper. It contains only static methods and fields.

import GDrive from "react-native-google-drive-api-wrapper";
  • setAccessToken()

    Sets the access token for use in subsequent calls to the api. Get the token from a package you choose to use.

     GDrive.setAccessToken(accessToken);
    
  • init()

    Initializes the wrapper.

     GDrive.init();
    

    or

     const params = {
         files: {
             boundary: String // The boundary string for multipart file uploads. Default: "foo_bar_baz".
         }
     };
     
     GDrive.init(params);
    
  • isInitialized()

    Returns true if an access token has been supplied, false otherwise.

     GDrive.isInitialized() ? <some code> : <some other code>;
    
  • createFileMultipart()

    Creates a file using multipart upload. Returns the result of fetch(). If contents is a base64 string, set isBase64 to true.

     const contents = "My text file contents";
     // or
     const contents = [10, 20, 30];
     
     GDrive.files.createFileMultipart(
         contents,
         "corresponding mime type", {
             parents: ["root"],
             name: "My file"
         },
         isBase64);
    
  • delete()

    Deletes the specified file returning the result of fetch().

     GDrive.files.delete(fileId);
    
  • get()

    Gets a file's metadata or a text-file's content by ID. By default the metadata is returned. Use download() for binary files. For queryParams see "Optional query parameters" here. If you want the content of a text-file and not its metadata add alt: "media" to queryParams.

     const queryParams = { ... };
     GDrive.files.get(fileId, queryParams);
    
  • download()

    Downloads the specified text or binary file.

    For downloadFileOptions see the description ofdownloadFile() here. Please, bear in mind that fromUrl is set automatically and any user supplied value will be overwritten.

    The meaning of queryParams is the same as in get().

    The function returns the result of RNFS.downloadFile(downloadFileOptions).

     GDrive.files.download(fileId, downloadFileOptions, queryParams);
    
  • export()

    Exports a google document, returning the result of fetch().

     GDrive.files.export(fileId, mimeType);
    
  • getId()

    Gets the id of the first file with the specified metadata. The function returns a Promise. It's rejected on failure and resolved to the file id or undefined (if nothing is found) on success.

     GDrive.files.getId(
         name: String, // The name.
         parents: [String], // The parents.
         mimeType: String, // The mime type.
         trashed: Boolean // Whether the file is trashed. Default: false
     );
    
  • list()

    Lists or searches files returning the result of fetch().

     GDrive.files.list({q: "'root' in parents"});
    
  • update()

    Updates a file's metadata. returning the result of fetch().

     GDrive.files.update("file_id", {
         removeParents: "o_parent_id",
         addParents: "parent_id",
         resource: {
     	modifiedTime: new Date(Date.now()).toISOString(),
         },
     })
    
  • safeCreateFolder()

    Gets the id of the first folder with the specified name and parents, creating the folder if it doesn't exist. The function returns a Promise that is rejected on failure and resolved to the folder id on success.

     GDrive.files.safeCreateFolder({
         name: "My folder",
         parents: ["root"]
     });
    
  • create()

    Creates a permission for the specified file returning the result of fetch().

     GDrive.permissions.create(
         fileId, {
             emailAddress: '[email protected]',
             role: "reader",
             type: "anyone"
         }, {
             emailMessage: `I shared a file with you.`,
         });
    
  • delete()

    Delete a permission returning the result of fetch().

     GDrive.permissions.delete("fileId", "permissionId");
    
  • get()

    Gets information about the user, the user's Drive, and system capabilities returning the result of fetch().

     GDrive.about.get({
         fields: 'storageQuota'
     });
    
Version number Changes
v1.2.0 GDrive.files.createFileMultipart()isBase64. Merge pull request #10 from duyluonglc/master. Thanks, duyluonglc!
v1.1.1 GDrive.files.export() added.
v1.0.1 1. A critical bug with invalid imports fixed.
2. client-side-common-utils deprecated; switched to simple-common-utils.
v1.0.0 Initial release.



Written with StackEdit.

react-native-google-drive-api-wrapper's People

Contributors

duyluonglc avatar mi5ha avatar mmoonn2 avatar robinbobin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.