gcloud 0.5.0 → 0.6.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 +8 -0
- data/lib/gcloud.rb +48 -30
- data/lib/gcloud/bigquery.rb +4 -6
- data/lib/gcloud/bigquery/connection.rb +2 -14
- data/lib/gcloud/bigquery/dataset.rb +41 -42
- data/lib/gcloud/bigquery/project.rb +50 -46
- data/lib/gcloud/bigquery/query_job.rb +7 -8
- data/lib/gcloud/bigquery/table.rb +54 -55
- data/lib/gcloud/bigquery/table/schema.rb +30 -40
- data/lib/gcloud/bigquery/view.rb +10 -11
- data/lib/gcloud/credentials.rb +19 -25
- data/lib/gcloud/datastore.rb +4 -6
- data/lib/gcloud/datastore/dataset.rb +3 -5
- data/lib/gcloud/dns.rb +4 -6
- data/lib/gcloud/dns/connection.rb +17 -16
- data/lib/gcloud/dns/importer.rb +5 -11
- data/lib/gcloud/dns/project.rb +11 -12
- data/lib/gcloud/dns/zone.rb +52 -92
- data/lib/gcloud/dns/zone/transaction.rb +2 -2
- data/lib/gcloud/pubsub.rb +4 -6
- data/lib/gcloud/pubsub/connection.rb +1 -12
- data/lib/gcloud/pubsub/project.rb +30 -36
- data/lib/gcloud/pubsub/subscription.rb +18 -26
- data/lib/gcloud/pubsub/topic.rb +16 -26
- data/lib/gcloud/resource_manager.rb +5 -6
- data/lib/gcloud/resource_manager/connection.rb +4 -4
- data/lib/gcloud/resource_manager/manager.rb +10 -14
- data/lib/gcloud/resource_manager/project.rb +3 -5
- data/lib/gcloud/search.rb +295 -0
- data/lib/gcloud/search/api_client.rb +144 -0
- data/lib/gcloud/search/connection.rb +146 -0
- data/lib/gcloud/search/credentials.rb +30 -0
- data/lib/gcloud/search/document.rb +301 -0
- data/lib/gcloud/search/document/list.rb +85 -0
- data/lib/gcloud/search/errors.rb +67 -0
- data/lib/gcloud/search/field_value.rb +164 -0
- data/lib/gcloud/search/field_values.rb +263 -0
- data/lib/gcloud/search/fields.rb +267 -0
- data/lib/gcloud/search/index.rb +613 -0
- data/lib/gcloud/search/index/list.rb +90 -0
- data/lib/gcloud/search/project.rb +197 -0
- data/lib/gcloud/search/result.rb +169 -0
- data/lib/gcloud/search/result/list.rb +95 -0
- data/lib/gcloud/storage.rb +4 -6
- data/lib/gcloud/storage/bucket.rb +55 -43
- data/lib/gcloud/storage/bucket/cors.rb +5 -7
- data/lib/gcloud/storage/file.rb +35 -30
- data/lib/gcloud/storage/file/acl.rb +12 -16
- data/lib/gcloud/storage/project.rb +56 -22
- data/lib/gcloud/version.rb +1 -1
- metadata +20 -3
data/lib/gcloud/dns/project.rb
CHANGED
@@ -171,12 +171,10 @@ module Gcloud
|
|
171
171
|
#
|
172
172
|
# === Parameters
|
173
173
|
#
|
174
|
-
# +
|
175
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
176
|
-
# <code>options[:token]</code>::
|
174
|
+
# +token+::
|
177
175
|
# A previously-returned page token representing part of the larger set
|
178
176
|
# of results to view. (+String+)
|
179
|
-
#
|
177
|
+
# +max+::
|
180
178
|
# Maximum number of zones to return. (+Integer+)
|
181
179
|
#
|
182
180
|
# === Returns
|
@@ -210,9 +208,9 @@ module Gcloud
|
|
210
208
|
# zones = zones.next
|
211
209
|
# end
|
212
210
|
#
|
213
|
-
def zones
|
211
|
+
def zones token: nil, max: nil
|
214
212
|
ensure_connection!
|
215
|
-
resp = connection.list_zones
|
213
|
+
resp = connection.list_zones token: token, max: max
|
216
214
|
if resp.success?
|
217
215
|
Zone::List.from_response resp, connection
|
218
216
|
else
|
@@ -234,13 +232,11 @@ module Gcloud
|
|
234
232
|
# +zone_dns+::
|
235
233
|
# The DNS name of this managed zone, for instance "example.com.".
|
236
234
|
# (+String+)
|
237
|
-
# +
|
238
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
239
|
-
# <code>options[:description]</code>::
|
235
|
+
# +description+::
|
240
236
|
# A string of at most 1024 characters associated with this resource for
|
241
237
|
# the user's convenience. Has no effect on the managed zone's function.
|
242
238
|
# (+String+)
|
243
|
-
#
|
239
|
+
# +name_server_set+::
|
244
240
|
# A NameServerSet is a set of DNS name servers that all host the same
|
245
241
|
# ManagedZones. Most users will leave this field unset. (+String+)
|
246
242
|
#
|
@@ -256,9 +252,12 @@ module Gcloud
|
|
256
252
|
# dns = gcloud.dns
|
257
253
|
# zone = dns.create_zone "example-com", "example.com."
|
258
254
|
#
|
259
|
-
def create_zone zone_name, zone_dns,
|
255
|
+
def create_zone zone_name, zone_dns, description: nil,
|
256
|
+
name_server_set: nil
|
260
257
|
ensure_connection!
|
261
|
-
resp = connection.create_zone zone_name, zone_dns,
|
258
|
+
resp = connection.create_zone zone_name, zone_dns,
|
259
|
+
description: description,
|
260
|
+
name_server_set: name_server_set
|
262
261
|
if resp.success?
|
263
262
|
Zone.from_gapi resp.data, connection
|
264
263
|
else
|
data/lib/gcloud/dns/zone.rb
CHANGED
@@ -121,9 +121,7 @@ module Gcloud
|
|
121
121
|
#
|
122
122
|
# === Parameters
|
123
123
|
#
|
124
|
-
# +
|
125
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
126
|
-
# <code>options[:force]</code>::
|
124
|
+
# +force+::
|
127
125
|
# If +true+, ensures the deletion of the zone by first deleting all
|
128
126
|
# records. If +false+ and the zone contains non-essential records, the
|
129
127
|
# request will fail. Default is +false+. (+Boolean+)
|
@@ -150,8 +148,8 @@ module Gcloud
|
|
150
148
|
# zone = dns.zone "example-com"
|
151
149
|
# zone.delete force: true
|
152
150
|
#
|
153
|
-
def delete
|
154
|
-
clear! if
|
151
|
+
def delete force: false
|
152
|
+
clear! if force
|
155
153
|
|
156
154
|
ensure_connection!
|
157
155
|
resp = connection.delete_zone id
|
@@ -222,14 +220,12 @@ module Gcloud
|
|
222
220
|
#
|
223
221
|
# === Parameters
|
224
222
|
#
|
225
|
-
# +
|
226
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
227
|
-
# <code>options[:token]</code>::
|
223
|
+
# +token+::
|
228
224
|
# A previously-returned page token representing part of the larger set
|
229
225
|
# of results to view. (+String+)
|
230
|
-
#
|
226
|
+
# +max+::
|
231
227
|
# Maximum number of changes to return. (+Integer+)
|
232
|
-
#
|
228
|
+
# +order+::
|
233
229
|
# Sort the changes by change sequence. (+Symbol+ or +String+)
|
234
230
|
#
|
235
231
|
# Acceptable values are:
|
@@ -278,13 +274,14 @@ module Gcloud
|
|
278
274
|
# changes = changes.next
|
279
275
|
# end
|
280
276
|
#
|
281
|
-
def changes
|
277
|
+
def changes token: nil, max: nil, order: nil
|
282
278
|
ensure_connection!
|
283
279
|
# Fix the sort options
|
284
|
-
|
285
|
-
|
280
|
+
order = adjust_change_sort_order order
|
281
|
+
sort = "changeSequence" if order
|
286
282
|
# Continue with the API call
|
287
|
-
resp = connection.list_changes id,
|
283
|
+
resp = connection.list_changes id, token: token, max: max,
|
284
|
+
order: order, sort: sort
|
288
285
|
if resp.success?
|
289
286
|
Change::List.from_response resp, self
|
290
287
|
else
|
@@ -304,12 +301,10 @@ module Gcloud
|
|
304
301
|
# Return only records with this {record
|
305
302
|
# type}[https://cloud.google.com/dns/what-is-cloud-dns].
|
306
303
|
# If present, the +name+ parameter must also be present. (+String+)
|
307
|
-
# +
|
308
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
309
|
-
# <code>options[:token]</code>::
|
304
|
+
# +token+::
|
310
305
|
# A previously-returned page token representing part of the larger set
|
311
306
|
# of results to view. (+String+)
|
312
|
-
#
|
307
|
+
# +max+::
|
313
308
|
# Maximum number of records to return. (+Integer+)
|
314
309
|
#
|
315
310
|
# === Returns
|
@@ -367,12 +362,12 @@ module Gcloud
|
|
367
362
|
# zone = dns.zone "example-com"
|
368
363
|
# records = zone.records.all
|
369
364
|
#
|
370
|
-
def records name = nil, type = nil,
|
365
|
+
def records name = nil, type = nil, token: nil, max: nil
|
371
366
|
ensure_connection!
|
372
367
|
|
373
|
-
|
368
|
+
name = fqdn(name) if name
|
374
369
|
|
375
|
-
resp = connection.list_records id,
|
370
|
+
resp = connection.list_records id, name, type, token: token, max: max
|
376
371
|
if resp.success?
|
377
372
|
Record::List.from_response resp, self
|
378
373
|
else
|
@@ -463,16 +458,14 @@ module Gcloud
|
|
463
458
|
# +path_or_io+::
|
464
459
|
# The path to a zone file on the filesystem, or an IO instance from
|
465
460
|
# which zone file data can be read. (+String+ or +IO+)
|
466
|
-
# +
|
467
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
468
|
-
# <code>options[:only]</code>::
|
461
|
+
# +only+::
|
469
462
|
# Include only records of this type or types. (+String+ or +Array+)
|
470
|
-
#
|
463
|
+
# +except+::
|
471
464
|
# Exclude records of this type or types. (+String+ or +Array+)
|
472
|
-
#
|
465
|
+
# +skip_soa+::
|
473
466
|
# Do not automatically update the SOA record serial number. See #update
|
474
467
|
# for details. (+Boolean+)
|
475
|
-
#
|
468
|
+
# +soa_serial+::
|
476
469
|
# A value (or a lambda or Proc returning a value) for the new SOA record
|
477
470
|
# serial number. See #update for details. (+Integer+, lambda, or +Proc+)
|
478
471
|
#
|
@@ -489,11 +482,12 @@ module Gcloud
|
|
489
482
|
# zone = dns.zone "example-com"
|
490
483
|
# change = zone.import "path/to/db.example.com"
|
491
484
|
#
|
492
|
-
def import path_or_io,
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
485
|
+
def import path_or_io, only: nil, except: nil,
|
486
|
+
skip_soa: nil, soa_serial: nil
|
487
|
+
except = (Array(except).map(&:to_s).map(&:upcase) + %w(SOA NS)).uniq
|
488
|
+
importer = Gcloud::Dns::Importer.new self, path_or_io
|
489
|
+
additions = importer.records only: only, except: except
|
490
|
+
update additions, [], skip_soa: skip_soa, soa_serial: soa_serial
|
497
491
|
end
|
498
492
|
|
499
493
|
# rubocop:disable all
|
@@ -516,11 +510,9 @@ module Gcloud
|
|
516
510
|
# The Record or array of records to add. (Record or +Array+)
|
517
511
|
# +deletions+::
|
518
512
|
# The Record or array of records to remove. (Record or +Array+)
|
519
|
-
# +
|
520
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
521
|
-
# <code>options[:skip_soa]</code>::
|
513
|
+
# +skip_soa+::
|
522
514
|
# Do not automatically update the SOA record serial number. (+Boolean+)
|
523
|
-
#
|
515
|
+
# +soa_serial+::
|
524
516
|
# A value (or a lambda or Proc returning a value) for the new SOA record
|
525
517
|
# serial number. (+Integer+, lambda, or +Proc+)
|
526
518
|
#
|
@@ -571,7 +563,7 @@ module Gcloud
|
|
571
563
|
# new_record = zone.record "example.com.", "A", 86400, ["1.2.3.4"]
|
572
564
|
# change = zone.update new_record, soa_serial: lambda { |sn| sn + 10 }
|
573
565
|
#
|
574
|
-
def update additions = [], deletions = [],
|
566
|
+
def update additions = [], deletions = [], skip_soa: nil, soa_serial: nil
|
575
567
|
# Handle only sending in options
|
576
568
|
if additions.is_a?(::Hash) && deletions.empty? && options.empty?
|
577
569
|
options = additions
|
@@ -594,8 +586,8 @@ module Gcloud
|
|
594
586
|
to_add = additions - deletions
|
595
587
|
to_remove = deletions - additions
|
596
588
|
return nil if to_add.empty? && to_remove.empty?
|
597
|
-
unless
|
598
|
-
increment_soa to_add, to_remove,
|
589
|
+
unless skip_soa || detect_soa(to_add) || detect_soa(to_remove)
|
590
|
+
increment_soa to_add, to_remove, soa_serial
|
599
591
|
end
|
600
592
|
create_change to_add, to_remove
|
601
593
|
end
|
@@ -627,12 +619,10 @@ module Gcloud
|
|
627
619
|
# (section 3.6.1)}[http://tools.ietf.org/html/rfc1034#section-3.6.1].
|
628
620
|
# For example: +192.0.2.1+ or +example.com.+. (+String+ or +Array+ of
|
629
621
|
# +String+)
|
630
|
-
# +
|
631
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
632
|
-
# <code>options[:skip_soa]</code>::
|
622
|
+
# +skip_soa+::
|
633
623
|
# Do not automatically update the SOA record serial number. See #update
|
634
624
|
# for details. (+Boolean+)
|
635
|
-
#
|
625
|
+
# +soa_serial+::
|
636
626
|
# A value (or a lambda or Proc returning a value) for the new SOA record
|
637
627
|
# serial number. See #update for details. (+Integer+, lambda, or +Proc+)
|
638
628
|
#
|
@@ -649,8 +639,9 @@ module Gcloud
|
|
649
639
|
# zone = dns.zone "example-com"
|
650
640
|
# change = zone.add "example.com.", "A", 86400, ["1.2.3.4"]
|
651
641
|
#
|
652
|
-
def add name, type, ttl, data,
|
653
|
-
update [record(name, type, ttl, data)], [],
|
642
|
+
def add name, type, ttl, data, skip_soa: nil, soa_serial: nil
|
643
|
+
update [record(name, type, ttl, data)], [],
|
644
|
+
skip_soa: skip_soa, soa_serial: soa_serial
|
654
645
|
end
|
655
646
|
|
656
647
|
##
|
@@ -669,12 +660,10 @@ module Gcloud
|
|
669
660
|
# The identifier of a {supported record
|
670
661
|
# type}[https://cloud.google.com/dns/what-is-cloud-dns].
|
671
662
|
# For example: +A+, +AAAA+, +CNAME+, +MX+, or +TXT+. (+String+)
|
672
|
-
# +
|
673
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
674
|
-
# <code>options[:skip_soa]</code>::
|
663
|
+
# +skip_soa+::
|
675
664
|
# Do not automatically update the SOA record serial number. See #update
|
676
665
|
# for details. (+Boolean+)
|
677
|
-
#
|
666
|
+
# +soa_serial+::
|
678
667
|
# A value (or a lambda or Proc returning a value) for the new SOA record
|
679
668
|
# serial number. See #update for details. (+Integer+, lambda, or +Proc+)
|
680
669
|
#
|
@@ -691,8 +680,9 @@ module Gcloud
|
|
691
680
|
# zone = dns.zone "example-com"
|
692
681
|
# change = zone.remove "example.com.", "A"
|
693
682
|
#
|
694
|
-
def remove name, type,
|
695
|
-
update [], records(name
|
683
|
+
def remove name, type, skip_soa: nil, soa_serial: nil
|
684
|
+
update [], records(name, type).all.to_a,
|
685
|
+
skip_soa: skip_soa, soa_serial: soa_serial
|
696
686
|
end
|
697
687
|
|
698
688
|
##
|
@@ -721,12 +711,10 @@ module Gcloud
|
|
721
711
|
# 3.6.1)}[http://tools.ietf.org/html/rfc1034#section-3.6.1]. For
|
722
712
|
# example: +192.0.2.1+ or +example.com.+. (+String+ or +Array+ of
|
723
713
|
# +String+)
|
724
|
-
# +
|
725
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
726
|
-
# <code>options[:skip_soa]</code>::
|
714
|
+
# +skip_soa+::
|
727
715
|
# Do not automatically update the SOA record serial number. See #update
|
728
716
|
# for details. (+Boolean+)
|
729
|
-
#
|
717
|
+
# +soa_serial+::
|
730
718
|
# A value (or a lambda or Proc returning a value) for the new SOA record
|
731
719
|
# serial number. See #update for details. (+Integer+, lambda, or +Proc+)
|
732
720
|
#
|
@@ -743,10 +731,10 @@ module Gcloud
|
|
743
731
|
# zone = dns.zone "example-com"
|
744
732
|
# change = zone.replace "example.com.", "A", 86400, ["5.6.7.8"]
|
745
733
|
#
|
746
|
-
def replace name, type, ttl, data,
|
734
|
+
def replace name, type, ttl, data, skip_soa: nil, soa_serial: nil
|
747
735
|
update [record(name, type, ttl, data)],
|
748
|
-
records(name
|
749
|
-
|
736
|
+
records(name, type).all.to_a,
|
737
|
+
skip_soa: skip_soa, soa_serial: soa_serial
|
750
738
|
end
|
751
739
|
|
752
740
|
def to_zonefile #:nodoc:
|
@@ -768,12 +756,10 @@ module Gcloud
|
|
768
756
|
# The identifier of a {supported record
|
769
757
|
# type}[https://cloud.google.com/dns/what-is-cloud-dns].
|
770
758
|
# For example: +A+, +AAAA+, +CNAME+, +MX+, or +TXT+. (+String+)
|
771
|
-
# +
|
772
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
773
|
-
# <code>options[:skip_soa]</code>::
|
759
|
+
# +skip_soa+::
|
774
760
|
# Do not automatically update the SOA record serial number. See #update
|
775
761
|
# for details. (+Boolean+)
|
776
|
-
#
|
762
|
+
# +soa_serial+::
|
777
763
|
# A value (or a lambda or Proc returning a value) for the new SOA record
|
778
764
|
# serial number. See #update for details. (+Integer+, lambda, or +Proc+)
|
779
765
|
#
|
@@ -792,11 +778,11 @@ module Gcloud
|
|
792
778
|
# mx.ttl = 3600 # change only the TTL
|
793
779
|
# end
|
794
780
|
#
|
795
|
-
def modify name, type,
|
796
|
-
existing = records(name
|
781
|
+
def modify name, type, skip_soa: nil, soa_serial: nil
|
782
|
+
existing = records(name, type).all.to_a
|
797
783
|
updated = existing.map(&:dup)
|
798
784
|
updated.each { |r| yield r }
|
799
|
-
update updated, existing,
|
785
|
+
update updated, existing, skip_soa: skip_soa, soa_serial: soa_serial
|
800
786
|
end
|
801
787
|
|
802
788
|
##
|
@@ -847,32 +833,6 @@ module Gcloud
|
|
847
833
|
fail "Must have active connection" unless connection
|
848
834
|
end
|
849
835
|
|
850
|
-
# rubocop:disable all
|
851
|
-
# Disabled rubocop because this complexity cannot easily be avoided.
|
852
|
-
|
853
|
-
def build_records_options name, type, options
|
854
|
-
# Handle only sending in options
|
855
|
-
if name.is_a?(::Hash) && type.nil? && options.empty?
|
856
|
-
options = name
|
857
|
-
name = nil
|
858
|
-
elsif type.is_a?(::Hash) && options.empty?
|
859
|
-
options = type
|
860
|
-
type = nil
|
861
|
-
end
|
862
|
-
|
863
|
-
# Set parameters as options, params have priority
|
864
|
-
options[:name] = name || options[:name]
|
865
|
-
options[:type] = type || options[:type]
|
866
|
-
|
867
|
-
# Ensure name is a FQDN
|
868
|
-
options[:name] = fqdn(options[:name]) if options[:name]
|
869
|
-
|
870
|
-
# return only the options
|
871
|
-
options
|
872
|
-
end
|
873
|
-
|
874
|
-
# rubocop:enable all
|
875
|
-
|
876
836
|
def create_change additions, deletions
|
877
837
|
ensure_connection!
|
878
838
|
resp = connection.create_change id,
|
@@ -886,7 +846,7 @@ module Gcloud
|
|
886
846
|
end
|
887
847
|
|
888
848
|
def increment_soa to_add, to_remove, soa_serial
|
889
|
-
current_soa = detect_soa records(
|
849
|
+
current_soa = detect_soa records(dns, "SOA").all
|
890
850
|
return false if current_soa.nil?
|
891
851
|
updated_soa = current_soa.dup
|
892
852
|
updated_soa.data[0] = replace_soa_serial updated_soa.data[0], soa_serial
|
@@ -111,7 +111,7 @@ module Gcloud
|
|
111
111
|
# end
|
112
112
|
#
|
113
113
|
def remove name, type
|
114
|
-
@deletions += @zone.records(name
|
114
|
+
@deletions += @zone.records(name, type).all
|
115
115
|
end
|
116
116
|
|
117
117
|
##
|
@@ -180,7 +180,7 @@ module Gcloud
|
|
180
180
|
# end
|
181
181
|
#
|
182
182
|
def modify name, type
|
183
|
-
existing = @zone.records(name
|
183
|
+
existing = @zone.records(name, type).all.to_a
|
184
184
|
updated = existing.map(&:dup)
|
185
185
|
updated.each { |r| yield r }
|
186
186
|
@additions += updated
|
data/lib/gcloud/pubsub.rb
CHANGED
@@ -31,9 +31,7 @@ module Gcloud
|
|
31
31
|
# +keyfile+::
|
32
32
|
# Keyfile downloaded from Google Cloud. If file path the file must be
|
33
33
|
# readable. (+String+ or +Hash+)
|
34
|
-
# +
|
35
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
36
|
-
# <code>options[:scope]</code>::
|
34
|
+
# +scope+::
|
37
35
|
# The OAuth 2.0 scopes controlling the set of resources and operations that
|
38
36
|
# the connection can access. See {Using OAuth 2.0 to Access Google
|
39
37
|
# APIs}[https://developers.google.com/identity/protocols/OAuth2]. (+String+
|
@@ -56,12 +54,12 @@ module Gcloud
|
|
56
54
|
# topic = pubsub.topic "my-topic"
|
57
55
|
# topic.publish "task completed"
|
58
56
|
#
|
59
|
-
def self.pubsub project = nil, keyfile = nil,
|
57
|
+
def self.pubsub project = nil, keyfile = nil, scope: nil
|
60
58
|
project ||= Gcloud::Pubsub::Project.default_project
|
61
59
|
if keyfile.nil?
|
62
|
-
credentials = Gcloud::Pubsub::Credentials.default
|
60
|
+
credentials = Gcloud::Pubsub::Credentials.default scope: scope
|
63
61
|
else
|
64
|
-
credentials = Gcloud::Pubsub::Credentials.new keyfile,
|
62
|
+
credentials = Gcloud::Pubsub::Credentials.new keyfile, scope: scope
|
65
63
|
end
|
66
64
|
Gcloud::Pubsub::Project.new project, credentials
|
67
65
|
end
|
@@ -280,7 +280,7 @@ module Gcloud
|
|
280
280
|
def subscription_data topic, options = {}
|
281
281
|
deadline = options[:deadline]
|
282
282
|
endpoint = options[:endpoint]
|
283
|
-
attributes =
|
283
|
+
attributes = (options[:attributes] || {}).to_h
|
284
284
|
|
285
285
|
data = { topic: topic_path(topic) }
|
286
286
|
data[:ackDeadlineSeconds] = deadline if deadline
|
@@ -290,17 +290,6 @@ module Gcloud
|
|
290
290
|
end
|
291
291
|
data
|
292
292
|
end
|
293
|
-
|
294
|
-
##
|
295
|
-
# Make sure the object is converted to a hash
|
296
|
-
# Ruby 1.9.3 doesn't support to_h, so here we are.
|
297
|
-
def hashify hash
|
298
|
-
if hash.respond_to? :to_h
|
299
|
-
hash.to_h
|
300
|
-
else
|
301
|
-
Hash.try_convert(hash) || {}
|
302
|
-
end
|
303
|
-
end
|
304
293
|
end
|
305
294
|
end
|
306
295
|
end
|
@@ -85,17 +85,15 @@ module Gcloud
|
|
85
85
|
#
|
86
86
|
# +topic_name+::
|
87
87
|
# Name of a topic. (+String+)
|
88
|
-
# +
|
89
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
90
|
-
# <code>options[:autocreate]</code>::
|
88
|
+
# +autocreate+::
|
91
89
|
# Flag to control whether the requested topic will be created if it does
|
92
90
|
# not exist. Ignored if +skip_lookup+ is +true+. The default value is
|
93
91
|
# +false+. (+Boolean+)
|
94
|
-
#
|
92
|
+
# +project+::
|
95
93
|
# If the topic belongs to a project other than the one currently
|
96
94
|
# connected to, the alternate project ID can be specified here.
|
97
95
|
# (+String+)
|
98
|
-
#
|
96
|
+
# +skip_lookup+::
|
99
97
|
# Optionally create a Topic object without verifying the topic resource
|
100
98
|
# exists on the Pub/Sub service. Calls made on this object will raise
|
101
99
|
# errors if the topic resource does not exist. Default is +false+.
|
@@ -150,15 +148,14 @@ module Gcloud
|
|
150
148
|
# pubsub = gcloud.pubsub
|
151
149
|
# topic = pubsub.topic "another-topic", skip_lookup: true
|
152
150
|
#
|
153
|
-
def topic topic_name,
|
151
|
+
def topic topic_name, autocreate: nil, project: nil, skip_lookup: nil
|
154
152
|
ensure_connection!
|
155
|
-
|
156
|
-
|
157
|
-
end
|
153
|
+
options = { project: project }
|
154
|
+
return Topic.new_lazy(topic_name, connection, options) if skip_lookup
|
158
155
|
resp = connection.get_topic topic_name
|
159
156
|
return Topic.from_gapi(resp.data, connection) if resp.success?
|
160
157
|
if resp.status == 404
|
161
|
-
return create_topic(topic_name) if
|
158
|
+
return create_topic(topic_name) if autocreate
|
162
159
|
return nil
|
163
160
|
end
|
164
161
|
fail ApiError.from_response(resp)
|
@@ -202,14 +199,11 @@ module Gcloud
|
|
202
199
|
#
|
203
200
|
# === Parameters
|
204
201
|
#
|
205
|
-
# +
|
206
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
207
|
-
# (+String+)
|
208
|
-
# <code>options[:token]</code>::
|
202
|
+
# +token+::
|
209
203
|
# The +token+ value returned by the last call to +topics+; indicates
|
210
204
|
# that this is a continuation of a call, and that the system should
|
211
205
|
# return the next page of data. (+String+)
|
212
|
-
#
|
206
|
+
# +max+::
|
213
207
|
# Maximum number of topics to return. (+Integer+)
|
214
208
|
#
|
215
209
|
# === Returns
|
@@ -248,8 +242,9 @@ module Gcloud
|
|
248
242
|
# tmp_topics = pubsub.topics token: tmp_topics.token
|
249
243
|
# end
|
250
244
|
#
|
251
|
-
def topics
|
245
|
+
def topics token: nil, max: nil
|
252
246
|
ensure_connection!
|
247
|
+
options = { token: token, max: max }
|
253
248
|
resp = connection.list_topics options
|
254
249
|
if resp.success?
|
255
250
|
Topic::List.from_response resp, connection
|
@@ -353,15 +348,13 @@ module Gcloud
|
|
353
348
|
# periods (.), tildes (~), plus (+) or percent signs (%). It must be
|
354
349
|
# between 3 and 255 characters in length, and it must not start with
|
355
350
|
# "goog". (+String+)
|
356
|
-
# +
|
357
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
358
|
-
# <code>options[:deadline]</code>::
|
351
|
+
# +deadline+::
|
359
352
|
# The maximum number of seconds after a subscriber receives a message
|
360
353
|
# before the subscriber should acknowledge the message. (+Integer+)
|
361
|
-
#
|
354
|
+
# +endpoint+::
|
362
355
|
# A URL locating the endpoint to which messages should be pushed.
|
363
356
|
# e.g. "https://example.com/push" (+String+)
|
364
|
-
#
|
357
|
+
# +autocreate+::
|
365
358
|
# Flag to control whether the topic will be created if it does not
|
366
359
|
# exist.
|
367
360
|
#
|
@@ -411,15 +404,18 @@ module Gcloud
|
|
411
404
|
#
|
412
405
|
# sub = pubsub.subscribe "new-topic", "new-topic-sub", autocreate: true
|
413
406
|
#
|
414
|
-
def subscribe topic_name, subscription_name,
|
407
|
+
def subscribe topic_name, subscription_name, deadline: nil, endpoint: nil,
|
408
|
+
autocreate: nil
|
415
409
|
ensure_connection!
|
410
|
+
options = { deadline: deadline, endpoint: endpoint }
|
416
411
|
resp = connection.create_subscription topic_name,
|
417
412
|
subscription_name, options
|
418
413
|
return Subscription.from_gapi(resp.data, connection) if resp.success?
|
419
|
-
if
|
414
|
+
if autocreate && resp.status == 404
|
420
415
|
create_topic topic_name
|
421
416
|
return subscribe(topic_name, subscription_name,
|
422
|
-
|
417
|
+
deadline: deadline, endpoint: endpoint,
|
418
|
+
autocreate: false)
|
423
419
|
end
|
424
420
|
fail ApiError.from_response(resp)
|
425
421
|
end
|
@@ -433,13 +429,11 @@ module Gcloud
|
|
433
429
|
#
|
434
430
|
# +subscription_name+::
|
435
431
|
# Name of a subscription. (+String+)
|
436
|
-
# +
|
437
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
438
|
-
# <code>options[:project]</code>::
|
432
|
+
# +project+::
|
439
433
|
# If the subscription belongs to a project other than the one currently
|
440
434
|
# connected to, the alternate project ID can be specified here.
|
441
435
|
# (+String+)
|
442
|
-
#
|
436
|
+
# +skip_lookup+::
|
443
437
|
# Optionally create a Subscription object without verifying the
|
444
438
|
# subscription resource exists on the Pub/Sub service. Calls made on
|
445
439
|
# this object will raise errors if the service resource does not exist.
|
@@ -471,9 +465,10 @@ module Gcloud
|
|
471
465
|
# subscription = pubsub.subscription "my-sub", skip_lookup: true
|
472
466
|
# puts subscription.name
|
473
467
|
#
|
474
|
-
def subscription subscription_name,
|
468
|
+
def subscription subscription_name, project: nil, skip_lookup: nil
|
475
469
|
ensure_connection!
|
476
|
-
|
470
|
+
options = { project: project }
|
471
|
+
if skip_lookup
|
477
472
|
return Subscription.new_lazy(subscription_name, connection, options)
|
478
473
|
end
|
479
474
|
resp = connection.get_subscription subscription_name
|
@@ -489,15 +484,13 @@ module Gcloud
|
|
489
484
|
#
|
490
485
|
# === Parameters
|
491
486
|
#
|
492
|
-
# +
|
493
|
-
# An optional Hash for controlling additional behavior. (+Hash+)
|
494
|
-
# <code>options[:prefix]</code>::
|
487
|
+
# +prefix+::
|
495
488
|
# Filter results to subscriptions whose names begin with this prefix.
|
496
489
|
# (+String+)
|
497
|
-
#
|
490
|
+
# +token+::
|
498
491
|
# A previously-returned page token representing part of the larger set
|
499
492
|
# of results to view. (+String+)
|
500
|
-
#
|
493
|
+
# +max+::
|
501
494
|
# Maximum number of subscriptions to return. (+Integer+)
|
502
495
|
#
|
503
496
|
# === Returns
|
@@ -537,8 +530,9 @@ module Gcloud
|
|
537
530
|
# tmp_subs = pubsub.subscriptions token: tmp_subs.token
|
538
531
|
# end
|
539
532
|
#
|
540
|
-
def subscriptions
|
533
|
+
def subscriptions prefix: nil, token: nil, max: nil
|
541
534
|
ensure_connection!
|
535
|
+
options = { prefix: prefix, token: token, max: max }
|
542
536
|
resp = connection.list_subscriptions options
|
543
537
|
if resp.success?
|
544
538
|
Subscription::List.from_response resp, connection
|