The Crystal module for the Drive API
Manages files in Drive including uploading, downloading, searching, detecting changes, and updating sharing permissions.
This SDK is automatically generated by the OpenAPI Generator project with CUSTOM templates:
- API version: v3
- Package version: 3.4.1
- Build package: org.openapitools.codegen.languages.CrystalClientCodegen
- Custom templates: crystal_client_generator
For more information, please visit https://google.com
Add the following to shard.yaml
dependencies:
google_drive:
github: cyangle/google_drive
version: ~> 3.4.1Check here for more information about how to use google drive v3 APIs.
Below lists only a few examples of the most interesting APIs, the client should support all APIs provided by google drive as it's generated from the OpenAPI v3 specification ./google-drive-api-v3-oas3.json.
First you need to require it.
require "google_drive"Or require a specific api only.
require "google_drive/api/files_api"GoogleDrive.configure do |config|
config.access_token = "Google OAuth2 Access Token"
endfiles_api = GoogleDrive::FilesApi.newfiles_api.list(page_size: 10, spaces: "appDataFolder")file_meta : GoogleDrive::File = files_api.get(file_id: "unique_file_id")files_api.get(file_id: "unique_file_id", alt: "media") do |response|
File.open("my_file.txt", "w") do |file|
IO.copy(response.body_io, file)
end
endnew_file_meta : GoogleDrive::File = files_api.upload(
upload_type: "media",
media: File.open("./test.json")
)file_meta = GoogleDrive::File.new(
name: "test.json",
mime_type: "application/json",
parents: ["appDataFolder"]
)
new_file_meta : GoogleDrive::File = files_api.upload(
upload_type: "multipart",
metadata: IO::Memory.new(file_meta.to_json),
media: File.open("./test.json")
)folder = GoogleDrive::File.new(
name: "my_app",
mime_type: "application/vnd.google-apps.folder",
parents: ["appDataFolder"]
)
files_api.create(file: folder)Update file name.
file_meta = GoogleDrive::File.new(name: "new_name.json")
files_api.update(file_id: "unique_file_id", file: file_meta)files_api.update_content(file_id: "unique_file_id", media: File.open("./test2.json"))files_api.delete(file_id: "unique_file_id")Install dependencies
shardsRun the tests:
crystal specRun lints
./bin/ameba
crystal tool format --check