gcloud 0.12.2 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +5 -13
  2. data/lib/gcloud.rb +27 -456
  3. data/lib/gcloud/bigquery.rb +2 -382
  4. data/lib/gcloud/datastore.rb +2 -576
  5. data/lib/gcloud/dns.rb +2 -321
  6. data/lib/gcloud/logging.rb +1 -322
  7. data/lib/gcloud/pubsub.rb +2 -476
  8. data/lib/gcloud/resource_manager.rb +2 -273
  9. data/lib/gcloud/storage.rb +2 -440
  10. data/lib/gcloud/translate.rb +1 -250
  11. data/lib/gcloud/version.rb +2 -2
  12. data/lib/gcloud/vision.rb +1 -501
  13. metadata +36 -332
  14. data/AUTHENTICATION.md +0 -75
  15. data/CHANGELOG.md +0 -382
  16. data/OVERVIEW.md +0 -259
  17. data/lib/gcloud/backoff.rb +0 -150
  18. data/lib/gcloud/bigquery/copy_job.rb +0 -97
  19. data/lib/gcloud/bigquery/credentials.rb +0 -29
  20. data/lib/gcloud/bigquery/data.rb +0 -239
  21. data/lib/gcloud/bigquery/dataset.rb +0 -753
  22. data/lib/gcloud/bigquery/dataset/access.rb +0 -507
  23. data/lib/gcloud/bigquery/dataset/list.rb +0 -169
  24. data/lib/gcloud/bigquery/extract_job.rb +0 -117
  25. data/lib/gcloud/bigquery/insert_response.rb +0 -81
  26. data/lib/gcloud/bigquery/job.rb +0 -299
  27. data/lib/gcloud/bigquery/job/list.rb +0 -172
  28. data/lib/gcloud/bigquery/load_job.rb +0 -202
  29. data/lib/gcloud/bigquery/project.rb +0 -475
  30. data/lib/gcloud/bigquery/query_data.rb +0 -234
  31. data/lib/gcloud/bigquery/query_job.rb +0 -137
  32. data/lib/gcloud/bigquery/schema.rb +0 -359
  33. data/lib/gcloud/bigquery/service.rb +0 -506
  34. data/lib/gcloud/bigquery/table.rb +0 -1141
  35. data/lib/gcloud/bigquery/table/list.rb +0 -180
  36. data/lib/gcloud/bigquery/view.rb +0 -475
  37. data/lib/gcloud/credentials.rb +0 -129
  38. data/lib/gcloud/datastore/commit.rb +0 -148
  39. data/lib/gcloud/datastore/credentials.rb +0 -35
  40. data/lib/gcloud/datastore/cursor.rb +0 -76
  41. data/lib/gcloud/datastore/dataset.rb +0 -660
  42. data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
  43. data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
  44. data/lib/gcloud/datastore/entity.rb +0 -449
  45. data/lib/gcloud/datastore/errors.rb +0 -41
  46. data/lib/gcloud/datastore/gql_query.rb +0 -211
  47. data/lib/gcloud/datastore/grpc_utils.rb +0 -132
  48. data/lib/gcloud/datastore/key.rb +0 -281
  49. data/lib/gcloud/datastore/properties.rb +0 -128
  50. data/lib/gcloud/datastore/query.rb +0 -348
  51. data/lib/gcloud/datastore/service.rb +0 -167
  52. data/lib/gcloud/datastore/transaction.rb +0 -362
  53. data/lib/gcloud/dns/change.rb +0 -158
  54. data/lib/gcloud/dns/change/list.rb +0 -173
  55. data/lib/gcloud/dns/credentials.rb +0 -29
  56. data/lib/gcloud/dns/importer.rb +0 -183
  57. data/lib/gcloud/dns/project.rb +0 -247
  58. data/lib/gcloud/dns/record.rb +0 -170
  59. data/lib/gcloud/dns/record/list.rb +0 -174
  60. data/lib/gcloud/dns/service.rb +0 -167
  61. data/lib/gcloud/dns/zone.rb +0 -759
  62. data/lib/gcloud/dns/zone/list.rb +0 -168
  63. data/lib/gcloud/dns/zone/transaction.rb +0 -176
  64. data/lib/gcloud/errors.rb +0 -206
  65. data/lib/gcloud/gce.rb +0 -56
  66. data/lib/gcloud/grpc_utils.rb +0 -87
  67. data/lib/gcloud/logging/credentials.rb +0 -29
  68. data/lib/gcloud/logging/entry.rb +0 -465
  69. data/lib/gcloud/logging/entry/http_request.rb +0 -141
  70. data/lib/gcloud/logging/entry/list.rb +0 -177
  71. data/lib/gcloud/logging/entry/operation.rb +0 -90
  72. data/lib/gcloud/logging/logger.rb +0 -307
  73. data/lib/gcloud/logging/metric.rb +0 -169
  74. data/lib/gcloud/logging/metric/list.rb +0 -172
  75. data/lib/gcloud/logging/project.rb +0 -642
  76. data/lib/gcloud/logging/resource.rb +0 -84
  77. data/lib/gcloud/logging/resource_descriptor.rb +0 -137
  78. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
  79. data/lib/gcloud/logging/service.rb +0 -267
  80. data/lib/gcloud/logging/sink.rb +0 -227
  81. data/lib/gcloud/logging/sink/list.rb +0 -171
  82. data/lib/gcloud/pubsub/credentials.rb +0 -29
  83. data/lib/gcloud/pubsub/message.rb +0 -94
  84. data/lib/gcloud/pubsub/policy.rb +0 -204
  85. data/lib/gcloud/pubsub/project.rb +0 -482
  86. data/lib/gcloud/pubsub/received_message.rb +0 -160
  87. data/lib/gcloud/pubsub/service.rb +0 -334
  88. data/lib/gcloud/pubsub/subscription.rb +0 -565
  89. data/lib/gcloud/pubsub/subscription/list.rb +0 -208
  90. data/lib/gcloud/pubsub/topic.rb +0 -511
  91. data/lib/gcloud/pubsub/topic/list.rb +0 -174
  92. data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
  93. data/lib/gcloud/resource_manager/credentials.rb +0 -30
  94. data/lib/gcloud/resource_manager/manager.rb +0 -266
  95. data/lib/gcloud/resource_manager/policy.rb +0 -211
  96. data/lib/gcloud/resource_manager/project.rb +0 -484
  97. data/lib/gcloud/resource_manager/project/list.rb +0 -167
  98. data/lib/gcloud/resource_manager/project/updater.rb +0 -130
  99. data/lib/gcloud/resource_manager/service.rb +0 -127
  100. data/lib/gcloud/storage/bucket.rb +0 -775
  101. data/lib/gcloud/storage/bucket/acl.rb +0 -810
  102. data/lib/gcloud/storage/bucket/cors.rb +0 -153
  103. data/lib/gcloud/storage/bucket/list.rb +0 -172
  104. data/lib/gcloud/storage/credentials.rb +0 -29
  105. data/lib/gcloud/storage/errors.rb +0 -65
  106. data/lib/gcloud/storage/file.rb +0 -842
  107. data/lib/gcloud/storage/file/acl.rb +0 -425
  108. data/lib/gcloud/storage/file/list.rb +0 -191
  109. data/lib/gcloud/storage/file/verifier.rb +0 -67
  110. data/lib/gcloud/storage/project.rb +0 -316
  111. data/lib/gcloud/storage/service.rb +0 -347
  112. data/lib/gcloud/translate/api.rb +0 -241
  113. data/lib/gcloud/translate/detection.rb +0 -137
  114. data/lib/gcloud/translate/language.rb +0 -69
  115. data/lib/gcloud/translate/service.rb +0 -80
  116. data/lib/gcloud/translate/translation.rb +0 -112
  117. data/lib/gcloud/vision/annotate.rb +0 -224
  118. data/lib/gcloud/vision/annotation.rb +0 -455
  119. data/lib/gcloud/vision/annotation/entity.rb +0 -234
  120. data/lib/gcloud/vision/annotation/face.rb +0 -1750
  121. data/lib/gcloud/vision/annotation/properties.rb +0 -245
  122. data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
  123. data/lib/gcloud/vision/annotation/text.rb +0 -236
  124. data/lib/gcloud/vision/annotation/vertex.rb +0 -108
  125. data/lib/gcloud/vision/credentials.rb +0 -29
  126. data/lib/gcloud/vision/image.rb +0 -590
  127. data/lib/gcloud/vision/location.rb +0 -115
  128. data/lib/gcloud/vision/project.rb +0 -278
  129. data/lib/gcloud/vision/service.rb +0 -66
  130. data/lib/google/api/annotations.rb +0 -14
  131. data/lib/google/api/http.rb +0 -30
  132. data/lib/google/api/label.rb +0 -24
  133. data/lib/google/api/monitored_resource.rb +0 -25
  134. data/lib/google/datastore/v1beta3/datastore.rb +0 -115
  135. data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
  136. data/lib/google/datastore/v1beta3/entity.rb +0 -63
  137. data/lib/google/datastore/v1beta3/query.rb +0 -128
  138. data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
  139. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
  140. data/lib/google/example/library/v1/library.rb +0 -91
  141. data/lib/google/example/library/v1/library_services.rb +0 -40
  142. data/lib/google/iam/v1/iam_policy.rb +0 -33
  143. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  144. data/lib/google/iam/v1/policy.rb +0 -25
  145. data/lib/google/logging/type/http_request.rb +0 -28
  146. data/lib/google/logging/type/log_severity.rb +0 -27
  147. data/lib/google/logging/v2/log_entry.rb +0 -44
  148. data/lib/google/logging/v2/logging.rb +0 -56
  149. data/lib/google/logging/v2/logging_config.rb +0 -59
  150. data/lib/google/logging/v2/logging_config_services.rb +0 -32
  151. data/lib/google/logging/v2/logging_metrics.rb +0 -51
  152. data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
  153. data/lib/google/logging/v2/logging_services.rb +0 -31
  154. data/lib/google/longrunning/operations.rb +0 -50
  155. data/lib/google/longrunning/operations_services.rb +0 -29
  156. data/lib/google/protobuf/descriptor.rb +0 -0
  157. data/lib/google/pubsub/v1/pubsub.rb +0 -129
  158. data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
  159. data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
  160. data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
  161. data/lib/google/rpc/code.rb +0 -32
  162. data/lib/google/rpc/error_details.rb +0 -61
  163. data/lib/google/rpc/status.rb +0 -19
  164. data/lib/google/type/color.rb +0 -20
  165. data/lib/google/type/date.rb +0 -18
  166. data/lib/google/type/dayofweek.rb +0 -23
  167. data/lib/google/type/latlng.rb +0 -17
  168. data/lib/google/type/money.rb +0 -18
  169. data/lib/google/type/timeofday.rb +0 -19
@@ -1,247 +0,0 @@
1
- # Copyright 2015 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/errors"
17
- require "gcloud/gce"
18
- require "gcloud/dns/service"
19
- require "gcloud/dns/credentials"
20
- require "gcloud/dns/zone"
21
-
22
- module Gcloud
23
- module Dns
24
- ##
25
- # # Project
26
- #
27
- # The project is a top level container for resources including Cloud DNS
28
- # ManagedZones. Projects can be created only in the [Google Developers
29
- # Console](https://console.developers.google.com).
30
- #
31
- # @example
32
- # require "gcloud"
33
- #
34
- # gcloud = Gcloud.new
35
- # dns = gcloud.dns
36
- # zone = dns.zone "example-com"
37
- # zone.records.each do |record|
38
- # puts record.name
39
- # end
40
- #
41
- # See {Gcloud#dns}
42
- class Project
43
- ##
44
- # @private The Service object.
45
- attr_accessor :service
46
-
47
- ##
48
- # @private The Google API Client object.
49
- attr_accessor :gapi
50
-
51
- ##
52
- # @private Creates a new Service instance.
53
- #
54
- # See {Gcloud.dns}
55
- def initialize service
56
- @service = service
57
- @gapi = nil
58
- end
59
-
60
- ##
61
- # The unique ID string for the current project.
62
- #
63
- # @example
64
- # require "gcloud"
65
- #
66
- # gcloud = Gcloud.new "my-todo-project", "/path/to/keyfile.json"
67
- # dns = gcloud.dns
68
- #
69
- # dns.project #=> "my-todo-project"
70
- #
71
- def project
72
- service.project
73
- end
74
- alias_method :id, :project
75
-
76
- ##
77
- # The project number.
78
- def number
79
- reload! if @gapi.nil?
80
- @gapi.number
81
- end
82
-
83
- ##
84
- # Maximum allowed number of zones in the project.
85
- def zones_quota
86
- reload! if @gapi.nil?
87
- @gapi.quota.managed_zones if @gapi.quota
88
- end
89
-
90
- ##
91
- # Maximum allowed number of data entries per record.
92
- def data_per_record
93
- reload! if @gapi.nil?
94
- @gapi.quota.resource_records_per_rrset if @gapi.quota
95
- end
96
-
97
- ##
98
- # Maximum allowed number of records to add per change.
99
- def additions_per_change
100
- reload! if @gapi.nil?
101
- @gapi.quota.rrset_additions_per_change if @gapi.quota
102
- end
103
-
104
- ##
105
- # Maximum allowed number of records to delete per change.
106
- def deletions_per_change
107
- reload! if @gapi.nil?
108
- @gapi.quota.rrset_deletions_per_change if @gapi.quota
109
- end
110
-
111
- ##
112
- # Maximum allowed number of records per zone in the project.
113
- def records_per_zone
114
- reload! if @gapi.nil?
115
- @gapi.quota.rrsets_per_managed_zone if @gapi.quota
116
- end
117
-
118
- ##
119
- # Maximum allowed total bytes size for all the data in one change.
120
- def total_data_per_change
121
- reload! if @gapi.nil?
122
- @gapi.quota.total_rrdata_size_per_change if @gapi.quota
123
- end
124
-
125
- ##
126
- # @private Default project.
127
- def self.default_project
128
- ENV["DNS_PROJECT"] ||
129
- ENV["GCLOUD_PROJECT"] ||
130
- ENV["GOOGLE_CLOUD_PROJECT"] ||
131
- Gcloud::GCE.project_id
132
- end
133
-
134
- ##
135
- # Retrieves an existing zone by name or id.
136
- #
137
- # @param [String, Integer] zone_id The name or id of a zone.
138
- #
139
- # @return [Gcloud::Dns::Zone, nil] Returns `nil` if the zone does not
140
- # exist.
141
- #
142
- # @example
143
- # require "gcloud"
144
- #
145
- # gcloud = Gcloud.new
146
- # dns = gcloud.dns
147
- # zone = dns.zone "example-com"
148
- # puts zone.name
149
- #
150
- def zone zone_id
151
- ensure_service!
152
- gapi = service.get_zone zone_id
153
- Zone.from_gapi gapi, service
154
- rescue Gcloud::NotFoundError
155
- nil
156
- end
157
- alias_method :find_zone, :zone
158
- alias_method :get_zone, :zone
159
-
160
- ##
161
- # Retrieves the list of zones belonging to the project.
162
- #
163
- # @param [String] token A previously-returned page token representing part
164
- # of the larger set of results to view.
165
- # @param [Integer] max Maximum number of zones to return.
166
- #
167
- # @return [Array<Gcloud::Dns::Zone>] (See {Gcloud::Dns::Zone::List})
168
- #
169
- # @example
170
- # require "gcloud"
171
- #
172
- # gcloud = Gcloud.new
173
- # dns = gcloud.dns
174
- # zones = dns.zones
175
- # zones.each do |zone|
176
- # puts zone.name
177
- # end
178
- #
179
- # @example Retrieve all zones: (See {Zone::List#all})
180
- # require "gcloud"
181
- #
182
- # gcloud = Gcloud.new
183
- # dns = gcloud.dns
184
- # zones = dns.zones
185
- # zones.all do |zone|
186
- # puts zone.name
187
- # end
188
- #
189
- def zones token: nil, max: nil
190
- ensure_service!
191
- gapi = service.list_zones token: token, max: max
192
- Zone::List.from_gapi gapi, service, max
193
- end
194
- alias_method :find_zones, :zones
195
-
196
- ##
197
- # Creates a new zone.
198
- #
199
- # @param [String] zone_name User assigned name for this resource. Must be
200
- # unique within the project. The name must be 1-32 characters long, must
201
- # begin with a letter, end with a letter or digit, and only contain
202
- # lowercase letters, digits or dashes.
203
- # @param [String] zone_dns The DNS name of this managed zone, for instance
204
- # "example.com.".
205
- # @param [String] description A string of at most 1024 characters
206
- # associated with this resource for the user's convenience. Has no
207
- # effect on the managed zone's function.
208
- # @param [String] name_server_set A NameServerSet is a set of DNS name
209
- # servers that all host the same ManagedZones. Most users will leave
210
- # this field unset.
211
- #
212
- # @return [Gcloud::Dns::Zone]
213
- #
214
- # @example
215
- # require "gcloud"
216
- #
217
- # gcloud = Gcloud.new
218
- # dns = gcloud.dns
219
- # zone = dns.create_zone "example-com", "example.com."
220
- #
221
- def create_zone zone_name, zone_dns, description: nil,
222
- name_server_set: nil
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
228
- end
229
-
230
- ##
231
- # Reloads the change with updated status from the DNS service.
232
- def reload!
233
- ensure_service!
234
- @gapi = service.get_project
235
- end
236
- alias_method :refresh!, :reload!
237
-
238
- protected
239
-
240
- ##
241
- # Raise an error unless an active connection is available.
242
- def ensure_service!
243
- fail "Must have active connection" unless service
244
- end
245
- end
246
- end
247
- end
@@ -1,170 +0,0 @@
1
- # Copyright 2015 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/dns/record/list"
17
-
18
- module Gcloud
19
- module Dns
20
- ##
21
- # # DNS Record
22
- #
23
- # Represents a set of DNS resource records (RRs) for a given
24
- # {Gcloud::Dns::Record#name} and {Gcloud::Dns::Record#type} in a
25
- # {Gcloud::Dns::Zone}. Since it is a value object, a newly created Record
26
- # instance is transient until it is added to a Zone with
27
- # {Gcloud::Dns::Zone#update}. Note that {Gcloud::Dns::Zone#add} and the
28
- # {Gcloud::Dns::Zone#update} block parameter can be used instead of
29
- # {Gcloud::Dns::Zone#record} or `Record.new` to create new records.
30
- #
31
- # @example
32
- # require "gcloud"
33
- #
34
- # gcloud = Gcloud.new
35
- # dns = gcloud.dns
36
- # zone = dns.zone "example-com"
37
- #
38
- # zone.records.count #=> 2
39
- # record = zone.record "example.com.", "A", 86400, "1.2.3.4"
40
- # zone.records.count #=> 2
41
- # change = zone.update record
42
- # zone.records.count #=> 3
43
- #
44
- class Record
45
- ##
46
- # The owner of the record. For example: `example.com.`.
47
- #
48
- # @return [String]
49
- #
50
- attr_accessor :name
51
-
52
- ##
53
- # The identifier of a [supported record type
54
- # ](https://cloud.google.com/dns/what-is-cloud-dns#supported_record_types)
55
- # . For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
56
- #
57
- # @return [String]
58
- #
59
- attr_accessor :type
60
-
61
- ##
62
- # The number of seconds that the record can be cached by resolvers.
63
- #
64
- # @return [Integer]
65
- #
66
- attr_accessor :ttl
67
-
68
- ##
69
- # The array of resource record data, as determined by `type` and defined
70
- # in [RFC 1035 (section 5)](http://tools.ietf.org/html/rfc1035#section-5)
71
- # and [RFC
72
- # 1034 (section 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1).
73
- # For example: ["10 mail.example.com.", "20 mail2.example.com."].
74
- #
75
- # @return [Array<String>]
76
- #
77
- attr_accessor :data
78
-
79
- ##
80
- # Creates a Record value object.
81
- #
82
- # @param [String] name The owner of the record. For example:
83
- # `example.com.`.
84
- # @param [String] type The identifier of a [supported record
85
- # type](https://cloud.google.com/dns/what-is-cloud-dns).
86
- # For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
87
- # @param [Integer] ttl The number of seconds that the record can be cached
88
- # by resolvers.
89
- # @param [String, Array<String>] data The resource record data, as
90
- # determined by `type` and defined in [RFC
91
- # 1035 (section 5)](http://tools.ietf.org/html/rfc1035#section-5) and
92
- # [RFC 1034
93
- # (section 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1).
94
- # For example: ["10 mail.example.com.", "20 mail2.example.com."].
95
- #
96
- def initialize name, type, ttl, data
97
- fail ArgumentError, "name is required" unless name
98
- fail ArgumentError, "type is required" unless type
99
- fail ArgumentError, "ttl is required" unless ttl
100
- fail ArgumentError, "data is required" unless data
101
- @name = name.to_s
102
- @type = type.to_s.upcase
103
- @ttl = Integer(ttl)
104
- @data = Array(data)
105
- end
106
-
107
- ##
108
- # @private Returns an array of strings in the zone file format, one
109
- # for each element in the record's data array.
110
- def to_zonefile_records
111
- data.map do |rrdata|
112
- "#{name} #{ttl} IN #{type} #{rrdata}"
113
- end
114
- end
115
-
116
- ##
117
- # Returns a deep copy of the record. Useful for updating records, since
118
- # the original, unmodified record must be passed for deletion when using
119
- # {Gcloud::Dns::Zone#update}.
120
- #
121
- def dup
122
- other = super
123
- other.data = data.map(&:dup)
124
- other
125
- end
126
-
127
- ##
128
- # @private New Record from a Google API Client object.
129
- def self.from_gapi gapi
130
- new gapi.name, gapi.type, gapi.ttl, gapi.rrdatas
131
- end
132
-
133
- ##
134
- # @private Convert the record object to a Google API hash.
135
- def to_gapi
136
- Google::Apis::DnsV1::ResourceRecordSet.new(
137
- kind: "dns#resourceRecordSet",
138
- name: name,
139
- rrdatas: data,
140
- ttl: ttl,
141
- type: type
142
- )
143
- end
144
-
145
- # @private
146
- def hash
147
- [name, type, ttl, data].hash
148
- end
149
-
150
- # @private
151
- def eql? other
152
- return false unless other.is_a? self.class
153
- name == other.name && type == other.type &&
154
- ttl == other.ttl && data == other.data
155
- end
156
-
157
- # @private
158
- def == other
159
- self.eql? other
160
- end
161
-
162
- # @private
163
- def <=> other
164
- return nil unless other.is_a? self.class
165
- [name, type, ttl, data] <=>
166
- [other.name, other.type, other.ttl, other.data]
167
- end
168
- end
169
- end
170
- end
@@ -1,174 +0,0 @@
1
- # Copyright 2015 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 "delegate"
17
-
18
- module Gcloud
19
- module Dns
20
- class Record
21
- ##
22
- # Record::List is a special case Array with additional values.
23
- class List < DelegateClass(::Array)
24
- ##
25
- # If not empty, indicates that there are more records that match
26
- # the request and this value should be passed to continue.
27
- attr_accessor :token
28
-
29
- ##
30
- # @private Create a new Record::List with an array of Record instances.
31
- def initialize arr = []
32
- super arr
33
- end
34
-
35
- ##
36
- # Whether there a next page of records.
37
- #
38
- # @return [Boolean]
39
- #
40
- # @example
41
- # require "gcloud"
42
- #
43
- # gcloud = Gcloud.new
44
- # dns = gcloud.dns
45
- # zone = dns.zone "example-com"
46
- #
47
- # records = zone.records "example.com."
48
- # if records.next?
49
- # next_records = records.next
50
- # end
51
- #
52
- def next?
53
- !token.nil?
54
- end
55
-
56
- ##
57
- # Retrieve the next page of records.
58
- #
59
- # @return [Record::List]
60
- #
61
- # @example
62
- # require "gcloud"
63
- #
64
- # gcloud = Gcloud.new
65
- # dns = gcloud.dns
66
- # zone = dns.zone "example-com"
67
- #
68
- # records = zone.records "example.com."
69
- # if records.next?
70
- # next_records = records.next
71
- # end
72
- #
73
- def next
74
- return nil unless next?
75
- ensure_zone!
76
- @zone.records @name, @type, token: token, max: @max
77
- end
78
-
79
- ##
80
- # Retrieves all records by repeatedly loading {#next} until {#next?}
81
- # returns `false`. Calls the given block once for each record, which is
82
- # passed as the parameter.
83
- #
84
- # An Enumerator is returned if no block is given.
85
- #
86
- # This method may make several API calls until all records are
87
- # retrieved. Be sure to use as narrow a search criteria as possible.
88
- # Please use with caution.
89
- #
90
- # @param [Integer] request_limit The upper limit of API requests to make
91
- # to load all records. Default is no limit.
92
- # @yield [record] The block for accessing each record.
93
- # @yieldparam [Record] record The record object.
94
- #
95
- # @return [Enumerator]
96
- #
97
- # @example Iterating each record by passing a block:
98
- # require "gcloud"
99
- #
100
- # gcloud = Gcloud.new
101
- # dns = gcloud.dns
102
- # zone = dns.zone "example-com"
103
- # records = zone.records "example.com."
104
- #
105
- # records.all do |record|
106
- # puts record.name
107
- # end
108
- #
109
- # @example Using the enumerator by not passing a block:
110
- # require "gcloud"
111
- #
112
- # gcloud = Gcloud.new
113
- # dns = gcloud.dns
114
- # zone = dns.zone "example-com"
115
- # records = zone.records "example.com."
116
- #
117
- # all_names = records.all.map do |record|
118
- # record.name
119
- # end
120
- #
121
- # @example Limit the number of API calls made:
122
- # require "gcloud"
123
- #
124
- # gcloud = Gcloud.new
125
- # dns = gcloud.dns
126
- # zone = dns.zone "example-com"
127
- # records = zone.records "example.com."
128
- #
129
- # records.all(request_limit: 10) do |record|
130
- # puts record.name
131
- # end
132
- #
133
- def all request_limit: nil
134
- request_limit = request_limit.to_i if request_limit
135
- unless block_given?
136
- return enum_for(:all, request_limit: request_limit)
137
- end
138
- results = self
139
- loop do
140
- results.each { |r| yield r }
141
- if request_limit
142
- request_limit -= 1
143
- break if request_limit < 0
144
- end
145
- break unless results.next?
146
- results = results.next
147
- end
148
- end
149
-
150
- ##
151
- # @private New Records::List from a response 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
- end)
156
- records.instance_variable_set "@token", gapi.next_page_token
157
- records.instance_variable_set "@zone", zone
158
- records.instance_variable_set "@name", name
159
- records.instance_variable_set "@type", type
160
- records.instance_variable_set "@max", max
161
- records
162
- end
163
-
164
- protected
165
-
166
- ##
167
- # Raise an error unless an active connection is available.
168
- def ensure_zone!
169
- fail "Must have active connection" unless @zone
170
- end
171
- end
172
- end
173
- end
174
- end