gcloud 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +36 -0
- data/lib/gcloud/backoff.rb +5 -5
- data/lib/gcloud/bigquery.rb +24 -0
- data/lib/gcloud/bigquery/connection.rb +32 -25
- data/lib/gcloud/bigquery/data.rb +99 -1
- data/lib/gcloud/bigquery/dataset.rb +5 -13
- data/lib/gcloud/bigquery/dataset/list.rb +124 -2
- data/lib/gcloud/bigquery/job/list.rb +125 -2
- data/lib/gcloud/bigquery/project.rb +30 -27
- data/lib/gcloud/bigquery/query_data.rb +102 -1
- data/lib/gcloud/bigquery/table.rb +17 -2
- data/lib/gcloud/bigquery/table/list.rb +132 -3
- data/lib/gcloud/datastore.rb +30 -19
- data/lib/gcloud/datastore/dataset.rb +2 -22
- data/lib/gcloud/datastore/dataset/lookup_results.rb +160 -4
- data/lib/gcloud/datastore/dataset/query_results.rb +229 -23
- data/lib/gcloud/datastore/transaction.rb +2 -5
- data/lib/gcloud/dns.rb +20 -0
- data/lib/gcloud/dns/change/list.rb +109 -6
- data/lib/gcloud/dns/connection.rb +18 -9
- data/lib/gcloud/dns/project.rb +4 -8
- data/lib/gcloud/dns/record/list.rb +96 -13
- data/lib/gcloud/dns/zone.rb +9 -24
- data/lib/gcloud/dns/zone/list.rb +102 -5
- data/lib/gcloud/dns/zone/transaction.rb +1 -1
- data/lib/gcloud/logging.rb +19 -0
- data/lib/gcloud/logging/entry/list.rb +83 -14
- data/lib/gcloud/logging/metric/list.rb +89 -12
- data/lib/gcloud/logging/project.rb +18 -30
- data/lib/gcloud/logging/resource_descriptor/list.rb +105 -6
- data/lib/gcloud/logging/sink/list.rb +89 -12
- data/lib/gcloud/pubsub.rb +23 -0
- data/lib/gcloud/pubsub/project.rb +21 -29
- data/lib/gcloud/pubsub/service.rb +1 -3
- data/lib/gcloud/pubsub/subscription/list.rb +167 -13
- data/lib/gcloud/pubsub/topic.rb +15 -13
- data/lib/gcloud/pubsub/topic/batch.rb +10 -4
- data/lib/gcloud/pubsub/topic/list.rb +134 -8
- data/lib/gcloud/resource_manager.rb +24 -0
- data/lib/gcloud/resource_manager/connection.rb +18 -9
- data/lib/gcloud/resource_manager/manager.rb +7 -4
- data/lib/gcloud/resource_manager/project/list.rb +93 -14
- data/lib/gcloud/storage.rb +63 -0
- data/lib/gcloud/storage/bucket.rb +100 -61
- data/lib/gcloud/storage/bucket/list.rb +132 -8
- data/lib/gcloud/storage/connection.rb +68 -44
- data/lib/gcloud/storage/errors.rb +9 -3
- data/lib/gcloud/storage/file.rb +48 -4
- data/lib/gcloud/storage/file/list.rb +151 -15
- data/lib/gcloud/storage/file/verifier.rb +3 -3
- data/lib/gcloud/storage/project.rb +15 -30
- data/lib/gcloud/translate.rb +20 -0
- data/lib/gcloud/translate/connection.rb +12 -3
- data/lib/gcloud/version.rb +1 -1
- data/lib/gcloud/vision.rb +20 -0
- data/lib/gcloud/vision/connection.rb +10 -1
- data/lib/gcloud/vision/image.rb +15 -18
- metadata +16 -2
@@ -502,23 +502,15 @@ module Gcloud
|
|
502
502
|
# puts table.name
|
503
503
|
# end
|
504
504
|
#
|
505
|
-
# @example
|
505
|
+
# @example Retrieve all tables: (See {Table::List#all})
|
506
506
|
# require "gcloud"
|
507
507
|
#
|
508
508
|
# gcloud = Gcloud.new
|
509
509
|
# bigquery = gcloud.bigquery
|
510
510
|
# dataset = bigquery.dataset "my_dataset"
|
511
|
-
#
|
512
|
-
#
|
513
|
-
#
|
514
|
-
# while tmp_tables.any? do
|
515
|
-
# tmp_tables.each do |table|
|
516
|
-
# all_tables << table
|
517
|
-
# end
|
518
|
-
# # break loop if no more tables available
|
519
|
-
# break if tmp_tables.token.nil?
|
520
|
-
# # get the next group of tables
|
521
|
-
# tmp_tables = dataset.tables token: tmp_tables.token
|
511
|
+
# tables = dataset.tables
|
512
|
+
# tables.all do |table|
|
513
|
+
# puts table.name
|
522
514
|
# end
|
523
515
|
#
|
524
516
|
# @!group Table
|
@@ -528,7 +520,7 @@ module Gcloud
|
|
528
520
|
options = { token: token, max: max }
|
529
521
|
resp = connection.list_tables dataset_id, options
|
530
522
|
if resp.success?
|
531
|
-
Table::List.from_response resp, connection
|
523
|
+
Table::List.from_response resp, connection, dataset_id, max
|
532
524
|
else
|
533
525
|
fail ApiError.from_response(resp)
|
534
526
|
end
|
@@ -30,21 +30,143 @@ module Gcloud
|
|
30
30
|
attr_accessor :etag
|
31
31
|
|
32
32
|
##
|
33
|
-
# Create a new Dataset::List with an array of datasets.
|
33
|
+
# @private Create a new Dataset::List with an array of datasets.
|
34
34
|
def initialize arr = []
|
35
35
|
super arr
|
36
36
|
end
|
37
37
|
|
38
|
+
##
|
39
|
+
# Whether there is a next page of datasets.
|
40
|
+
#
|
41
|
+
# @return [Boolean]
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# require "gcloud"
|
45
|
+
#
|
46
|
+
# gcloud = Gcloud.new
|
47
|
+
# bigquery = gcloud.bigquery
|
48
|
+
#
|
49
|
+
# datasets = bigquery.datasets
|
50
|
+
# if datasets.next?
|
51
|
+
# next_datasets = datasets.next
|
52
|
+
# end
|
53
|
+
def next?
|
54
|
+
!token.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Retrieve the next page of datasets.
|
59
|
+
#
|
60
|
+
# @return [Dataset::List]
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# require "gcloud"
|
64
|
+
#
|
65
|
+
# gcloud = Gcloud.new
|
66
|
+
# bigquery = gcloud.bigquery
|
67
|
+
#
|
68
|
+
# datasets = bigquery.datasets
|
69
|
+
# if datasets.next?
|
70
|
+
# next_datasets = datasets.next
|
71
|
+
# end
|
72
|
+
def next
|
73
|
+
return nil unless next?
|
74
|
+
ensure_connection!
|
75
|
+
options = { all: @hidden, token: token, max: @max }
|
76
|
+
resp = @connection.list_datasets options
|
77
|
+
if resp.success?
|
78
|
+
self.class.from_response resp, @connection
|
79
|
+
else
|
80
|
+
fail ApiError.from_response(resp)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Retrieves all datasets by repeatedly loading {#next} until {#next?}
|
86
|
+
# returns `false`. Calls the given block once for each dataset, which is
|
87
|
+
# passed as the parameter.
|
88
|
+
#
|
89
|
+
# An Enumerator is returned if no block is given.
|
90
|
+
#
|
91
|
+
# This method may make several API calls until all datasets are
|
92
|
+
# retrieved. Be sure to use as narrow a search criteria as possible.
|
93
|
+
# Please use with caution.
|
94
|
+
#
|
95
|
+
# @param [Integer] request_limit The upper limit of API requests to make
|
96
|
+
# to load all datasets. Default is no limit.
|
97
|
+
# @yield [dataset] The block for accessing each dataset.
|
98
|
+
# @yieldparam [Dataset] dataset The dataset object.
|
99
|
+
#
|
100
|
+
# @return [Enumerator]
|
101
|
+
#
|
102
|
+
# @example Iterating each result by passing a block:
|
103
|
+
# require "gcloud"
|
104
|
+
#
|
105
|
+
# gcloud = Gcloud.new
|
106
|
+
# bigquery = gcloud.bigquery
|
107
|
+
#
|
108
|
+
# bigquery.datasets.all do |dataset|
|
109
|
+
# puts dataset.name
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# @example Using the enumerator by not passing a block:
|
113
|
+
# require "gcloud"
|
114
|
+
#
|
115
|
+
# gcloud = Gcloud.new
|
116
|
+
# bigquery = gcloud.bigquery
|
117
|
+
#
|
118
|
+
# all_names = bigquery.datasets.all.map do |dataset|
|
119
|
+
# dataset.name
|
120
|
+
# end
|
121
|
+
#
|
122
|
+
# @example Limit the number of API calls made:
|
123
|
+
# require "gcloud"
|
124
|
+
#
|
125
|
+
# gcloud = Gcloud.new
|
126
|
+
# bigquery = gcloud.bigquery
|
127
|
+
#
|
128
|
+
# bigquery.datasets.all(request_limit: 10) do |dataset|
|
129
|
+
# puts dataset.name
|
130
|
+
# end
|
131
|
+
#
|
132
|
+
def all request_limit: nil
|
133
|
+
request_limit = request_limit.to_i if request_limit
|
134
|
+
unless block_given?
|
135
|
+
return enum_for(:all, request_limit: request_limit)
|
136
|
+
end
|
137
|
+
results = self
|
138
|
+
loop do
|
139
|
+
results.each { |r| yield r }
|
140
|
+
if request_limit
|
141
|
+
request_limit -= 1
|
142
|
+
break if request_limit < 0
|
143
|
+
end
|
144
|
+
break unless results.next?
|
145
|
+
results = results.next
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
38
149
|
##
|
39
150
|
# @private New Dataset::List from a response object.
|
40
|
-
def self.from_response resp, conn
|
151
|
+
def self.from_response resp, conn, hidden = nil, max = nil
|
41
152
|
datasets = List.new(Array(resp.data["datasets"]).map do |gapi_object|
|
42
153
|
Dataset.from_gapi gapi_object, conn
|
43
154
|
end)
|
44
155
|
datasets.instance_variable_set "@token", resp.data["nextPageToken"]
|
45
156
|
datasets.instance_variable_set "@etag", resp.data["etag"]
|
157
|
+
datasets.instance_variable_set "@connection", conn
|
158
|
+
datasets.instance_variable_set "@hidden", hidden
|
159
|
+
datasets.instance_variable_set "@max", max
|
46
160
|
datasets
|
47
161
|
end
|
162
|
+
|
163
|
+
protected
|
164
|
+
|
165
|
+
##
|
166
|
+
# Raise an error unless an active connection is available.
|
167
|
+
def ensure_connection!
|
168
|
+
fail "Must have active connection" unless @connection
|
169
|
+
end
|
48
170
|
end
|
49
171
|
end
|
50
172
|
end
|
@@ -33,22 +33,145 @@ module Gcloud
|
|
33
33
|
attr_accessor :total
|
34
34
|
|
35
35
|
##
|
36
|
-
# Create a new Job::List with an array of jobs.
|
36
|
+
# @private Create a new Job::List with an array of jobs.
|
37
37
|
def initialize arr = []
|
38
38
|
super arr
|
39
39
|
end
|
40
40
|
|
41
|
+
##
|
42
|
+
# Whether there is a next page of jobs.
|
43
|
+
#
|
44
|
+
# @return [Boolean]
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# require "gcloud"
|
48
|
+
#
|
49
|
+
# gcloud = Gcloud.new
|
50
|
+
# bigquery = gcloud.bigquery
|
51
|
+
#
|
52
|
+
# jobs = bigquery.jobs
|
53
|
+
# if jobs.next?
|
54
|
+
# next_jobs = jobs.next
|
55
|
+
# end
|
56
|
+
def next?
|
57
|
+
!token.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Retrieve the next page of jobs.
|
62
|
+
#
|
63
|
+
# @return [Job::List]
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# require "gcloud"
|
67
|
+
#
|
68
|
+
# gcloud = Gcloud.new
|
69
|
+
# bigquery = gcloud.bigquery
|
70
|
+
#
|
71
|
+
# jobs = bigquery.jobs
|
72
|
+
# if jobs.next?
|
73
|
+
# next_jobs = jobs.next
|
74
|
+
# end
|
75
|
+
def next
|
76
|
+
return nil unless next?
|
77
|
+
ensure_connection!
|
78
|
+
options = { all: @hidden, token: token, max: @max, filter: @filter }
|
79
|
+
resp = @connection.list_jobs options
|
80
|
+
if resp.success?
|
81
|
+
self.class.from_response resp, @connection, @hidden, @max, @filter
|
82
|
+
else
|
83
|
+
fail ApiError.from_response(resp)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Retrieves all jobs by repeatedly loading {#next} until {#next?}
|
89
|
+
# returns `false`. Calls the given block once for each job, which is
|
90
|
+
# passed as the parameter.
|
91
|
+
#
|
92
|
+
# An Enumerator is returned if no block is given.
|
93
|
+
#
|
94
|
+
# This method may make several API calls until all jobs are retrieved.
|
95
|
+
# Be sure to use as narrow a search criteria as possible. Please use
|
96
|
+
# with caution.
|
97
|
+
#
|
98
|
+
# @param [Integer] request_limit The upper limit of API requests to make
|
99
|
+
# to load all jobs. Default is no limit.
|
100
|
+
# @yield [job] The block for accessing each job.
|
101
|
+
# @yieldparam [Job] job The job object.
|
102
|
+
#
|
103
|
+
# @return [Enumerator]
|
104
|
+
#
|
105
|
+
# @example Iterating each job by passing a block:
|
106
|
+
# require "gcloud"
|
107
|
+
#
|
108
|
+
# gcloud = Gcloud.new
|
109
|
+
# bigquery = gcloud.bigquery
|
110
|
+
#
|
111
|
+
# bigquery.jobs.all do |job|
|
112
|
+
# puts job.state
|
113
|
+
# end
|
114
|
+
#
|
115
|
+
# @example Using the enumerator by not passing a block:
|
116
|
+
# require "gcloud"
|
117
|
+
#
|
118
|
+
# gcloud = Gcloud.new
|
119
|
+
# bigquery = gcloud.bigquery
|
120
|
+
#
|
121
|
+
# all_states = bigquery.jobs.all.map do |job|
|
122
|
+
# job.state
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# @example Limit the number of API calls made:
|
126
|
+
# require "gcloud"
|
127
|
+
#
|
128
|
+
# gcloud = Gcloud.new
|
129
|
+
# bigquery = gcloud.bigquery
|
130
|
+
#
|
131
|
+
# bigquery.jobs.all(request_limit: 10) do |job|
|
132
|
+
# puts job.state
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
def all request_limit: nil
|
136
|
+
request_limit = request_limit.to_i if request_limit
|
137
|
+
unless block_given?
|
138
|
+
return enum_for(:all, request_limit: request_limit)
|
139
|
+
end
|
140
|
+
results = self
|
141
|
+
loop do
|
142
|
+
results.each { |r| yield r }
|
143
|
+
if request_limit
|
144
|
+
request_limit -= 1
|
145
|
+
break if request_limit < 0
|
146
|
+
end
|
147
|
+
break unless results.next?
|
148
|
+
results = results.next
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
41
152
|
##
|
42
153
|
# @private New Job::List from a response object.
|
43
|
-
def self.from_response resp, conn
|
154
|
+
def self.from_response resp, conn, hidden = nil, max = nil, filter = nil
|
44
155
|
jobs = List.new(Array(resp.data["jobs"]).map do |gapi_object|
|
45
156
|
Job.from_gapi gapi_object, conn
|
46
157
|
end)
|
47
158
|
jobs.instance_variable_set "@token", resp.data["nextPageToken"]
|
48
159
|
jobs.instance_variable_set "@etag", resp.data["etag"]
|
49
160
|
jobs.instance_variable_set "@total", resp.data["totalItems"]
|
161
|
+
jobs.instance_variable_set "@connection", conn
|
162
|
+
jobs.instance_variable_set "@hidden", hidden
|
163
|
+
jobs.instance_variable_set "@max", max
|
164
|
+
jobs.instance_variable_set "@filter", filter
|
50
165
|
jobs
|
51
166
|
end
|
167
|
+
|
168
|
+
protected
|
169
|
+
|
170
|
+
##
|
171
|
+
# Raise an error unless an active connection is available.
|
172
|
+
def ensure_connection!
|
173
|
+
fail "Must have active connection" unless @connection
|
174
|
+
end
|
52
175
|
end
|
53
176
|
end
|
54
177
|
end
|
@@ -210,6 +210,17 @@ module Gcloud
|
|
210
210
|
# puts row["name"]
|
211
211
|
# end
|
212
212
|
#
|
213
|
+
# @example Retrieve all rows: (See {QueryData#all})
|
214
|
+
# require "gcloud"
|
215
|
+
#
|
216
|
+
# gcloud = Gcloud.new
|
217
|
+
# bigquery = gcloud.bigquery
|
218
|
+
#
|
219
|
+
# data = bigquery.query "SELECT name FROM [my_proj:my_data.my_table]"
|
220
|
+
# data.all do |row|
|
221
|
+
# puts row["name"]
|
222
|
+
# end
|
223
|
+
#
|
213
224
|
def query query, max: nil, timeout: 10000, dryrun: nil, cache: true,
|
214
225
|
dataset: nil, project: nil
|
215
226
|
ensure_connection!
|
@@ -352,30 +363,23 @@ module Gcloud
|
|
352
363
|
# puts dataset.name
|
353
364
|
# end
|
354
365
|
#
|
355
|
-
# @example Retrieve
|
366
|
+
# @example Retrieve hidden datasets with the `all` optional arg:
|
356
367
|
# require "gcloud"
|
357
368
|
#
|
358
369
|
# gcloud = Gcloud.new
|
359
370
|
# bigquery = gcloud.bigquery
|
360
371
|
#
|
361
|
-
# all_datasets = bigquery.datasets
|
372
|
+
# all_datasets = bigquery.datasets all: true
|
362
373
|
#
|
363
|
-
# @example
|
374
|
+
# @example Retrieve all datasets: (See {Dataset::List#all})
|
364
375
|
# require "gcloud"
|
365
376
|
#
|
366
377
|
# gcloud = Gcloud.new
|
367
378
|
# bigquery = gcloud.bigquery
|
368
379
|
#
|
369
|
-
#
|
370
|
-
#
|
371
|
-
#
|
372
|
-
# tmp_datasets.each do |dataset|
|
373
|
-
# all_datasets << dataset
|
374
|
-
# end
|
375
|
-
# # break loop if no more datasets available
|
376
|
-
# break if tmp_datasets.token.nil?
|
377
|
-
# # get the next group of datasets
|
378
|
-
# tmp_datasets = bigquery.datasets token: tmp_datasets.token
|
380
|
+
# datasets = bigquery.datasets
|
381
|
+
# datasets.all do |dataset|
|
382
|
+
# puts dataset.name
|
379
383
|
# end
|
380
384
|
#
|
381
385
|
def datasets all: nil, token: nil, max: nil
|
@@ -383,7 +387,7 @@ module Gcloud
|
|
383
387
|
options = { all: all, token: token, max: max }
|
384
388
|
resp = connection.list_datasets options
|
385
389
|
if resp.success?
|
386
|
-
Dataset::List.from_response resp, connection
|
390
|
+
Dataset::List.from_response resp, connection, all, max
|
387
391
|
else
|
388
392
|
fail ApiError.from_response(resp)
|
389
393
|
end
|
@@ -442,31 +446,30 @@ module Gcloud
|
|
442
446
|
# bigquery = gcloud.bigquery
|
443
447
|
#
|
444
448
|
# jobs = bigquery.jobs
|
449
|
+
# jobs.each do |job|
|
450
|
+
# # process job
|
451
|
+
# end
|
445
452
|
#
|
446
|
-
# @example Retrieve only running jobs using the
|
453
|
+
# @example Retrieve only running jobs using the `filter` optional arg:
|
447
454
|
# require "gcloud"
|
448
455
|
#
|
449
456
|
# gcloud = Gcloud.new
|
450
457
|
# bigquery = gcloud.bigquery
|
451
458
|
#
|
452
459
|
# running_jobs = bigquery.jobs filter: "running"
|
460
|
+
# running_jobs.each do |job|
|
461
|
+
# # process job
|
462
|
+
# end
|
453
463
|
#
|
454
|
-
# @example
|
464
|
+
# @example Retrieve all jobs: (See {Job::List#all})
|
455
465
|
# require "gcloud"
|
456
466
|
#
|
457
467
|
# gcloud = Gcloud.new
|
458
468
|
# bigquery = gcloud.bigquery
|
459
469
|
#
|
460
|
-
#
|
461
|
-
#
|
462
|
-
#
|
463
|
-
# tmp_jobs.each do |job|
|
464
|
-
# all_jobs << job
|
465
|
-
# end
|
466
|
-
# # break loop if no more jobs available
|
467
|
-
# break if tmp_jobs.token.nil?
|
468
|
-
# # get the next group of jobs
|
469
|
-
# tmp_jobs = bigquery.jobs token: tmp_jobs.token
|
470
|
+
# jobs = bigquery.jobs
|
471
|
+
# jobs.all do |job|
|
472
|
+
# # process job
|
470
473
|
# end
|
471
474
|
#
|
472
475
|
def jobs all: nil, token: nil, max: nil, filter: nil
|
@@ -474,7 +477,7 @@ module Gcloud
|
|
474
477
|
options = { all: all, token: token, max: max, filter: filter }
|
475
478
|
resp = connection.list_jobs options
|
476
479
|
if resp.success?
|
477
|
-
Job::List.from_response resp, connection
|
480
|
+
Job::List.from_response resp, connection, all, max, filter
|
478
481
|
else
|
479
482
|
fail ApiError.from_response(resp)
|
480
483
|
end
|
@@ -73,11 +73,43 @@ module Gcloud
|
|
73
73
|
end
|
74
74
|
|
75
75
|
##
|
76
|
-
#
|
76
|
+
# Whether there is a next page of query data.
|
77
|
+
#
|
78
|
+
# @return [Boolean]
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# require "gcloud"
|
82
|
+
#
|
83
|
+
# gcloud = Gcloud.new
|
84
|
+
# bigquery = gcloud.bigquery
|
85
|
+
# job = bigquery.job "my_job"
|
86
|
+
#
|
87
|
+
# data = job.query_results
|
88
|
+
# if data.next?
|
89
|
+
# next_data = data.next
|
90
|
+
# end
|
91
|
+
#
|
77
92
|
def next?
|
78
93
|
!token.nil?
|
79
94
|
end
|
80
95
|
|
96
|
+
##
|
97
|
+
# Retrieve the next page of query data.
|
98
|
+
#
|
99
|
+
# @return [QueryData]
|
100
|
+
#
|
101
|
+
# @example
|
102
|
+
# require "gcloud"
|
103
|
+
#
|
104
|
+
# gcloud = Gcloud.new
|
105
|
+
# bigquery = gcloud.bigquery
|
106
|
+
# job = bigquery.job "my_job"
|
107
|
+
#
|
108
|
+
# data = job.query_results
|
109
|
+
# if data.next?
|
110
|
+
# next_data = data.next
|
111
|
+
# end
|
112
|
+
#
|
81
113
|
def next
|
82
114
|
return nil unless next?
|
83
115
|
ensure_connection!
|
@@ -89,6 +121,75 @@ module Gcloud
|
|
89
121
|
end
|
90
122
|
end
|
91
123
|
|
124
|
+
##
|
125
|
+
# Retrieves all rows by repeatedly loading {#next} until {#next?} returns
|
126
|
+
# `false`. Calls the given block once for each row, which is passed as the
|
127
|
+
# parameter.
|
128
|
+
#
|
129
|
+
# An Enumerator is returned if no block is given.
|
130
|
+
#
|
131
|
+
# This method may make several API calls until all rows are retrieved. Be
|
132
|
+
# sure to use as narrow a search criteria as possible. Please use with
|
133
|
+
# caution.
|
134
|
+
#
|
135
|
+
# @param [Integer] request_limit The upper limit of API requests to make
|
136
|
+
# to load all data. Default is no limit.
|
137
|
+
# @yield [row] The block for accessing each row of data.
|
138
|
+
# @yieldparam [Hash] row The row object.
|
139
|
+
#
|
140
|
+
# @return [Enumerator]
|
141
|
+
#
|
142
|
+
# @example Iterating each row by passing a block:
|
143
|
+
# require "gcloud"
|
144
|
+
#
|
145
|
+
# gcloud = Gcloud.new
|
146
|
+
# bigquery = gcloud.bigquery
|
147
|
+
# job = bigquery.job "my_job"
|
148
|
+
#
|
149
|
+
# data = job.query_results
|
150
|
+
# data.all do |row|
|
151
|
+
# puts row["word"]
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# @example Using the enumerator by not passing a block:
|
155
|
+
# require "gcloud"
|
156
|
+
#
|
157
|
+
# gcloud = Gcloud.new
|
158
|
+
# bigquery = gcloud.bigquery
|
159
|
+
# job = bigquery.job "my_job"
|
160
|
+
#
|
161
|
+
# data = job.query_results
|
162
|
+
# words = data.all.map do |row|
|
163
|
+
# row["word"]
|
164
|
+
# end
|
165
|
+
#
|
166
|
+
# @example Limit the number of API calls made:
|
167
|
+
# require "gcloud"
|
168
|
+
#
|
169
|
+
# gcloud = Gcloud.new
|
170
|
+
# bigquery = gcloud.bigquery
|
171
|
+
# job = bigquery.job "my_job"
|
172
|
+
#
|
173
|
+
# data = job.query_results
|
174
|
+
# data.all(request_limit: 10) do |row|
|
175
|
+
# puts row["word"]
|
176
|
+
# end
|
177
|
+
#
|
178
|
+
def all request_limit: nil
|
179
|
+
request_limit = request_limit.to_i if request_limit
|
180
|
+
return enum_for(:all, request_limit: request_limit) unless block_given?
|
181
|
+
results = self
|
182
|
+
loop do
|
183
|
+
results.each { |r| yield r }
|
184
|
+
if request_limit
|
185
|
+
request_limit -= 1
|
186
|
+
break if request_limit < 0
|
187
|
+
end
|
188
|
+
break unless results.next?
|
189
|
+
results = results.next
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
92
193
|
##
|
93
194
|
# The BigQuery {Job} that was created to run the query.
|
94
195
|
def job
|