gcloud 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWUyNTJhOGZkZDNmY2E2NTFlOWJkNjRjZTEyNzhmYzkyMjVlY2RlMA==
4
+ MmIyMDI3NTljZjg4NGM3YzA2ODY0YmMwMmE5ZDUwOGJmM2I5MmZlMA==
5
5
  data.tar.gz: !binary |-
6
- MGNhMjVhNjE5Njc5ZmM5NTU4MDlkYjJiYjA0OGQ1MmJjM2M0NDAyNA==
6
+ ZmY3ZTI0NmQ4MWIzMmYyZmZjY2ViYThkZDRlN2MxZjZiODUzNjhiNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzUzYTQ3NWRkMDI1N2U1YTVkMWJkZDZjM2VjYTAxZjYxZGMxMWRlMmRjY2Vi
10
- MmU2MGFlNDI4YTE1NmIzZjg2ODYzOGU3NWUzMDE3YmNmMzU4Y2JiMjMwOGUz
11
- NGU3ZTdmMzM4ZGU2YjAyZmFiOTg4OGZiOGNmMWEwM2Y3YzA4MjA=
9
+ ODE0ZTZjNzI4M2I2MDhlMWYyNTNjYjVhMTIwNzc5NTI2ZmE4MmVlY2NiOGEw
10
+ YjZjMjlkODNjOWNmMWEwZDdlNmMyYWVkNTEzOTgyYzM2NDJiM2YyZWUyOGUy
11
+ NmFmYzEzMzQwYWUzNjc5N2Q0MWRhOWY0ZDIyNjEyYzRkMTU0ODg=
12
12
  data.tar.gz: !binary |-
13
- ZGEwM2NmNTQ0ZjExNjQ4NzhlZGFmODg5NjkwZjhkNjVmMjBmMzJlM2QzZTg5
14
- YTFmOTc5NGVhMzdjZWNjMTY1OTY3OWE0OGE0MGQwM2UzNmY5N2IyZDI1MmQy
15
- NDhjNmZkYzQ3YTUwYWIxZTA1MTk0NGIwZDNiMjMyMDAzZmNiMTY=
13
+ YzFmZGEzYTExZTI4Y2FjN2E4MmRlMjdmNjI5ZGE3Y2Q2Mjk2ZDUwYzcxOWNj
14
+ MDVmZDc1NTI5OWEwN2Y2M2RiYmJmYzJiZTQyNjU5MmY0NDFjZWJlNzM4MGZh
15
+ ZWMzZDkzMDhlMTkzYmU5ZGNkYzUwYmVkY2RlMTEwMWZlYmQ5NzA=
@@ -61,7 +61,7 @@ This option allows for an easy way to authenticate during development. If creden
61
61
  To configure your system for this, simply:
62
62
 
63
63
  1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
64
- 2. Authenticate using OAuth2 `$ gcloud auth login`
64
+ 2. Authenticate using OAuth 2.0 `$ gcloud auth login`
65
65
  3. Write code as if already authenticated.
66
66
 
67
67
  **NOTE:** This is _not_ recommended for running in production. The Cloud SDK should only be used during development.
@@ -1,5 +1,19 @@
1
1
  # Release History
2
2
 
3
+ ### 0.2.0 / 2015-07-22
4
+
5
+ #### Major changes
6
+
7
+ Add Pub/Sub service
8
+
9
+ #### Minor changes
10
+
11
+ * Add top-level `Gcloud` object with instance methods to initialize connections
12
+ with individual services (e.g. `Gcloud#storage`)
13
+ * Add credential options to `Gcloud::Storage::File#signed_url`
14
+ * Add method aliases to improve usability of Storage API
15
+ * Improve documentation
16
+
3
17
  ### 0.1.1 / 2015-06-16
4
18
 
5
19
  * Storage downloads files in binary mode (premist).
@@ -0,0 +1,87 @@
1
+ # Getting started
2
+
3
+ The `gcloud` library is installable through rubygems:
4
+
5
+ ```sh
6
+ $ gem install gcloud
7
+ ```
8
+
9
+ Gcloud aims to make authentication as simple as possible. Google Cloud requires a **Project ID** and **Service Account Credentials** to connect to the APIs. You can learn more about various options for connection on the [Authentication Guide](AUTHENTICATION.md).
10
+
11
+ # Datastore
12
+
13
+ [Google Cloud Datastore](https://cloud.google.com/datastore/) ([docs](https://cloud.google.com/datastore/docs)) is a fully managed, schemaless database for storing non-relational data. Cloud Datastore automatically scales with your users and supports ACID transactions, high availability of reads and writes, strong consistency for reads and ancestor queries, and eventual consistency for all other queries.
14
+
15
+ Follow the [activation instructions](https://cloud.google.com/datastore/docs/activate) to use the Google Cloud Datastore API with your project.
16
+
17
+ See the [gcloud-ruby Datastore API documentation](rdoc-ref:Gcloud::Datastore) to learn how to interact with the Cloud Datastore using this library.
18
+
19
+ ```ruby
20
+ require "gcloud"
21
+
22
+ gcloud = Gcloud.new
23
+ dataset = gcloud.datastore
24
+
25
+ # Create a new task to demo datastore
26
+ demo_task = Gcloud::Datastore::Entity.new
27
+ demo_task.key = Gcloud::Datastore::Key.new "Task", "datastore-demo"
28
+ demo_task[:description] = "Demonstrate Datastore functionality"
29
+ demo_task[:completed] = false
30
+
31
+ # Save the new task
32
+ dataset.save demo_task
33
+
34
+ # Run a query for all completed tasks
35
+ query = Gcloud::Datastore::Query.new.kind("Task").
36
+ where("completed", "=", true)
37
+ completed_tasks = dataset.run query
38
+ ```
39
+
40
+ # Pub/Sub
41
+
42
+ [Google Cloud Pub/Sub](https://cloud.google.com/pubsub/) ([docs](https://cloud.google.com/pubsub/reference/rest/)) is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a “topic” and other applications can subscribe to that topic to receive the messages. By decoupling senders and receivers, Google Cloud Pub/Sub allows developers to communicate between independently written applications.
43
+
44
+ See the [gcloud-ruby Pub/Sub API documentation](rdoc-ref:Gcloud::Pubsub) to learn how to connect to Cloud Pub/Sub using this library.
45
+
46
+ ```ruby
47
+ require "gcloud"
48
+
49
+ gcloud = Gcloud.new
50
+ pubsub = gcloud.pubsub
51
+
52
+ # Retrieve a topic
53
+ topic = pubsub.topic "my-topic"
54
+
55
+ # Publish a new message
56
+ msg = topic.publish "new-message"
57
+
58
+ # Retrieve a subscription
59
+ sub = pubsub.subscription "my-topic-sub"
60
+
61
+ # Pull available messages
62
+ msgs = sub.pull
63
+ ```
64
+
65
+ # Storage
66
+
67
+ [Google Cloud Storage](https://cloud.google.com/storage/) ([docs](https://cloud.google.com/storage/docs/json_api/)) allows you to store data on Google infrastructure with very high reliability, performance and availability, and can be used to distribute large data objects to users via direct download.
68
+
69
+ See the [gcloud-ruby Storage API documentation](rdoc-ref:Gcloud::Storage) to learn how to connect to Cloud Storage using this library.
70
+
71
+ ```ruby
72
+ require "gcloud"
73
+
74
+ gcloud = Gcloud.new
75
+ storage = gcloud.storage
76
+
77
+ bucket = storage.bucket "task-attachments"
78
+
79
+ file = bucket.file "path/to/my-file.ext"
80
+
81
+ # Download the file to the local file system
82
+ file.download "/tasks/attachments/#{file.name}"
83
+
84
+ # Copy the file to a backup bucket
85
+ backup = storage.bucket "task-attachment-backups"
86
+ file.copy backup, file.name
87
+ ```
@@ -31,6 +31,112 @@ require "gcloud/version"
31
31
  # {Authentication Guide}[AUTHENTICATION.md].
32
32
  #
33
33
  module Gcloud
34
+ ##
35
+ # Creates a new object for connecting to Google Cloud.
36
+ #
37
+ # === Parameters
38
+ #
39
+ # +project+::
40
+ # Project identifier for the Pub/Sub service you are connecting to.
41
+ # (+String+)
42
+ # +keyfile+::
43
+ # Keyfile downloaded from Google Cloud. If file path the file must be
44
+ # readable. (+String+ or +Hash+)
45
+ #
46
+ # === Returns
47
+ #
48
+ # Gcloud
49
+ #
50
+ # === Example
51
+ #
52
+ # require "gcloud"
53
+ #
54
+ # gcloud = Gcloud.new
55
+ # dataset = gcloud.datastore
56
+ # pubsub = gcloud.pubsub
57
+ # storage = gcloud.storage
58
+ #
59
+ def self.new project = nil, keyfile = nil
60
+ gcloud = Object.new
61
+ gcloud.instance_eval do
62
+ @project = project
63
+ @keyfile = keyfile
64
+ end
65
+ gcloud.extend Gcloud
66
+ gcloud
67
+ end
68
+
69
+ ##
70
+ # Creates a new object for connecting to the Datastore service.
71
+ # Each call creates a new connection.
72
+ #
73
+ # === Returns
74
+ #
75
+ # Gcloud::Datastore::Dataset
76
+ #
77
+ # === Example
78
+ #
79
+ # require "gcloud"
80
+ #
81
+ # gcloud = Gcloud.new
82
+ # dataset = gcloud.datastore
83
+ #
84
+ # entity = Gcloud::Datastore::Entity.new
85
+ # entity.key = Gcloud::Datastore::Key.new "Task"
86
+ # entity["description"] = "Get started with Google Cloud"
87
+ # entity["completed"] = false
88
+ #
89
+ # dataset.save entity
90
+ #
91
+ def datastore
92
+ require "gcloud/datastore"
93
+ Gcloud.datastore @project, @keyfile
94
+ end
95
+
96
+ ##
97
+ # Creates a new object for connecting to the Storage service.
98
+ # Each call creates a new connection.
99
+ #
100
+ # === Returns
101
+ #
102
+ # Gcloud::Storage::Project
103
+ #
104
+ # === Example
105
+ #
106
+ # require "gcloud"
107
+ #
108
+ # gcloud = Gcloud.new
109
+ # storage = gcloud.storage
110
+ # bucket = storage.bucket "my-bucket"
111
+ # file = bucket.file "path/to/my-file.ext"
112
+ #
113
+ def storage
114
+ require "gcloud/storage"
115
+ Gcloud.storage @project, @keyfile
116
+ end
117
+
118
+ ##
119
+ # Creates a new object for connecting to the Pub/Sub service.
120
+ # Each call creates a new connection.
121
+ #
122
+ # === Returns
123
+ #
124
+ # Gcloud::Pubsub::Project
125
+ #
126
+ # === Example
127
+ #
128
+ # require "gcloud"
129
+ #
130
+ # gcloud = Gcloud.new
131
+ # pubsub = gcloud.pubsub
132
+ # topic = pubsub.topic "my-topic"
133
+ # topic.publish "task completed"
134
+ #
135
+ def pubsub
136
+ require "gcloud/pubsub"
137
+ Gcloud.pubsub @project, @keyfile
138
+ end
139
+
34
140
  ##
35
141
  # Base Gcloud exception class.
36
142
  class Error < StandardError
@@ -22,7 +22,7 @@ require "googleauth"
22
22
  # Google Cloud Credentials
23
23
  module Gcloud
24
24
  ##
25
- # Represents the Oauth2 signing logic.
25
+ # Represents the OAuth 2.0 signing logic.
26
26
  # This class is intended to be inherited by API-specific classes
27
27
  # which overrides the SCOPE constant.
28
28
  class Credentials #:nodoc:
@@ -40,7 +40,7 @@ module Gcloud
40
40
  #
41
41
  # === Example
42
42
  #
43
- # require "glcoud/datastore"
43
+ # require "gcloud/datastore"
44
44
  #
45
45
  # dataset = Gcloud.datastore "my-todo-project",
46
46
  # "/path/to/keyfile.json"
@@ -71,15 +71,16 @@ module Gcloud
71
71
  # make the most of using Datastore.
72
72
  #
73
73
  # Gcloud's goal is to provide a API that is familiar and comfortable to
74
- # Rubyists. Authentication is handled by Gcloud.datastore. You can provide
74
+ # Rubyists. Authentication is handled by Gcloud#datastore. You can provide
75
75
  # the project and credential information to connect to the Datastore service,
76
76
  # or if you are running on Google Compute Engine this configuration is taken
77
77
  # care of for you.
78
78
  #
79
- # require "glcoud/datastore"
79
+ # require "gcloud"
80
80
  #
81
- # dataset = Gcloud.datastore "my-todo-project",
82
- # "/path/to/keyfile.json"
81
+ # gcloud = Gcloud.new "my-todo-project",
82
+ # "/path/to/keyfile.json"
83
+ # dataset = gcloud.datastore
83
84
  # entity = dataset.find "Task", "start"
84
85
  # entity["completed"] = true
85
86
  # dataset.save entity
@@ -100,16 +101,18 @@ module Gcloud
100
101
  # <tt>name</tt> value. A single record can be retrieved by calling
101
102
  # Gcloud::Datastore::Dataset#find and passing the parts of the key:
102
103
  #
103
- # require "glcoud/datastore"
104
+ # require "gcloud"
104
105
  #
105
- # dataset = Gcloud.datastore
106
+ # gcloud = Gcloud.new
107
+ # dataset = gcloud.datastore
106
108
  # entity = dataset.find "Task", "start"
107
109
  #
108
110
  # Optionally, Gcloud::Datastore::Dataset#find can be given a Key object:
109
111
  #
110
- # require "glcoud/datastore"
112
+ # require "gcloud"
111
113
  #
112
- # dataset = Gcloud.datastore
114
+ # gcloud = Gcloud.new
115
+ # dataset = gcloud.datastore
113
116
  # key = Gcloud::Datastore::Key.new "Task", 12345
114
117
  # entity = dataset.find key
115
118
  #
@@ -120,9 +123,10 @@ module Gcloud
120
123
  # Multiple records can be found that match criteria.
121
124
  # (See Gcloud::Datastore::Query#where)
122
125
  #
123
- # require "glcoud/datastore"
126
+ # require "gcloud"
124
127
  #
125
- # dataset = Gcloud.datastore
128
+ # gcloud = Gcloud.new
129
+ # dataset = gcloud.datastore
126
130
  # query = Gcloud::Datastore::Query.new
127
131
  # query.kind("List").
128
132
  # where("active", "=", true)
@@ -130,9 +134,10 @@ module Gcloud
130
134
  #
131
135
  # Records can also be ordered. (See Gcloud::Datastore::Query#order)
132
136
  #
133
- # require "glcoud/datastore"
137
+ # require "gcloud"
134
138
  #
135
- # dataset = Gcloud.datastore
139
+ # gcloud = Gcloud.new
140
+ # dataset = gcloud.datastore
136
141
  # query = Gcloud::Datastore::Query.new
137
142
  # query.kind("List").
138
143
  # where("active", "=", true).
@@ -142,9 +147,10 @@ module Gcloud
142
147
  # The number of records returned can be specified.
143
148
  # (See Gcloud::Datastore::Query#limit)
144
149
  #
145
- # require "glcoud/datastore"
150
+ # require "gcloud"
146
151
  #
147
- # dataset = Gcloud.datastore
152
+ # gcloud = Gcloud.new
153
+ # dataset = gcloud.datastore
148
154
  # query = Gcloud::Datastore::Query.new
149
155
  # query.kind("List").
150
156
  # where("active", "=", true).
@@ -155,9 +161,10 @@ module Gcloud
155
161
  # Records' Key structures can also be queried.
156
162
  # (See Gcloud::Datastore::Query#ancestor)
157
163
  #
158
- # require "glcoud/datastore"
164
+ # require "gcloud"
159
165
  #
160
- # dataset = Gcloud.datastore
166
+ # gcloud = Gcloud.new
167
+ # dataset = gcloud.datastore
161
168
  #
162
169
  # list = dataset.find "List", "todos"
163
170
  # query = Gcloud::Datastore::Query.new
@@ -173,9 +180,10 @@ module Gcloud
173
180
  # to return them all. The returned records will have a <tt>cursor</tt> if
174
181
  # there are more available.
175
182
  #
176
- # require "glcoud/datastore"
183
+ # require "gcloud"
177
184
  #
178
- # dataset = Gcloud.datastore
185
+ # gcloud = Gcloud.new
186
+ # dataset = gcloud.datastore
179
187
  #
180
188
  # list = dataset.find "List", "todos"
181
189
  # query = Gcloud::Datastore::Query.new
@@ -204,9 +212,10 @@ module Gcloud
204
212
  # The entity must have a Key to be saved. If the Key is incomplete then
205
213
  # it will be completed when saved.
206
214
  #
207
- # require "glcoud/datastore"
215
+ # require "gcloud"
208
216
  #
209
- # dataset = Gcloud.datastore
217
+ # gcloud = Gcloud.new
218
+ # dataset = gcloud.datastore
210
219
  # entity = Gcloud::Datastore::Entity.new
211
220
  # entity.key = Gcloud::Datastore::Key.new "User"
212
221
  # entity["name"] = "Heidi Henderson"
@@ -221,10 +230,11 @@ module Gcloud
221
230
  # String, Integer, Date, Time, and even other Entity or Key objects. Changes
222
231
  # to the Entity's properties are persisted by calling Dataset#save.
223
232
  #
224
- # require "glcoud/datastore"
233
+ # require "gcloud"
225
234
  #
226
- # dataset = Gcloud.datastore
227
- # entity = datastore.find "User", "heidi"
235
+ # gcloud = Gcloud.new
236
+ # dataset = gcloud.datastore
237
+ # entity = dataset.find "User", "heidi"
228
238
  # # Read the status property
229
239
  # entity["status"] #=> "inactive"
230
240
  # # Write the status property
@@ -237,10 +247,11 @@ module Gcloud
237
247
  # Entities can be removed from Datastore by calling Dataset#delete and passing
238
248
  # the Entity object or the entity's Key object.
239
249
  #
240
- # require "glcoud/datastore"
250
+ # require "gcloud"
241
251
  #
242
- # dataset = Gcloud.datastore
243
- # entity = datastore.find "User", "heidi"
252
+ # gcloud = Gcloud.new
253
+ # dataset = gcloud.datastore
254
+ # entity = dataset.find "User", "heidi"
244
255
  # dataset.delete entity
245
256
  #
246
257
  # == Transactions
@@ -249,9 +260,10 @@ module Gcloud
249
260
  # within the Dataset#transaction block are run within the transaction scope,
250
261
  # and will be automatically committed when the block completes.
251
262
  #
252
- # require "gcloud/datastore"
263
+ # require "gcloud"
253
264
  #
254
- # dataset = Gcloud.datastore
265
+ # gcloud = Gcloud.new
266
+ # dataset = gcloud.datastore
255
267
  #
256
268
  # key = Gcloud::Datastore::Key.new "User", "heidi"
257
269
  #
@@ -269,9 +281,10 @@ module Gcloud
269
281
  # Alternatively, if no block is given the transaction object is returned
270
282
  # allowing you to commit or rollback manually.
271
283
  #
272
- # require "gcloud/datastore"
284
+ # require "gcloud"
273
285
  #
274
- # dataset = Gcloud.datastore
286
+ # gcloud = Gcloud.new
287
+ # dataset = gcloud.datastore
275
288
  #
276
289
  # key = Gcloud::Datastore::Key.new "User", "heidi"
277
290
  #
@@ -30,7 +30,7 @@ module Gcloud
30
30
  JSON_ENV_VARS = %w(DATASTORE_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON)
31
31
 
32
32
  ##
33
- # Sign Oauth2 API calls.
33
+ # Sign OAuth 2.0 API calls.
34
34
  def sign_http_request request #:nodoc:
35
35
  if @client
36
36
  @client.fetch_access_token! if @client.expired?