gcloud 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +3 -3
  3. data/CHANGELOG.md +92 -0
  4. data/OVERVIEW.md +3 -3
  5. data/lib/gcloud.rb +75 -25
  6. data/lib/gcloud/backoff.rb +5 -1
  7. data/lib/gcloud/bigquery.rb +25 -43
  8. data/lib/gcloud/bigquery/copy_job.rb +13 -13
  9. data/lib/gcloud/bigquery/data.rb +20 -16
  10. data/lib/gcloud/bigquery/dataset.rb +202 -177
  11. data/lib/gcloud/bigquery/dataset/access.rb +118 -104
  12. data/lib/gcloud/bigquery/dataset/list.rb +14 -18
  13. data/lib/gcloud/bigquery/extract_job.rb +12 -12
  14. data/lib/gcloud/bigquery/insert_response.rb +12 -14
  15. data/lib/gcloud/bigquery/job.rb +45 -57
  16. data/lib/gcloud/bigquery/job/list.rb +18 -24
  17. data/lib/gcloud/bigquery/load_job.rb +35 -27
  18. data/lib/gcloud/bigquery/project.rb +53 -73
  19. data/lib/gcloud/bigquery/query_data.rb +28 -35
  20. data/lib/gcloud/bigquery/query_job.rb +18 -18
  21. data/lib/gcloud/bigquery/schema.rb +359 -0
  22. data/lib/gcloud/bigquery/service.rb +506 -0
  23. data/lib/gcloud/bigquery/table.rb +185 -266
  24. data/lib/gcloud/bigquery/table/list.rb +15 -19
  25. data/lib/gcloud/bigquery/view.rb +126 -81
  26. data/lib/gcloud/datastore.rb +39 -27
  27. data/lib/gcloud/datastore/commit.rb +2 -2
  28. data/lib/gcloud/datastore/dataset.rb +8 -19
  29. data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -4
  30. data/lib/gcloud/datastore/dataset/query_results.rb +0 -2
  31. data/lib/gcloud/datastore/entity.rb +7 -1
  32. data/lib/gcloud/datastore/errors.rb +5 -27
  33. data/lib/gcloud/datastore/grpc_utils.rb +4 -3
  34. data/lib/gcloud/datastore/key.rb +6 -0
  35. data/lib/gcloud/datastore/service.rb +18 -12
  36. data/lib/gcloud/datastore/transaction.rb +0 -10
  37. data/lib/gcloud/dns.rb +29 -19
  38. data/lib/gcloud/dns/change.rb +10 -15
  39. data/lib/gcloud/dns/change/list.rb +4 -4
  40. data/lib/gcloud/dns/importer.rb +1 -1
  41. data/lib/gcloud/dns/project.rb +32 -49
  42. data/lib/gcloud/dns/record.rb +8 -2
  43. data/lib/gcloud/dns/record/list.rb +4 -4
  44. data/lib/gcloud/dns/service.rb +167 -0
  45. data/lib/gcloud/dns/zone.rb +33 -52
  46. data/lib/gcloud/dns/zone/list.rb +12 -16
  47. data/lib/gcloud/errors.rb +31 -19
  48. data/lib/gcloud/logging.rb +50 -39
  49. data/lib/gcloud/logging/entry.rb +197 -24
  50. data/lib/gcloud/logging/entry/list.rb +0 -2
  51. data/lib/gcloud/logging/logger.rb +1 -1
  52. data/lib/gcloud/logging/metric.rb +3 -9
  53. data/lib/gcloud/logging/metric/list.rb +0 -2
  54. data/lib/gcloud/logging/project.rb +58 -54
  55. data/lib/gcloud/logging/resource_descriptor.rb +2 -2
  56. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -2
  57. data/lib/gcloud/logging/service.rb +32 -23
  58. data/lib/gcloud/logging/sink.rb +8 -14
  59. data/lib/gcloud/logging/sink/list.rb +0 -2
  60. data/lib/gcloud/pubsub.rb +21 -16
  61. data/lib/gcloud/pubsub/policy.rb +204 -0
  62. data/lib/gcloud/pubsub/project.rb +26 -38
  63. data/lib/gcloud/pubsub/service.rb +39 -31
  64. data/lib/gcloud/pubsub/subscription.rb +56 -59
  65. data/lib/gcloud/pubsub/subscription/list.rb +4 -4
  66. data/lib/gcloud/pubsub/topic.rb +69 -66
  67. data/lib/gcloud/pubsub/topic/list.rb +0 -2
  68. data/lib/gcloud/pubsub/topic/{batch.rb → publisher.rb} +15 -2
  69. data/lib/gcloud/resource_manager.rb +27 -26
  70. data/lib/gcloud/resource_manager/manager.rb +19 -39
  71. data/lib/gcloud/resource_manager/policy.rb +211 -0
  72. data/lib/gcloud/resource_manager/project.rb +97 -121
  73. data/lib/gcloud/resource_manager/project/list.rb +7 -7
  74. data/lib/gcloud/resource_manager/project/updater.rb +4 -9
  75. data/lib/gcloud/resource_manager/service.rb +127 -0
  76. data/lib/gcloud/storage.rb +24 -42
  77. data/lib/gcloud/storage/bucket.rb +104 -192
  78. data/lib/gcloud/storage/bucket/acl.rb +47 -143
  79. data/lib/gcloud/storage/bucket/cors.rb +55 -11
  80. data/lib/gcloud/storage/bucket/list.rb +14 -14
  81. data/lib/gcloud/storage/errors.rb +3 -43
  82. data/lib/gcloud/storage/file.rb +114 -111
  83. data/lib/gcloud/storage/file/acl.rb +27 -113
  84. data/lib/gcloud/storage/file/list.rb +21 -21
  85. data/lib/gcloud/storage/project.rb +49 -59
  86. data/lib/gcloud/storage/service.rb +347 -0
  87. data/lib/gcloud/translate.rb +24 -14
  88. data/lib/gcloud/translate/api.rb +12 -21
  89. data/lib/gcloud/translate/detection.rb +5 -5
  90. data/lib/gcloud/translate/language.rb +1 -1
  91. data/lib/gcloud/translate/service.rb +80 -0
  92. data/lib/gcloud/translate/translation.rb +6 -6
  93. data/lib/gcloud/version.rb +1 -1
  94. data/lib/gcloud/vision.rb +24 -15
  95. data/lib/gcloud/vision/annotate.rb +24 -21
  96. data/lib/gcloud/vision/annotation.rb +9 -9
  97. data/lib/gcloud/vision/annotation/entity.rb +11 -11
  98. data/lib/gcloud/vision/annotation/face.rb +25 -25
  99. data/lib/gcloud/vision/annotation/properties.rb +8 -8
  100. data/lib/gcloud/vision/annotation/safe_search.rb +4 -4
  101. data/lib/gcloud/vision/annotation/text.rb +7 -7
  102. data/lib/gcloud/vision/annotation/vertex.rb +1 -1
  103. data/lib/gcloud/vision/image.rb +11 -11
  104. data/lib/gcloud/vision/location.rb +5 -2
  105. data/lib/gcloud/vision/project.rb +14 -16
  106. data/lib/gcloud/vision/service.rb +66 -0
  107. data/lib/google/api_client.rb +0 -0
  108. metadata +27 -24
  109. data/lib/gcloud/bigquery/connection.rb +0 -624
  110. data/lib/gcloud/bigquery/errors.rb +0 -68
  111. data/lib/gcloud/bigquery/table/schema.rb +0 -234
  112. data/lib/gcloud/dns/connection.rb +0 -173
  113. data/lib/gcloud/dns/errors.rb +0 -68
  114. data/lib/gcloud/resource_manager/connection.rb +0 -134
  115. data/lib/gcloud/resource_manager/errors.rb +0 -68
  116. data/lib/gcloud/storage/connection.rb +0 -444
  117. data/lib/gcloud/translate/connection.rb +0 -85
  118. data/lib/gcloud/translate/errors.rb +0 -68
  119. data/lib/gcloud/upload.rb +0 -95
  120. data/lib/gcloud/vision/connection.rb +0 -63
  121. data/lib/gcloud/vision/errors.rb +0 -69
@@ -201,8 +201,6 @@ module Gcloud
201
201
  lookup_res = service.lookup(*Array(keys).flatten.map(&:to_grpc),
202
202
  transaction: @id)
203
203
  LookupResults.from_grpc lookup_res, service, nil, @id
204
- rescue GRPC::BadStatus => e
205
- raise Gcloud::Error.from_error(e)
206
204
  end
207
205
  alias_method :lookup, :find_all
208
206
 
@@ -237,8 +235,6 @@ module Gcloud
237
235
  query_res = service.run_query query.to_grpc, namespace,
238
236
  transaction: @id
239
237
  QueryResults.from_grpc query_res, service, namespace, query.to_grpc.dup
240
- rescue GRPC::BadStatus => e
241
- raise Gcloud::Error.from_error(e)
242
238
  end
243
239
  alias_method :run_query, :run
244
240
 
@@ -251,8 +247,6 @@ module Gcloud
251
247
  ensure_service!
252
248
  tx_res = service.begin_transaction
253
249
  @id = tx_res.transaction
254
- rescue GRPC::BadStatus => e
255
- raise Gcloud::Error.from_error(e)
256
250
  end
257
251
  alias_method :begin_transaction, :start
258
252
 
@@ -319,8 +313,6 @@ module Gcloud
319
313
  # Make sure all entity keys are frozen so all show as persisted
320
314
  entities.each { |e| e.key.freeze unless e.persisted? }
321
315
  true
322
- rescue GRPC::BadStatus => e
323
- raise Gcloud::Error.from_error(e)
324
316
  end
325
317
 
326
318
  ##
@@ -356,8 +348,6 @@ module Gcloud
356
348
  ensure_service!
357
349
  service.rollback @id
358
350
  true
359
- rescue GRPC::BadStatus => e
360
- raise Gcloud::Error.from_error(e)
361
351
  end
362
352
 
363
353
  ##
data/lib/gcloud/dns.rb CHANGED
@@ -36,6 +36,9 @@ module Gcloud
36
36
  # The default scope is:
37
37
  #
38
38
  # * `https://www.googleapis.com/auth/ndev.clouddns.readwrite`
39
+ # @param [Integer] retries Number of times to retry requests on server error.
40
+ # The default value is `3`. Optional.
41
+ # @param [Integer] timeout Default timeout to use in requests. Optional.
39
42
  #
40
43
  # @return [Gcloud::Dns::Project]
41
44
  #
@@ -47,14 +50,21 @@ module Gcloud
47
50
  #
48
51
  # zone = dns.zone "example-com"
49
52
  #
50
- def self.dns project = nil, keyfile = nil, scope: nil
53
+ def self.dns project = nil, keyfile = nil, scope: nil, retries: nil,
54
+ timeout: nil
51
55
  project ||= Gcloud::Dns::Project.default_project
56
+ project = project.to_s # Always cast to a string
57
+ fail ArgumentError, "project is missing" if project.empty?
58
+
52
59
  if keyfile.nil?
53
60
  credentials = Gcloud::Dns::Credentials.default scope: scope
54
61
  else
55
62
  credentials = Gcloud::Dns::Credentials.new keyfile, scope: scope
56
63
  end
57
- Gcloud::Dns::Project.new project, credentials
64
+
65
+ Gcloud::Dns::Project.new(
66
+ Gcloud::Dns::Service.new(
67
+ project, credentials, retries: retries, timeout: timeout))
58
68
  end
59
69
 
60
70
  ##
@@ -67,8 +77,8 @@ module Gcloud
67
77
  # relied upon by Google. To learn more, read [What is Google Cloud
68
78
  # DNS?](https://cloud.google.com/dns/what-is-cloud-dns).
69
79
  #
70
- # Gcloud's goal is to provide an API that is familiar and comfortable to
71
- # Rubyists. Authentication is handled by {Gcloud#dns}. You can provide the
80
+ # The goal of gcloud-ruby is to provide an API that is comfortable
81
+ # to Rubyists. Authentication is handled by {Gcloud#dns}. You can provide the
72
82
  # project and credential information to connect to the Cloud DNS service, or
73
83
  # if you are running on Google Compute Engine this configuration is taken care
74
84
  # of for you. You can read more about the options for connecting in the
@@ -164,9 +174,10 @@ module Gcloud
164
174
  #
165
175
  # Whenever you change the set of records belonging to a zone, the zone's start
166
176
  # of authority (SOA) record should be updated with a higher serial number. The
167
- # gcloud library automates this update for you, deleting the old SOA record
168
- # and adding an updated one, as shown in the example above. You can disable or
169
- # modify this behavior, of course. See {Gcloud::Dns::Zone#update} for details.
177
+ # gcloud-ruby library automates this update for you, deleting the old SOA
178
+ # record and adding an updated one, as shown in the example above. You can
179
+ # disable or modify this behavior, of course. See {Gcloud::Dns::Zone#update}
180
+ # for details.
170
181
  #
171
182
  # You can retrieve records by name and type. The name argument can be a
172
183
  # subdomain (e.g., `www`) fragment for convenience, but notice that the
@@ -301,24 +312,23 @@ module Gcloud
301
312
  # zone.export "path/to/db.example.com"
302
313
  # ```
303
314
  #
304
- # ## Configuring Backoff
315
+ # ## Configuring retries and timeout
305
316
  #
306
- # The {Gcloud::Backoff} class allows users to globally configure how Cloud API
307
- # requests are automatically retried in the case of some errors, such as a
308
- # `500` or `503` status code, or a specific internal error code such as
309
- # `rateLimitExceeded`.
317
+ # You can configure how many times API requests may be automatically retried.
318
+ # When an API request fails, the response will be inspected to see if the
319
+ # request meets criteria indicating that it may succeed on retry, such as
320
+ # `500` and `503` status codes or a specific internal error code such as
321
+ # `rateLimitExceeded`. If it meets the criteria, the request will be retried
322
+ # after a delay. If another error occurs, the delay will be increased before a
323
+ # subsequent attempt, until the `retries` limit is reached.
310
324
  #
311
- # If an API call fails, the response will be inspected to see if the call
312
- # should be retried. If the response matches the criteria, then the request
313
- # will be retried after a delay. If another error occurs, the delay will be
314
- # increased incrementally before a subsequent attempt. The first retry will be
315
- # delayed one second, the second retry two seconds, and so on.
325
+ # You can also set the request `timeout` value in seconds.
316
326
  #
317
327
  # ```ruby
318
328
  # require "gcloud"
319
- # require "gcloud/backoff"
320
329
  #
321
- # Gcloud::Backoff.retries = 5 # Raise the maximum number of retries from 3
330
+ # gcloud = Gcloud.new
331
+ # dns = gcloud.dns retries: 10, timeout: 120
322
332
  # ```
323
333
  #
324
334
  module Dns
@@ -57,28 +57,28 @@ module Gcloud
57
57
  # Unique identifier for the resource; defined by the server.
58
58
  #
59
59
  def id
60
- @gapi["id"]
60
+ @gapi.id
61
61
  end
62
62
 
63
63
  ##
64
64
  # The records added in this change request.
65
65
  #
66
66
  def additions
67
- Array(@gapi["additions"]).map { |gapi| Record.from_gapi gapi }
67
+ Array(@gapi.additions).map { |gapi| Record.from_gapi gapi }
68
68
  end
69
69
 
70
70
  ##
71
71
  # The records removed in this change request.
72
72
  #
73
73
  def deletions
74
- Array(@gapi["deletions"]).map { |gapi| Record.from_gapi gapi }
74
+ Array(@gapi.deletions).map { |gapi| Record.from_gapi gapi }
75
75
  end
76
76
 
77
77
  ##
78
78
  # Status of the operation. Values are `"done"` and `"pending"`.
79
79
  #
80
80
  def status
81
- @gapi["status"]
81
+ @gapi.status
82
82
  end
83
83
 
84
84
  ##
@@ -99,7 +99,7 @@ module Gcloud
99
99
  # The time that this operation was started by the server.
100
100
  #
101
101
  def started_at
102
- Time.parse @gapi["startTime"]
102
+ Time.parse @gapi.start_time
103
103
  rescue
104
104
  nil
105
105
  end
@@ -107,13 +107,8 @@ module Gcloud
107
107
  ##
108
108
  # Reloads the change with updated status from the DNS service.
109
109
  def reload!
110
- ensure_connection!
111
- resp = zone.connection.get_change @zone.id, id
112
- if resp.success?
113
- @gapi = resp.data
114
- else
115
- fail ApiError.from_response(resp)
116
- end
110
+ ensure_service!
111
+ @gapi = zone.service.get_change @zone.id, id
117
112
  end
118
113
  alias_method :refresh!, :reload!
119
114
 
@@ -154,9 +149,9 @@ module Gcloud
154
149
  protected
155
150
 
156
151
  ##
157
- # Raise an error unless an active connection is available.
158
- def ensure_connection!
159
- fail "Must have active connection" unless zone && zone.connection
152
+ # Raise an error unless an active service is available.
153
+ def ensure_service!
154
+ fail "Must have active connection" unless zone && zone.service
160
155
  end
161
156
  end
162
157
  end
@@ -149,11 +149,11 @@ module Gcloud
149
149
 
150
150
  ##
151
151
  # @private New Changes::List from a response object.
152
- def self.from_response resp, zone, max = nil, order = nil
153
- changes = new(Array(resp.data["changes"]).map do |gapi_object|
154
- Change.from_gapi gapi_object, zone
152
+ def self.from_gapi gapi, zone, max = nil, order = nil
153
+ changes = new(Array(gapi.changes).map do |g|
154
+ Change.from_gapi g, zone
155
155
  end)
156
- changes.instance_variable_set "@token", resp.data["nextPageToken"]
156
+ changes.instance_variable_set "@token", gapi.next_page_token
157
157
  changes.instance_variable_set "@zone", zone
158
158
  changes.instance_variable_set "@max", max
159
159
  changes.instance_variable_set "@order", order
@@ -83,7 +83,7 @@ module Gcloud
83
83
  type = r.first
84
84
  type = :aaaa if type == :a4
85
85
  r.last.each do |zf_record|
86
- name = Connection.fqdn(zf_record[:name], @zonefile.origin)
86
+ name = Service.fqdn(zf_record[:name], @zonefile.origin)
87
87
  key = [name, type]
88
88
  (@merged_zf_records[key] ||= []) << zf_record
89
89
  end
@@ -13,11 +13,11 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
+ require "gcloud/errors"
16
17
  require "gcloud/gce"
17
- require "gcloud/dns/connection"
18
+ require "gcloud/dns/service"
18
19
  require "gcloud/dns/credentials"
19
20
  require "gcloud/dns/zone"
20
- require "gcloud/dns/errors"
21
21
 
22
22
  module Gcloud
23
23
  module Dns
@@ -41,21 +41,19 @@ module Gcloud
41
41
  # See {Gcloud#dns}
42
42
  class Project
43
43
  ##
44
- # @private The Connection object.
45
- attr_accessor :connection
44
+ # @private The Service object.
45
+ attr_accessor :service
46
46
 
47
47
  ##
48
48
  # @private The Google API Client object.
49
49
  attr_accessor :gapi
50
50
 
51
51
  ##
52
- # @private Creates a new Connection instance.
52
+ # @private Creates a new Service instance.
53
53
  #
54
54
  # See {Gcloud.dns}
55
- def initialize project, credentials
56
- project = project.to_s # Always cast to a string
57
- fail ArgumentError, "project is missing" if project.empty?
58
- @connection = Connection.new project, credentials
55
+ def initialize service
56
+ @service = service
59
57
  @gapi = nil
60
58
  end
61
59
 
@@ -71,7 +69,7 @@ module Gcloud
71
69
  # dns.project #=> "my-todo-project"
72
70
  #
73
71
  def project
74
- connection.project
72
+ service.project
75
73
  end
76
74
  alias_method :id, :project
77
75
 
@@ -79,49 +77,49 @@ module Gcloud
79
77
  # The project number.
80
78
  def number
81
79
  reload! if @gapi.nil?
82
- @gapi["number"]
80
+ @gapi.number
83
81
  end
84
82
 
85
83
  ##
86
84
  # Maximum allowed number of zones in the project.
87
85
  def zones_quota
88
86
  reload! if @gapi.nil?
89
- @gapi["quota"]["managedZones"] if @gapi["quota"]
87
+ @gapi.quota.managed_zones if @gapi.quota
90
88
  end
91
89
 
92
90
  ##
93
91
  # Maximum allowed number of data entries per record.
94
92
  def data_per_record
95
93
  reload! if @gapi.nil?
96
- @gapi["quota"]["resourceRecordsPerRrset"] if @gapi["quota"]
94
+ @gapi.quota.resource_records_per_rrset if @gapi.quota
97
95
  end
98
96
 
99
97
  ##
100
98
  # Maximum allowed number of records to add per change.
101
99
  def additions_per_change
102
100
  reload! if @gapi.nil?
103
- @gapi["quota"]["rrsetAdditionsPerChange"] if @gapi["quota"]
101
+ @gapi.quota.rrset_additions_per_change if @gapi.quota
104
102
  end
105
103
 
106
104
  ##
107
105
  # Maximum allowed number of records to delete per change.
108
106
  def deletions_per_change
109
107
  reload! if @gapi.nil?
110
- @gapi["quota"]["rrsetDeletionsPerChange"] if @gapi["quota"]
108
+ @gapi.quota.rrset_deletions_per_change if @gapi.quota
111
109
  end
112
110
 
113
111
  ##
114
112
  # Maximum allowed number of records per zone in the project.
115
113
  def records_per_zone
116
114
  reload! if @gapi.nil?
117
- @gapi["quota"]["rrsetsPerManagedZone"] if @gapi["quota"]
115
+ @gapi.quota.rrsets_per_managed_zone if @gapi.quota
118
116
  end
119
117
 
120
118
  ##
121
119
  # Maximum allowed total bytes size for all the data in one change.
122
120
  def total_data_per_change
123
121
  reload! if @gapi.nil?
124
- @gapi["quota"]["totalRrdataSizePerChange"] if @gapi["quota"]
122
+ @gapi.quota.total_rrdata_size_per_change if @gapi.quota
125
123
  end
126
124
 
127
125
  ##
@@ -150,13 +148,11 @@ module Gcloud
150
148
  # puts zone.name
151
149
  #
152
150
  def zone zone_id
153
- ensure_connection!
154
- resp = connection.get_zone zone_id
155
- if resp.success?
156
- Zone.from_gapi resp.data, connection
157
- else
158
- nil
159
- end
151
+ ensure_service!
152
+ gapi = service.get_zone zone_id
153
+ Zone.from_gapi gapi, service
154
+ rescue Gcloud::NotFoundError
155
+ nil
160
156
  end
161
157
  alias_method :find_zone, :zone
162
158
  alias_method :get_zone, :zone
@@ -191,13 +187,9 @@ module Gcloud
191
187
  # end
192
188
  #
193
189
  def zones token: nil, max: nil
194
- ensure_connection!
195
- resp = connection.list_zones token: token, max: max
196
- if resp.success?
197
- Zone::List.from_response resp, connection, max
198
- else
199
- fail ApiError.from_response(resp)
200
- end
190
+ ensure_service!
191
+ gapi = service.list_zones token: token, max: max
192
+ Zone::List.from_gapi gapi, service, max
201
193
  end
202
194
  alias_method :find_zones, :zones
203
195
 
@@ -228,27 +220,18 @@ module Gcloud
228
220
  #
229
221
  def create_zone zone_name, zone_dns, description: nil,
230
222
  name_server_set: nil
231
- ensure_connection!
232
- resp = connection.create_zone zone_name, zone_dns,
233
- description: description,
234
- name_server_set: name_server_set
235
- if resp.success?
236
- Zone.from_gapi resp.data, connection
237
- else
238
- fail ApiError.from_response(resp)
239
- end
223
+ ensure_service!
224
+ gapi = service.create_zone zone_name, zone_dns,
225
+ description: description,
226
+ name_server_set: name_server_set
227
+ Zone.from_gapi gapi, service
240
228
  end
241
229
 
242
230
  ##
243
231
  # Reloads the change with updated status from the DNS service.
244
232
  def reload!
245
- ensure_connection!
246
- resp = connection.get_project
247
- if resp.success?
248
- @gapi = resp.data
249
- else
250
- fail ApiError.from_response(resp)
251
- end
233
+ ensure_service!
234
+ @gapi = service.get_project
252
235
  end
253
236
  alias_method :refresh!, :reload!
254
237
 
@@ -256,8 +239,8 @@ module Gcloud
256
239
 
257
240
  ##
258
241
  # Raise an error unless an active connection is available.
259
- def ensure_connection!
260
- fail "Must have active connection" unless connection
242
+ def ensure_service!
243
+ fail "Must have active connection" unless service
261
244
  end
262
245
  end
263
246
  end
@@ -127,13 +127,19 @@ module Gcloud
127
127
  ##
128
128
  # @private New Record from a Google API Client object.
129
129
  def self.from_gapi gapi
130
- new gapi["name"], gapi["type"], gapi["ttl"], gapi["rrdatas"]
130
+ new gapi.name, gapi.type, gapi.ttl, gapi.rrdatas
131
131
  end
132
132
 
133
133
  ##
134
134
  # @private Convert the record object to a Google API hash.
135
135
  def to_gapi
136
- { "name" => name, "type" => type, "ttl" => ttl, "rrdatas" => data }
136
+ Google::Apis::DnsV1::ResourceRecordSet.new(
137
+ kind: "dns#resourceRecordSet",
138
+ name: name,
139
+ rrdatas: data,
140
+ ttl: ttl,
141
+ type: type
142
+ )
137
143
  end
138
144
 
139
145
  # @private
@@ -149,11 +149,11 @@ module Gcloud
149
149
 
150
150
  ##
151
151
  # @private New Records::List from a response object.
152
- def self.from_response resp, zone, name = nil, type = nil, max = nil
153
- records = new(Array(resp.data["rrsets"]).map do |gapi_object|
154
- Record.from_gapi gapi_object
152
+ def self.from_gapi gapi, zone, name = nil, type = nil, max = nil
153
+ records = new(Array(gapi.rrsets).map do |g|
154
+ Record.from_gapi g
155
155
  end)
156
- records.instance_variable_set "@token", resp.data["nextPageToken"]
156
+ records.instance_variable_set "@token", gapi.next_page_token
157
157
  records.instance_variable_set "@zone", zone
158
158
  records.instance_variable_set "@name", name
159
159
  records.instance_variable_set "@type", type