This is a Ruby project built to interact with Amazon's CloudDrive API. It works as both an SDK and a CLI in the sense that I've built the code to easily be implemented in your own projects but it also includes an executable to run many common processes right from the command line.
To obtain credentials for the client you must have an Amazon Developer account.
- Register for an Amazon Developer account at https://developer.amazon.com/
- Create a Security Profile at https://developer.amazon.com/lwa/sp/overview.html. Note the Client ID and Client Secret that are generated for you
- Request that your Security Profile be whitelisted for the Cloud Drive API at
https://developer.amazon.com/cd/sp/overview.html
- For Account Access Control select all options
- For Permission Level select Read and Write
- For Platform Support select Amazon
- Follow these instructions to add the website http://localhost to Allowed Return URLs for your Security Profile
Add this line to your application's Gemfile:
gem 'clouddrive'
And then execute:
$ bundle
Or install it yourself as:
$ gem install clouddrive
Create a file at ~/.cache/clouddrive-ruby/config.json
with the following contents:
{
"email": "YOUR EMAIL",
"client-id": "YOUR CLIENT ID",
"client-secret": "YOUR CLIENT SECRET"
}
Set the credentials on the file so that others cannot read it:
$ chmod 600 ~/.cache/clouddrive-ruby/config.json
The CLI is used by running clouddrive
with one of the following commands followed by any necessary arguments (use help
argument before any of the following commands for more information).
init Initialize the CLI with your Amazon email and CloudDrive API credentials
sync Sync the local cache with Amazon CloudDrive
clearcache Clear the local cache
metadata Output JSON-formatted metadata related to the remote file give its remote path
The CloudDrive SDK first needs have an authenticated Account
object which can then be passed into the different classes for API calls.
The Account
class is created by passing in the email
, client_id
, and client_secret
into the constructor and calling the authorize
method. This will handle authorizing and (if necessary) renewing authorization.
The initial authorize
method call will return false with an auth_url
key in its data
. This URL can then be passed into a second authorize
call which will parse out the code
parameter and complete the initial OAuth process.
account = CloudDrive::Account.new("me@example.com", "my-client-id", "clientsecret")
account.authorize
...
account.authorize(auth_url)
The authorize
method call will still need to be called periodically to renew its authorization as the OAuth token expires every 60 minutes.
By default, the SDK stores all necessary information (OAuth token information, local account caches, etc) into ~/.clouddrive
. Each account (email), has its own cache file and local cache database of its remote filesystem. Once authenticated, the local cache is initially synced with the remote CloudDrive by calling the sync
method.
account.sync
Every time sync
is called, it will update the local cache with all changes since the last sync
call. The local cache can be cleared out and reset by calling clear_cache
.
account.clear_cache
- Fork it ( https://github.com/[my-github-username]/clouddrive/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request