google_drive
google_drive
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
Installation
Install from Git
Add the following to shard.yaml
dependencies:
google_drive:
github: cyangle/google_drive
version: ~> 3.4.1
Usage
Check 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
.
Require this shard in your project
First you need to require it.
require "google_drive"
Or require a specific api only.
require "google_drive/api/files_api"
Configure client with google OAuth2 access token
GoogleDrive.configure do |config|
config.access_token = "Google OAuth2 Access Token"
end
FilesApi
files_api = GoogleDrive::FilesApi.new
List files
files_api.list(page_size: 10, spaces: "appDataFolder")
Get file meta data by id
file_meta : GoogleDrive::File = files_api.get(file_id: "unique_file_id")
Download file by 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
end
Upload file
Simple upload
new_file_meta : GoogleDrive::File = files_api.upload(
upload_type: "media",
media: File.open("./test.json")
)
Multipart upload
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")
)
Create folder
folder = GoogleDrive::File.new(
name: "my_app",
mime_type: "application/vnd.google-apps.folder",
parents: ["appDataFolder"]
)
files_api.create(file: folder)
Update file metadata by id
Update file name.
file_meta = GoogleDrive::File.new(name: "new_name.json")
files_api.update(file_id: "unique_file_id", file: file_meta)
Update file content by id
files_api.update_content(file_id: "unique_file_id", media: File.open("./test2.json"))
Delete file by id
files_api.delete(file_id: "unique_file_id")
Development
Install dependencies
shards
Run the tests:
crystal spec
Run lints
./bin/ameba
crystal tool format --check
google_drive
- 9
- 2
- 0
- 0
- 5
- 3 months ago
- November 21, 2021
MIT License
Sun, 22 Dec 2024 23:03:52 GMT