Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darrarski/swift-google-drive-client
Basic Google Drive HTTP API client that does not depend on Google's SDK.
https://github.com/darrarski/swift-google-drive-client
cloud-file-system cloud-files google-drive google-drive-api google-drive-client oauth2 swift swift-package-manager
Last synced: 19 days ago
JSON representation
Basic Google Drive HTTP API client that does not depend on Google's SDK.
- Host: GitHub
- URL: https://github.com/darrarski/swift-google-drive-client
- Owner: darrarski
- License: mit
- Created: 2023-07-03T11:50:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-13T19:59:31.000Z (8 months ago)
- Last Synced: 2024-11-30T18:52:14.399Z (22 days ago)
- Topics: cloud-file-system, cloud-files, google-drive, google-drive-api, google-drive-client, oauth2, swift, swift-package-manager
- Language: Swift
- Homepage:
- Size: 135 KB
- Stars: 31
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swift Google Drive Client
![Swift v5.8](https://img.shields.io/badge/swift-v5.8-orange.svg)
![platforms iOS, macOS](https://img.shields.io/badge/platforms-iOS,_macOS-blue.svg)Basic Google Drive HTTP API client that does not depend on Google's SDK. No external dependencies.
- Authorize access
- List files
- Get file info
- Get file (download)
- Create file (upload)
- Update file (upload)
- Delete file
- Get user info (about)## 📖 Usage
Use [Swift Package Manager](https://swift.org/package-manager/) to add the `GoogleDriveClient` library as a dependency to your project.
Configure OAuth 2.0 Client ID using [Google Cloud Console](https://console.cloud.google.com/). Use `iOS` application type.
Configure your application so that it can handle sign-in redirects. For an iOS app, you can do it by adding or modifying `CFBundleURLTypes` in `Info.plist`:
```xml
CFBundleURLTypes
CFBundleTypeRole
Editor
CFBundleURLName
CFBundleURLSchemes
com.googleusercontent.apps.1234-abcd
```
Create the client:
```swift
import GoogleDriveClientlet client = GoogleDriveClient.Client.live(
config: .init(
clientID: "1234-abcd.apps.googleusercontent.com",
authScope: "https://www.googleapis.com/auth/drive",
redirectURI: "com.googleusercontent.apps.1234-abcd://"
)
)
```Make sure the `redirectURI` contains the scheme defined earlier.
The package provides a basic implementation for storing vulnerable data securely in the keychain. Optionally, you can provide your own, custom implementation of a keychain, instead of using the default one.
```swift
import GoogleDriveClientlet keychain = GoogleDriveClient.Keychain(
loadCredentials: { () async -> GoogleDriveClient.Credentials? in
// load from secure storage and return
},
saveCredentials: { (GoogleDriveClient.Credentials) async -> Void in
// save in secure storage
},
deleteCredentials: { () async -> Void in
// delete from secure storage
}
)
let client = GoogleDriveClient.Client.live(
config: .init(...),
keychain: keychain
)
```### ▶️ Example
This repository contains an [example iOS application](Example/GoogleDriveClientExampleApp) built with SwiftUI.
- Open `GoogleDriveClient.xcworkspace` in Xcode.
- Example source code is contained in the `Example` Xcode project.
- Run the app using the `GoogleDriveClientExampleApp` build scheme.
- The "Example" tab provides UI that uses `GoogleDriveClient` library.
- The "Console" tab provides UI for browsing application logs and HTTP requests.The example app uses [Dependencies](https://github.com/pointfreeco/swift-dependencies) to manage its own internal dependencies. For more information about the `Dependencies` library check out [official documentation](https://pointfreeco.github.io/swift-dependencies/main/documentation/dependencies).
## 🏛 Project structure
```
GoogleDriveClient (Xcode Workspace)
├─ swift-google-drive-client (Swift Package)
| └─ GoogleDriveClient (Library)
└─ Example (Xcode Project)
└─ GoogleDriveClientExampleApp (iOS Application)
```## 🛠 Develop
- Use Xcode (version ≥ 14.3.1).
- Clone the repository or create a fork & clone it.
- Open `GoogleDriveClient.xcworkspace` in Xcode.
- Use the `GoogleDriveClient` scheme for building the library and running unit tests.
- If you want to contribute, create a pull request containing your changes or bug fixes. Make sure to include tests for new/updated code.## ☕️ Do you like the project?
## 📄 License
Copyright © 2023 Dariusz Rybicki Darrarski
License: [MIT](LICENSE)