gcloud 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.md +36 -0
  3. data/lib/gcloud/backoff.rb +5 -5
  4. data/lib/gcloud/bigquery.rb +24 -0
  5. data/lib/gcloud/bigquery/connection.rb +32 -25
  6. data/lib/gcloud/bigquery/data.rb +99 -1
  7. data/lib/gcloud/bigquery/dataset.rb +5 -13
  8. data/lib/gcloud/bigquery/dataset/list.rb +124 -2
  9. data/lib/gcloud/bigquery/job/list.rb +125 -2
  10. data/lib/gcloud/bigquery/project.rb +30 -27
  11. data/lib/gcloud/bigquery/query_data.rb +102 -1
  12. data/lib/gcloud/bigquery/table.rb +17 -2
  13. data/lib/gcloud/bigquery/table/list.rb +132 -3
  14. data/lib/gcloud/datastore.rb +30 -19
  15. data/lib/gcloud/datastore/dataset.rb +2 -22
  16. data/lib/gcloud/datastore/dataset/lookup_results.rb +160 -4
  17. data/lib/gcloud/datastore/dataset/query_results.rb +229 -23
  18. data/lib/gcloud/datastore/transaction.rb +2 -5
  19. data/lib/gcloud/dns.rb +20 -0
  20. data/lib/gcloud/dns/change/list.rb +109 -6
  21. data/lib/gcloud/dns/connection.rb +18 -9
  22. data/lib/gcloud/dns/project.rb +4 -8
  23. data/lib/gcloud/dns/record/list.rb +96 -13
  24. data/lib/gcloud/dns/zone.rb +9 -24
  25. data/lib/gcloud/dns/zone/list.rb +102 -5
  26. data/lib/gcloud/dns/zone/transaction.rb +1 -1
  27. data/lib/gcloud/logging.rb +19 -0
  28. data/lib/gcloud/logging/entry/list.rb +83 -14
  29. data/lib/gcloud/logging/metric/list.rb +89 -12
  30. data/lib/gcloud/logging/project.rb +18 -30
  31. data/lib/gcloud/logging/resource_descriptor/list.rb +105 -6
  32. data/lib/gcloud/logging/sink/list.rb +89 -12
  33. data/lib/gcloud/pubsub.rb +23 -0
  34. data/lib/gcloud/pubsub/project.rb +21 -29
  35. data/lib/gcloud/pubsub/service.rb +1 -3
  36. data/lib/gcloud/pubsub/subscription/list.rb +167 -13
  37. data/lib/gcloud/pubsub/topic.rb +15 -13
  38. data/lib/gcloud/pubsub/topic/batch.rb +10 -4
  39. data/lib/gcloud/pubsub/topic/list.rb +134 -8
  40. data/lib/gcloud/resource_manager.rb +24 -0
  41. data/lib/gcloud/resource_manager/connection.rb +18 -9
  42. data/lib/gcloud/resource_manager/manager.rb +7 -4
  43. data/lib/gcloud/resource_manager/project/list.rb +93 -14
  44. data/lib/gcloud/storage.rb +63 -0
  45. data/lib/gcloud/storage/bucket.rb +100 -61
  46. data/lib/gcloud/storage/bucket/list.rb +132 -8
  47. data/lib/gcloud/storage/connection.rb +68 -44
  48. data/lib/gcloud/storage/errors.rb +9 -3
  49. data/lib/gcloud/storage/file.rb +48 -4
  50. data/lib/gcloud/storage/file/list.rb +151 -15
  51. data/lib/gcloud/storage/file/verifier.rb +3 -3
  52. data/lib/gcloud/storage/project.rb +15 -30
  53. data/lib/gcloud/translate.rb +20 -0
  54. data/lib/gcloud/translate/connection.rb +12 -3
  55. data/lib/gcloud/version.rb +1 -1
  56. data/lib/gcloud/vision.rb +20 -0
  57. data/lib/gcloud/vision/connection.rb +10 -1
  58. data/lib/gcloud/vision/image.rb +15 -18
  59. metadata +16 -2
@@ -38,7 +38,7 @@ module Gcloud
38
38
  gcloud_digest = gcloud_file.crc32c
39
39
  local_digest = crc32c_for local_file
40
40
  if gcloud_digest != local_digest
41
- fail FileVerificationError.for_md5(gcloud_digest, local_digest)
41
+ fail FileVerificationError.for_crc32c(gcloud_digest, local_digest)
42
42
  end
43
43
  end
44
44
 
@@ -52,13 +52,13 @@ module Gcloud
52
52
 
53
53
  def self.md5_for local_file
54
54
  ::File.open(Pathname(local_file).to_path, "rb") do |f|
55
- ::Digest::MD5.base64digest f.read
55
+ ::Digest::MD5.file(f).base64digest
56
56
  end
57
57
  end
58
58
 
59
59
  def self.crc32c_for local_file
60
60
  ::File.open(Pathname(local_file).to_path, "rb") do |f|
61
- ::Digest::CRC32c.base64digest f.read
61
+ ::Digest::CRC32c.file(f).base64digest
62
62
  end
63
63
  end
64
64
  end
@@ -109,37 +109,33 @@ module Gcloud
109
109
  # puts bucket.name
110
110
  # end
111
111
  #
112
- # @example Retrieve all buckets with names that begin with a given prefix:
112
+ # @example Retrieve buckets with names that begin with a given prefix:
113
113
  # require "gcloud"
114
114
  #
115
115
  # gcloud = Gcloud.new
116
116
  # storage = gcloud.storage
117
117
  #
118
118
  # user_buckets = storage.buckets prefix: "user-"
119
+ # user_buckets.each do |bucket|
120
+ # puts bucket.name
121
+ # end
119
122
  #
120
- # @example With pagination: (See {Bucket::List#token})
123
+ # @example Retrieve all buckets: (See {Bucket::List#all})
121
124
  # require "gcloud"
122
125
  #
123
126
  # gcloud = Gcloud.new
124
127
  # storage = gcloud.storage
125
128
  #
126
- # all_buckets = []
127
- # tmp_buckets = storage.buckets
128
- # while tmp_buckets.any? do
129
- # tmp_buckets.each do |bucket|
130
- # all_buckets << bucket
131
- # end
132
- # # break loop if no more buckets available
133
- # break if tmp_buckets.token.nil?
134
- # # get the next group of buckets
135
- # tmp_buckets = storage.buckets token: tmp_buckets.token
129
+ # buckets = storage.buckets
130
+ # buckets.all do |bucket|
131
+ # puts bucket.name
136
132
  # end
137
133
  #
138
134
  def buckets prefix: nil, token: nil, max: nil
139
135
  options = { prefix: prefix, token: token, max: max }
140
136
  resp = connection.list_buckets options
141
137
  if resp.success?
142
- Bucket::List.from_response resp, connection
138
+ Bucket::List.from_response resp, connection, prefix, max
143
139
  else
144
140
  fail ApiError.from_response(resp)
145
141
  end
@@ -180,8 +176,7 @@ module Gcloud
180
176
  # bucket. See {Bucket::Cors} for details.
181
177
  #
182
178
  # The API call to create the bucket may be retried under certain
183
- # conditions. See {Gcloud::Backoff} to control this behavior, or
184
- # specify the wanted behavior in the call with the `:retries:` option.
179
+ # conditions. See {Gcloud::Backoff} to control this behavior.
185
180
  #
186
181
  # You can pass [website
187
182
  # settings](https://cloud.google.com/storage/docs/website-configuration)
@@ -245,8 +240,6 @@ module Gcloud
245
240
  # . By default, the object prefix is the name of the bucket for which
246
241
  # the logs are enabled. For more information, see [Access
247
242
  # Logs](https://cloud.google.com/storage/docs/access-logs).
248
- # @param [Integer] retries The number of times the API call should be
249
- # retried. Default is {Gcloud::Backoff.retries}.
250
243
  # @param [Symbol, String] storage_class Defines how objects in the bucket
251
244
  # are stored and determines the SLA and the cost of storage. Values
252
245
  # include `:standard`, `:nearline`, and `:dra` (Durable Reduced
@@ -280,14 +273,6 @@ module Gcloud
280
273
  #
281
274
  # bucket = storage.create_bucket "my-bucket"
282
275
  #
283
- # @example Specify the number of retries to attempt:
284
- # require "gcloud"
285
- #
286
- # gcloud = Gcloud.new
287
- # storage = gcloud.storage
288
- #
289
- # bucket = storage.create_bucket "my-bucket", retries: 5
290
- #
291
276
  # @example Add CORS rules in a block:
292
277
  # require "gcloud"
293
278
  #
@@ -307,13 +292,13 @@ module Gcloud
307
292
  #
308
293
  def create_bucket bucket_name, acl: nil, default_acl: nil, cors: nil,
309
294
  location: nil, logging_bucket: nil, logging_prefix: nil,
310
- retries: nil, storage_class: nil, versioning: nil,
311
- website_main: nil, website_404: nil
295
+ storage_class: nil, versioning: nil, website_main: nil,
296
+ website_404: nil
312
297
  opts = { acl: acl_rule(acl), default_acl: acl_rule(default_acl),
313
298
  cors: cors, location: location, logging_bucket: logging_bucket,
314
- logging_prefix: logging_prefix, retries: retries,
315
- storage_class: storage_class, versioning: versioning,
316
- website_main: website_main, website_404: website_404 }
299
+ logging_prefix: logging_prefix, storage_class: storage_class,
300
+ versioning: versioning, website_main: website_main,
301
+ website_404: website_404 }
317
302
  if block_given?
318
303
  cors_builder = Bucket::Cors.new
319
304
  yield cors_builder
@@ -231,6 +231,26 @@ module Gcloud
231
231
  # languages[0].name #=> "Afrikaans"
232
232
  # ```
233
233
  #
234
+ # ## Configuring Backoff
235
+ #
236
+ # The {Gcloud::Backoff} class allows users to globally configure how Cloud API
237
+ # requests are automatically retried in the case of some errors, such as a
238
+ # `500` or `503` status code, or a specific internal error code such as
239
+ # `rateLimitExceeded`.
240
+ #
241
+ # If an API call fails, the response will be inspected to see if the call
242
+ # should be retried. If the response matches the criteria, then the request
243
+ # will be retried after a delay. If another error occurs, the delay will be
244
+ # increased incrementally before a subsequent attempt. The first retry will be
245
+ # delayed one second, the second retry two seconds, and so on.
246
+ #
247
+ # ```ruby
248
+ # require "gcloud"
249
+ # require "gcloud/backoff"
250
+ #
251
+ # Gcloud::Backoff.retries = 5 # Raise the maximum number of retries from 3
252
+ # ```
253
+ #
234
254
  module Translate
235
255
  end
236
256
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
 
16
16
  require "gcloud/version"
17
+ require "gcloud/backoff"
17
18
  require "google/api_client"
18
19
 
19
20
  module Gcloud
@@ -45,14 +46,14 @@ module Gcloud
45
46
  prettyprint: false
46
47
  }.delete_if { |_, v| v.nil? }
47
48
 
48
- @client.execute(
49
+ execute(
49
50
  api_method: @translate.translations.list,
50
51
  parameters: params
51
52
  )
52
53
  end
53
54
 
54
55
  def detect text
55
- @client.execute(
56
+ execute(
56
57
  api_method: @translate.detections.list,
57
58
  parameters: { q: Array(text), prettyprint: false }
58
59
  )
@@ -62,7 +63,7 @@ module Gcloud
62
63
  params = { target: language,
63
64
  prettyprint: false }.delete_if { |_, v| v.nil? }
64
65
 
65
- @client.execute(
66
+ execute(
66
67
  api_method: @translate.languages.list,
67
68
  parameters: params
68
69
  )
@@ -71,6 +72,14 @@ module Gcloud
71
72
  def inspect
72
73
  "#{self.class}(#{@project})"
73
74
  end
75
+
76
+ protected
77
+
78
+ def execute options
79
+ Gcloud::Backoff.new.execute_gapi do
80
+ @client.execute options
81
+ end
82
+ end
74
83
  end
75
84
  end
76
85
  end
@@ -14,5 +14,5 @@
14
14
 
15
15
 
16
16
  module Gcloud
17
- VERSION = "0.10.0"
17
+ VERSION = "0.11.0"
18
18
  end
data/lib/gcloud/vision.rb CHANGED
@@ -239,6 +239,26 @@ module Gcloud
239
239
  # annotation = vision.annotate image, faces: 5
240
240
  # ```
241
241
  #
242
+ # ## Configuring Backoff
243
+ #
244
+ # The {Gcloud::Backoff} class allows users to globally configure how Cloud API
245
+ # requests are automatically retried in the case of some errors, such as a
246
+ # `500` or `503` status code, or a specific internal error code such as
247
+ # `rateLimitExceeded`.
248
+ #
249
+ # If an API call fails, the response will be inspected to see if the call
250
+ # should be retried. If the response matches the criteria, then the request
251
+ # will be retried after a delay. If another error occurs, the delay will be
252
+ # increased incrementally before a subsequent attempt. The first retry will be
253
+ # delayed one second, the second retry two seconds, and so on.
254
+ #
255
+ # ```ruby
256
+ # require "gcloud"
257
+ # require "gcloud/backoff"
258
+ #
259
+ # Gcloud::Backoff.retries = 5 # Raise the maximum number of retries from 3
260
+ # ```
261
+ #
242
262
  module Vision
243
263
  class << self
244
264
  ##
@@ -14,6 +14,7 @@
14
14
 
15
15
 
16
16
  require "gcloud/version"
17
+ require "gcloud/backoff"
17
18
  require "google/api_client"
18
19
 
19
20
  module Gcloud
@@ -40,7 +41,7 @@ module Gcloud
40
41
  end
41
42
 
42
43
  def annotate requests
43
- @client.execute(
44
+ execute(
44
45
  api_method: @vision.images.annotate,
45
46
  body_object: { requests: requests }
46
47
  )
@@ -49,6 +50,14 @@ module Gcloud
49
50
  def inspect
50
51
  "#{self.class}(#{@project})"
51
52
  end
53
+
54
+ protected
55
+
56
+ def execute options
57
+ Gcloud::Backoff.new.execute_gapi do
58
+ @client.execute options
59
+ end
60
+ end
52
61
  end
53
62
  end
54
63
  end
@@ -72,28 +72,19 @@ module Gcloud
72
72
  #
73
73
  # @see {#url?}
74
74
  #
75
- def content?
75
+ def io?
76
76
  !@io.nil?
77
77
  end
78
78
 
79
79
  ##
80
80
  # @private Whether the Image is a URL.
81
81
  #
82
- # @see {#content?}
82
+ # @see {#io?}
83
83
  #
84
84
  def url?
85
85
  !@url.nil?
86
86
  end
87
87
 
88
- ##
89
- # @private The contents of the image, encoded via Base64.
90
- #
91
- # @return [String]
92
- #
93
- def content
94
- @content ||= Base64.encode64 @io.read
95
- end
96
-
97
88
  ##
98
89
  # @private The URL of the image.
99
90
  #
@@ -347,8 +338,14 @@ module Gcloud
347
338
 
348
339
  # @private
349
340
  def to_s
350
- return "(io)" if content?
351
- "(url: #{url})"
341
+ @to_s ||= begin
342
+ if io?
343
+ @io.rewind
344
+ "(#{@io.read(16)}...)"
345
+ else
346
+ "(#{url})"
347
+ end
348
+ end
352
349
  end
353
350
 
354
351
  # @private
@@ -359,8 +356,9 @@ module Gcloud
359
356
  ##
360
357
  # @private The Google API Client object for the Image.
361
358
  def to_gapi
362
- if content?
363
- { content: content }
359
+ if io?
360
+ @io.rewind
361
+ { content: Base64.strict_encode64(@io.read) }
364
362
  elsif url?
365
363
  { source: { gcsImageUri: @url } }
366
364
  else
@@ -371,7 +369,7 @@ module Gcloud
371
369
  ##
372
370
  # @private New Image from a source object.
373
371
  def self.from_source source, vision = nil
374
- if source.is_a?(IO) || source.is_a?(StringIO)
372
+ if source.respond_to?(:read) && source.respond_to?(:rewind)
375
373
  return from_io(source, vision)
376
374
  end
377
375
  # Convert Storage::File objects to the URL
@@ -393,8 +391,7 @@ module Gcloud
393
391
  ##
394
392
  # @private New Image from an IO object.
395
393
  def self.from_io io, vision
396
- if !io.is_a?(IO) && !io.is_a?(StringIO)
397
- puts io.inspect
394
+ if !io.respond_to?(:read) && !io.respond_to?(:rewind)
398
395
  fail ArgumentError, "Cannot create an Image without an IO object"
399
396
  end
400
397
  new.tap do |i|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silvano Luciani
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-19 00:00:00.000000000 Z
13
+ date: 2016-06-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grpc
@@ -194,6 +194,20 @@ dependencies:
194
194
  - - <=
195
195
  - !ruby/object:Gem::Version
196
196
  version: 0.35.1
197
+ - !ruby/object:Gem::Dependency
198
+ name: parser
199
+ requirement: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - <=
202
+ - !ruby/object:Gem::Version
203
+ version: 2.3.0.2
204
+ type: :development
205
+ prerelease: false
206
+ version_requirements: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - <=
209
+ - !ruby/object:Gem::Version
210
+ version: 2.3.0.2
197
211
  - !ruby/object:Gem::Dependency
198
212
  name: httpclient
199
213
  requirement: !ruby/object:Gem::Requirement