gcloud 0.7.2 → 0.8.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
- ODI3ODU0YWQzNDU0MmNlZjU1ZDM4NzgwM2ViOWM3YTliYWY4NTllMg==
4
+ ZmFhODViYTg5Nzc4Yjg0ZDJmMGFlZjQ3MmNiYTZjYWNlOTdlMjI5Zg==
5
5
  data.tar.gz: !binary |-
6
- MTI3Y2U4MjA5ZmRjYjQ0YjllYzNlYmJlYmUzZmY5MjQ2NWVjYzJjNg==
6
+ ZDI5YjQ0YjRlMDE1YTNmYTNmMjYyN2I0ZTIzZTQyMjllNDljMTAwZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2MzZjYyYTc3N2U1YTQxY2IwOTQ3OGQ5MjRhMjM3MWIxNmYyYTgxNzJmZjQx
10
- YjNmYjI1OWY5NmFmNjZlZjk4NGVkZWFkMGViMjI3ZDNmYjMzOTM4YzdhNGI0
11
- MzdiM2I5YTVjMDdmNTU2Yzk2Y2FiM2RjOGEyYjI1YTE1MzYxMjg=
9
+ ZTNkNDUxZTIzZWFkMjFkZmI2ODBjZDc1NWE2YjBlYmYwODUzMmU1Y2M4OTZl
10
+ MDBhYTI1YmI5NjI4N2QwODJmYzM4MTFkNDAwY2Y1MWFhYmJjYTlhMGQxNWE0
11
+ ZDQ1YzIyMjE4MTIxN2NjM2NkMTYzYzc5ZGQ5ZTQwZGQwOWVhNTM=
12
12
  data.tar.gz: !binary |-
13
- M2MwMTIzOWU1ZDFiNzk2M2QzMDg4NmE2ZWYyOTViYjYzMGU5MDIyYTVhNGVl
14
- ODA4NTNhNWFiZWI5NjkxYmUzNGYyMTZjYTM2MDEzNGFkNjU1OGM3MGExZmQ2
15
- N2Q0MTAxMTFiZWZhMzI4YjQ3Nzc0NTAzMjk5ZWI1NGY5ZDViYzM=
13
+ MjBlNTAxNTBkYzVmMjA0MTBjZTNjZWE2NmM4OGZmMzE0NTM3Nzg5YTdiNjE5
14
+ ZmE0ODVhMDQxNGUwNjg0NjViYmFhNGU3OWYxNWY3ZWY0MWExNjhhMjExOTQx
15
+ YjhkNDUxOTQwODliYjAxMDM5ZTZlZDhjYmFiNzE4NWVhMTc0NTc=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Release History
2
2
 
3
+ ### 0.8.0 / 2016-04-28
4
+
5
+ #### Major changes
6
+
7
+ * Add support for Translate API
8
+ * Drop support for Search service
9
+
10
+ #### Minor changes
11
+
12
+ * Pub/Sub
13
+ * Add support for emulator (dlorenc)
14
+ * Datastore
15
+ * Fix bug where entities were not properly marked persisted after being saved
16
+ * Fix bug in transaction delete accepting keys (timanovsky)
17
+ * Update access token logic to avoid expired credentials (timanovsky)
18
+
3
19
  ### 0.7.2 / 2016-04-01
4
20
 
5
21
  #### Changes
data/OVERVIEW.md CHANGED
@@ -191,24 +191,6 @@ end
191
191
  projects = resource_manager.projects filter: "labels.env:production"
192
192
  ```
193
193
 
194
- # Search
195
-
196
- [Google Cloud Search](https://cloud.google.com/search/) ([docs](https://cloud.google.com/search/reference/rest/index)) allows an application to quickly perform full-text and geo-spatial searches without having to spin up instances and without the hassle of managing and maintaining a search service.
197
-
198
- See the {Gcloud::Search gcloud-ruby Search API documentation} to learn how to connect to Cloud Search using this library.
199
-
200
- ```ruby
201
- require "gcloud"
202
-
203
- gcloud = Gcloud.new
204
- search = gcloud.search
205
- index = search.index "products"
206
-
207
- results = index.search "cotton T-shirt",
208
- expressions: { total_price: "(price + tax)" },
209
- fields: ["name", "total_price", "highlight"]
210
- ```
211
-
212
194
  # Storage
213
195
 
214
196
  [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.
@@ -232,3 +214,26 @@ file.download "/tasks/attachments/#{file.name}"
232
214
  backup = storage.bucket "task-attachment-backups"
233
215
  file.copy backup, file.name
234
216
  ```
217
+
218
+ # Translate
219
+
220
+ [Google Translate](https://cloud.google.com/translate/) ([docs](https://cloud.google.com/translate/docs)) provides a simple, programmatic interface for translating an arbitrary string into any supported language. It is highly responsive, so websites and applications can integrate with Translate API for fast, dynamic translation of source text. Language detection is also available in cases where the source language is unknown.
221
+
222
+ See the {Gcloud::Translate gcloud-ruby Translate API documentation} to learn how to connect to Google Translate using this library.
223
+
224
+ ```ruby
225
+ require "gcloud"
226
+
227
+ gcloud = Gcloud.new
228
+ translate = gcloud.translate
229
+
230
+ translation = translate.translate "Hello world!", to: "la"
231
+
232
+ puts translation #=> Salve mundi!
233
+
234
+ translation.from #=> "en"
235
+ translation.origin #=> "Hello world!"
236
+ translation.to #=> "la"
237
+ translation.text #=> "Salve mundi!"
238
+ ```
239
+
data/lib/gcloud.rb CHANGED
@@ -311,33 +311,6 @@ module Gcloud
311
311
 
312
312
  # rubocop:enable Metrics/LineLength
313
313
 
314
- ##
315
- # Creates a new object for connecting to the Search service.
316
- # Each call creates a new connection.
317
- #
318
- # For more information on connecting to Google Cloud see the [Authentication
319
- # Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
320
- #
321
- # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
322
- # set of resources and operations that the connection can access. See [Using
323
- # OAuth 2.0 to Access Google
324
- # APIs](https://developers.google.com/identity/protocols/OAuth2).
325
- #
326
- # The default scopes are:
327
- #
328
- # * `https://www.googleapis.com/auth/cloudsearch`
329
- # * `https://www.googleapis.com/auth/userinfo.email`
330
- #
331
- # @return [Gcloud::Search::Project]
332
- #
333
- # @example
334
- # require "gcloud"
335
- #
336
- def search scope: nil
337
- require "gcloud/search"
338
- Gcloud.search @project, @keyfile, scope: scope
339
- end
340
-
341
314
  ##
342
315
  # Creates a new object for connecting to the Logging service.
343
316
  # Each call creates a new connection.
@@ -374,4 +347,45 @@ module Gcloud
374
347
  require "gcloud/logging"
375
348
  Gcloud.logging @project, @keyfile, scope: scope
376
349
  end
350
+
351
+ ##
352
+ # Creates a new object for connecting to the Translate service.
353
+ # Each call creates a new connection.
354
+ #
355
+ # Unlike other Cloud Platform services, which authenticate using a project ID
356
+ # and OAuth 2.0 credentials, Google Translate API requires a public API access
357
+ # key. (This may change in future releases of Google Translate API.) Follow
358
+ # the general instructions at [Identifying your application to
359
+ # Google](https://cloud.google.com/translate/v2/using_rest#auth), and the
360
+ # specific instructions for [Server
361
+ # keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
362
+ #
363
+ # @param [String] key a public API access key (not an OAuth 2.0 token)
364
+ #
365
+ # @return [Gcloud::Translate::Api]
366
+ #
367
+ # @example
368
+ # require "gcloud"
369
+ #
370
+ # gcloud = Gcloud.new
371
+ # translate = gcloud.translate "api-key-abc123XYZ789"
372
+ #
373
+ # translation = translate.translate "Hello world!", to: "la"
374
+ # translation.text #=> "Salve mundi!"
375
+ #
376
+ # @example Using API Key from the environment variable.
377
+ # require "gcloud"
378
+ #
379
+ # ENV["TRANSLATE_KEY"] = "api-key-abc123XYZ789"
380
+ #
381
+ # gcloud = Gcloud.new
382
+ # translate = gcloud.translate
383
+ #
384
+ # translation = translate.translate "Hello world!", to: "la"
385
+ # translation.text #=> "Salve mundi!"
386
+ #
387
+ def translate key = nil
388
+ require "gcloud/translate"
389
+ Gcloud.translate key
390
+ end
377
391
  end
@@ -36,7 +36,7 @@ module Gcloud
36
36
  # Sign OAuth 2.0 API calls.
37
37
  def sign_http_request request
38
38
  if @client
39
- @client.fetch_access_token! if @client.expired?
39
+ @client.fetch_access_token! if @client.expires_within? 30
40
40
  @client.generate_authenticated_request request: request
41
41
  end
42
42
  request
@@ -127,6 +127,8 @@ module Gcloud
127
127
  save_entities_to_mutation entities, mutation
128
128
  response = connection.commit mutation
129
129
  auto_id_assign_ids response.mutation_result.insert_auto_id_key
130
+ # Make sure all entity keys are frozen so all show as persisted
131
+ entities.each { |e| e.key.freeze unless e.persisted? }
130
132
  entities
131
133
  end
132
134
 
@@ -45,6 +45,7 @@ module Gcloud
45
45
  #
46
46
  def save *entities
47
47
  save_entities_to_mutation entities, shared_mutation
48
+ @_saved_entities += entities
48
49
  # Do not save or assign auto_ids yet
49
50
  entities
50
51
  end
@@ -59,9 +60,12 @@ module Gcloud
59
60
  # end
60
61
  # end
61
62
  #
62
- def delete *entities
63
+ def delete *entities_or_keys
64
+ keys = entities_or_keys.map do |e_or_k|
65
+ e_or_k.respond_to?(:key) ? e_or_k.key.to_proto : e_or_k.to_proto
66
+ end
63
67
  shared_mutation.tap do |m|
64
- m.delete = entities.map { |entity| entity.key.to_proto }
68
+ m.delete = keys
65
69
  end
66
70
  # Do not delete yet
67
71
  true
@@ -87,6 +91,8 @@ module Gcloud
87
91
 
88
92
  response = connection.commit shared_mutation, @id
89
93
  auto_id_assign_ids response.mutation_result.insert_auto_id_key
94
+ # Make sure all entity keys are frozen so all show as persisted
95
+ @_saved_entities.each { |e| e.key.freeze unless e.persisted? }
90
96
  true
91
97
  end
92
98
 
@@ -108,6 +114,7 @@ module Gcloud
108
114
  @shared_mutation = nil
109
115
  @id = nil
110
116
  @_auto_id_entities = []
117
+ @_saved_entities = []
111
118
  end
112
119
 
113
120
  protected
data/lib/gcloud/pubsub.rb CHANGED
@@ -49,6 +49,11 @@ module Gcloud
49
49
  #
50
50
  def self.pubsub project = nil, keyfile = nil, scope: nil
51
51
  project ||= Gcloud::Pubsub::Project.default_project
52
+ if ENV["PUBSUB_EMULATOR_HOST"]
53
+ ps = Gcloud::Pubsub::Project.new project, :this_channel_is_insecure
54
+ ps.service.host = ENV["PUBSUB_EMULATOR_HOST"]
55
+ return ps
56
+ end
52
57
  if keyfile.nil?
53
58
  credentials = Gcloud::Pubsub::Credentials.default scope: scope
54
59
  else
@@ -424,6 +429,35 @@ module Gcloud
424
429
  # sub.topic.name #=> "projects/other-project-id/topics/other-topic"
425
430
  # ```
426
431
  #
432
+ # ## Using the Gcloud SDK Emulator
433
+ #
434
+ # To develop and test your application locally, you can use the [Google Cloud
435
+ # Pub/Sub Emulator](https://cloud.google.com/pubsub/emulator), which provides
436
+ # [local
437
+ # emulation](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/) of
438
+ # the production Google Cloud Pub/Sub environment. You can start the Google
439
+ # Cloud Pub/Sub emulator using the `gcloud` command-line tool.
440
+ #
441
+ # To configure your ruby code to use the emulator, set the
442
+ # `PUBSUB_EMULATOR_HOST` environment variable to the host and port where the
443
+ # emulator is running. The value can be set as an environment variable in the
444
+ # shell running the ruby code, or can be set directly in the ruby code as
445
+ # shown below.
446
+ #
447
+ # ```ruby
448
+ # require "gcloud"
449
+ #
450
+ # # Make Pub/Sub use the emulator
451
+ # ENV["PUBSUB_EMULATOR_HOST"] = "localhost:8918"
452
+ #
453
+ # gcloud = Gcloud.new "emulator-project-id"
454
+ # pubsub = gcloud.pubsub
455
+ #
456
+ # # Get a topic in the current project
457
+ # my_topic = pubsub.new_topic "my-topic"
458
+ # my_topic.name #=> "projects/emulator-project-id/topics/my-topic"
459
+ # ```
460
+ #
427
461
  module Pubsub
428
462
  end
429
463
  end
@@ -36,6 +36,7 @@ module Gcloud
36
36
  end
37
37
 
38
38
  def creds
39
+ return credentials if insecure?
39
40
  GRPC::Core::ChannelCredentials.new.compose \
40
41
  GRPC::Core::CallCredentials.new credentials.client.updater_proc
41
42
  end
@@ -58,6 +59,10 @@ module Gcloud
58
59
  end
59
60
  attr_accessor :mocked_iam
60
61
 
62
+ def insecure?
63
+ credentials == :this_channel_is_insecure
64
+ end
65
+
61
66
  ##
62
67
  # Gets the configuration of a topic.
63
68
  # Since the topic only has the name attribute,
@@ -0,0 +1,236 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "gcloud"
17
+ require "gcloud/translate/api"
18
+
19
+ module Gcloud
20
+ ##
21
+ # Creates a new object for connecting to the Translate service.
22
+ # Each call creates a new connection.
23
+ #
24
+ # Unlike other Cloud Platform services, which authenticate using a project ID
25
+ # and OAuth 2.0 credentials, Google Translate API requires a public API access
26
+ # key. (This may change in future releases of Google Translate API.) Follow
27
+ # the general instructions at [Identifying your application to
28
+ # Google](https://cloud.google.com/translate/v2/using_rest#auth), and the
29
+ # specific instructions for [Server
30
+ # keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
31
+ #
32
+ # @param [String] key a public API access key (not an OAuth 2.0 token)
33
+ #
34
+ # @return [Gcloud::Translate::Api]
35
+ #
36
+ # @example
37
+ # require "gcloud"
38
+ #
39
+ # translate = Gcloud.translate "api-key-abc123XYZ789"
40
+ #
41
+ # translation = translate.translate "Hello world!", to: "la"
42
+ # translation.text #=> "Salve mundi!"
43
+ #
44
+ # @example Using API Key from the environment variable.
45
+ # require "gcloud"
46
+ #
47
+ # ENV["TRANSLATE_KEY"] = "api-key-abc123XYZ789"
48
+ #
49
+ # translate = Gcloud.translate
50
+ #
51
+ # translation = translate.translate "Hello world!", to: "la"
52
+ # translation.text #=> "Salve mundi!"
53
+ #
54
+ def self.translate key = nil
55
+ Gcloud::Translate::Api.new key
56
+ end
57
+
58
+ ##
59
+ # # Google Translate API
60
+ #
61
+ # [Google Translate API](https://cloud.google.com/translate/) provides a
62
+ # simple, programmatic interface for translating an arbitrary string into any
63
+ # supported language. It is highly responsive, so websites and applications
64
+ # can integrate with Translate API for fast, dynamic translation of source
65
+ # text. Language detection is also available in cases where the source
66
+ # language is unknown.
67
+ #
68
+ # Translate API supports more than ninety different languages, from Afrikaans
69
+ # to Zulu. Used in combination, this enables translation between thousands of
70
+ # language pairs. Also, you can send in HTML and receive HTML with translated
71
+ # text back. You don't need to extract your source text or reassemble the
72
+ # translated content.
73
+ #
74
+ # ## Authenticating
75
+ #
76
+ # Unlike other Cloud Platform services, which authenticate using a project ID
77
+ # and OAuth 2.0 credentials, Translate API requires a public API access key.
78
+ # (This may change in future releases of Translate API.) Follow the general
79
+ # instructions at [Identifying your application to
80
+ # Google](https://cloud.google.com/translate/v2/using_rest#auth), and the
81
+ # specific instructions for [Server
82
+ # keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
83
+ #
84
+ # ## Translating texts
85
+ #
86
+ # Translating text from one language to another is easy (and extremely fast.)
87
+ # The only required arguments to {Gcloud::Translate::Api#translate} are a
88
+ # string and the [ISO
89
+ # 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code of the
90
+ # language to which you wish to translate.
91
+ #
92
+ # ```ruby
93
+ # require "gcloud"
94
+ #
95
+ # gcloud = Gcloud.new
96
+ # translate = gcloud.translate
97
+ #
98
+ # translation = translate.translate "Hello world!", to: "la"
99
+ #
100
+ # puts translation #=> Salve mundi!
101
+ #
102
+ # translation.from #=> "en"
103
+ # translation.origin #=> "Hello world!"
104
+ # translation.to #=> "la"
105
+ # translation.text #=> "Salve mundi!"
106
+ # ```
107
+ #
108
+ # You may want to use the `from` option to specify the language of the source
109
+ # text, as the following example illustrates. (Single words do not give
110
+ # Translate API much to work with.)
111
+ #
112
+ # ```ruby
113
+ # require "gcloud"
114
+ #
115
+ # gcloud = Gcloud.new
116
+ # translate = gcloud.translate
117
+ #
118
+ # translation = translate.translate "chat", to: "en"
119
+ #
120
+ # translation.detected? #=> true
121
+ # translation.from #=> "en"
122
+ # translation.text #=> "chat"
123
+ #
124
+ # translation = translate.translate "chat", from: "fr", to: "en"
125
+ #
126
+ # translation.detected? #=> false
127
+ # translation.from #=> "fr"
128
+ # translation.text #=> "cat"
129
+ # ```
130
+ #
131
+ # You can pass multiple texts to {Gcloud::Translate::Api#translate}.
132
+ #
133
+ # ```ruby
134
+ # require "gcloud"
135
+ #
136
+ # gcloud = Gcloud.new
137
+ # translate = gcloud.translate
138
+ #
139
+ # translations = translate.translate "chien", "chat", from: "fr", to: "en"
140
+ #
141
+ # translations.size #=> 2
142
+ # translations[0].origin #=> "chien"
143
+ # translations[0].text #=> "dog"
144
+ # translations[1].origin #=> "chat"
145
+ # translations[1].text #=> "cat"
146
+ # ```
147
+ #
148
+ # By default, any HTML in your source text will be preserved.
149
+ #
150
+ # ```ruby
151
+ # require "gcloud"
152
+ #
153
+ # gcloud = Gcloud.new
154
+ # translate = gcloud.translate
155
+ #
156
+ # translation = translate.translate "<strong>Hello</strong> world!",
157
+ # to: :la
158
+ # translation.text #=> "<strong>Salve</strong> mundi!"
159
+ # ```
160
+ #
161
+ # ## Detecting languages
162
+ #
163
+ # You can use {Gcloud::Translate::Api#detect} to see which language the
164
+ # Translate API ranks as the most likely source language for a text. The
165
+ # `confidence` score is a float value between `0` and `1`.
166
+ #
167
+ # ```ruby
168
+ # require "gcloud"
169
+ #
170
+ # gcloud = Gcloud.new
171
+ # translate = gcloud.translate
172
+ #
173
+ # detection = translate.detect "chat"
174
+ #
175
+ # detection.text #=> "chat"
176
+ # detection.language #=> "en"
177
+ # detection.confidence #=> 0.59922177
178
+ # ```
179
+ #
180
+ # You can pass multiple texts to {Gcloud::Translate::Api#detect}.
181
+ #
182
+ # ```ruby
183
+ # require "gcloud"
184
+ #
185
+ # gcloud = Gcloud.new
186
+ # translate = gcloud.translate
187
+ #
188
+ # detections = translate.detect "chien", "chat"
189
+ #
190
+ # detections.size #=> 2
191
+ # detections[0].text #=> "chien"
192
+ # detections[0].language #=> "fr"
193
+ # detections[0].confidence #=> 0.7109375
194
+ # detections[1].text #=> "chat"
195
+ # detections[1].language #=> "en"
196
+ # detections[1].confidence #=> 0.59922177
197
+ # ```
198
+ #
199
+ # ## Listing supported languages
200
+ #
201
+ # Translate API adds new languages frequently. You can use
202
+ # {Gcloud::Translate::Api#languages} to query the list of supported languages.
203
+ #
204
+ # ```ruby
205
+ # require "gcloud"
206
+ #
207
+ # gcloud = Gcloud.new
208
+ # translate = gcloud.translate
209
+ #
210
+ # languages = translate.languages
211
+ #
212
+ # languages.size #=> 104
213
+ # languages[0].code #=> "af"
214
+ # languages[0].name #=> nil
215
+ # ```
216
+ #
217
+ # To receive the names of the supported languages, as well as their [ISO
218
+ # 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes, provide
219
+ # the code for the language in which you wish to receive the names.
220
+ #
221
+ # ```ruby
222
+ # require "gcloud"
223
+ #
224
+ # gcloud = Gcloud.new
225
+ # translate = gcloud.translate
226
+ #
227
+ # languages = translate.languages "en"
228
+ #
229
+ # languages.size #=> 104
230
+ # languages[0].code #=> "af"
231
+ # languages[0].name #=> "Afrikaans"
232
+ # ```
233
+ #
234
+ module Translate
235
+ end
236
+ end