-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from GoogleCloudPlatform/new-storage-samples
Add Google Cloud Storage samples
- Loading branch information
Showing
10 changed files
with
647 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/> | ||
|
||
# Google Cloud Storage Ruby Samples | ||
|
||
[Cloud Storage][storage_docs] allows world-wide storage and retrieval of any | ||
amount of data at any time. | ||
|
||
[storage_docs]: https://cloud.google.com/storage/docs/ | ||
|
||
## Run sample | ||
|
||
To run the sample, first install dependencies: | ||
|
||
bundle install | ||
|
||
Run the sample: | ||
|
||
bundle exec ruby buckets.rb | ||
bundle exec ruby files.rb | ||
|
||
## Samples | ||
|
||
### Buckets | ||
|
||
**Usage:** `bundle exec ruby buckets.rb [command] [arguments]` | ||
|
||
``` | ||
sage: bundle exec ruby buckets.rb [command] [arguments] | ||
Commands: | ||
list List all buckets in the authenticated project | ||
create <bucket> Create a new bucket with the provided name | ||
delete <bucket> Delete bucket with the provided name | ||
Environment variables: | ||
GCLOUD_PROJECT must be set to your Google Cloud project ID | ||
``` | ||
|
||
### Files | ||
|
||
**Usage:** `bundle exec ruby files.rb [command] [arguments]` | ||
|
||
``` | ||
Usage: bundle exec ruby files.rb [command] [arguments] | ||
Commands: | ||
list <bucket> List all files in the bucket | ||
upload <bucket> <file> Upload local file to a bucket | ||
download <bucket> <file> <path> Download a file from a bucket | ||
delete <bucket> <file> Delete a file from a bucket | ||
metadata <bucket> <file> Display metadata for a file in a bucket | ||
make_public <bucket> <file> Make a file in a bucket public | ||
rename <bucket> <file> <new> Rename a file in a bucket | ||
copy <srcBucket> <srcFile> <destBucket> <destFile> Copy file to other bucket | ||
Environment variables: | ||
GCLOUD_PROJECT must be set to your Google Cloud project ID | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2016 Google, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in write, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
def list_buckets project_id: | ||
# [START list_buckets] | ||
# project_id = "Your Google Cloud project ID" | ||
|
||
require "google/cloud" | ||
|
||
gcloud = Google::Cloud.new project_id | ||
storage = gcloud.storage | ||
|
||
storage.buckets.each do |bucket| | ||
puts bucket.name | ||
end | ||
# [END list_buckets] | ||
end | ||
|
||
def create_bucket project_id:, bucket_name: | ||
# [START create_bucket] | ||
# project_id = "Your Google Cloud project ID" | ||
# bucket_name = "Name of Google Cloud Storage bucket to create" | ||
|
||
require "google/cloud" | ||
|
||
gcloud = Google::Cloud.new project_id | ||
storage = gcloud.storage | ||
bucket = storage.create_bucket bucket_name | ||
|
||
puts "Created bucket: #{bucket.name}" | ||
# [END create_bucket] | ||
end | ||
|
||
def delete_bucket project_id:, bucket_name: | ||
# [START delete_bucket] | ||
# project_id = "Your Google Cloud project ID" | ||
# bucket_name = "Name of your Google Cloud Storage bucket to delete" | ||
|
||
require "google/cloud" | ||
|
||
gcloud = Google::Cloud.new project_id | ||
storage = gcloud.storage | ||
bucket = storage.bucket bucket_name | ||
|
||
bucket.delete | ||
|
||
puts "Deleted bucket: #{bucket.name}" | ||
# [END delete_bucket] | ||
end | ||
|
||
if __FILE__ == $0 | ||
case ARGV.shift | ||
when "list" | ||
list_buckets project_id: ENV["GCLOUD_PROJECT"] | ||
when "create" | ||
create_bucket project_id: ENV["GCLOUD_PROJECT"], | ||
bucket_name: ARGV.shift | ||
when "delete" | ||
delete_bucket project_id: ENV["GCLOUD_PROJECT"], | ||
bucket_name: ARGV.shift | ||
else | ||
puts <<-usage | ||
Usage: bundle exec ruby buckets.rb [command] [arguments] | ||
Commands: | ||
list List all buckets in the authenticated project | ||
create <bucket> Create a new bucket with the provided name | ||
delete <bucket> Delete bucket with the provided name | ||
Environment variables: | ||
GCLOUD_PROJECT must be set to your Google Cloud project ID | ||
usage | ||
end | ||
end |
Oops, something went wrong.