Class: Gcloud::Storage::Project
- Inherits:
-
Object
- Object
- Gcloud::Storage::Project
- Defined in:
- lib/gcloud/storage/project.rb
Overview
Represents the Project that the Buckets and Files belong to.
Gcloud::Storage::Project is the main object for interacting with Google Storage. Gcloud::Storage::Bucket objects are created, read, updated, and deleted by Gcloud::Storage::Project.
storage = Gcloud.storage "my-todo-project",
"/path/to/keyfile.json"
bucket = storage.find_bucket "my-bucket"
file = bucket.find_file "path/to/my-file.ext"
See Gcloud.storage
Instance Attribute Summary collapse
-
#connection ⇒ Object
The Connection object.
Instance Method Summary collapse
-
#buckets(options = {}) ⇒ Object
Retrieves a list of buckets for the given project.
-
#create_bucket(bucket_name, options = {}) ⇒ Object
Creates a new bucket.
-
#find_bucket(bucket_name) ⇒ Object
Retrieves bucket by name.
-
#initialize(project, credentials) ⇒ Project
constructor
Creates a new Project instance.
-
#project ⇒ Object
The project identifier.
Constructor Details
#initialize(project, credentials) ⇒ Project
Creates a new Project instance.
See Gcloud.storage
45 46 47 |
# File 'lib/gcloud/storage/project.rb', line 45 def initialize project, credentials #:nodoc: @connection = Connection.new project, credentials end |
Instance Attribute Details
#connection ⇒ Object
The Connection object.
39 40 41 |
# File 'lib/gcloud/storage/project.rb', line 39 def connection @connection end |
Instance Method Details
#buckets(options = {}) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/gcloud/storage/project.rb', line 65 def buckets = {} resp = connection.list_buckets if resp.success? Bucket::List.from_resp resp, connection else fail ApiError.from_response(resp) end end |
#create_bucket(bucket_name, options = {}) ⇒ Object
Creates a new bucket.
bucket = project.create_bucket "my-bucket"
The API call to create the bucket may be retried under certain conditions. See Gcloud::Backoff to control this behavior, or specify the wanted behavior in the call:
bucket = project.create_bucket "my-bucket", retries: 5
See Gcloud::Storage::Bucket
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gcloud/storage/project.rb', line 104 def create_bucket bucket_name, = {} [:acl] = Bucket::Acl.predefined_rule_for [:acl] default_acl = [:default_acl] default_acl = Bucket::DefaultAcl.predefined_rule_for default_acl [:default_acl] = default_acl resp = connection.insert_bucket bucket_name, if resp.success? Bucket.from_gapi resp.data, connection else fail ApiError.from_response(resp) end end |
#find_bucket(bucket_name) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/gcloud/storage/project.rb', line 82 def find_bucket bucket_name resp = connection.get_bucket bucket_name if resp.success? Bucket.from_gapi resp.data, connection else return nil if resp.data["error"]["code"] == 404 fail ApiError.from_response(resp) end end |
#project ⇒ Object
The project identifier.
51 52 53 |
# File 'lib/gcloud/storage/project.rb', line 51 def project connection.project end |