gcloud 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.md +26 -0
  3. data/OVERVIEW.md +10 -8
  4. data/lib/gcloud.rb +12 -13
  5. data/lib/gcloud/bigquery/dataset/list.rb +2 -4
  6. data/lib/gcloud/bigquery/job/list.rb +3 -5
  7. data/lib/gcloud/bigquery/table/list.rb +3 -5
  8. data/lib/gcloud/datastore.rb +326 -97
  9. data/lib/gcloud/datastore/commit.rb +73 -56
  10. data/lib/gcloud/datastore/credentials.rb +1 -12
  11. data/lib/gcloud/datastore/cursor.rb +76 -0
  12. data/lib/gcloud/datastore/dataset.rb +337 -134
  13. data/lib/gcloud/datastore/dataset/lookup_results.rb +12 -12
  14. data/lib/gcloud/datastore/dataset/query_results.rb +117 -27
  15. data/lib/gcloud/datastore/entity.rb +159 -93
  16. data/lib/gcloud/datastore/errors.rb +0 -21
  17. data/lib/gcloud/datastore/gql_query.rb +211 -0
  18. data/lib/gcloud/datastore/grpc_utils.rb +131 -0
  19. data/lib/gcloud/datastore/key.rb +74 -65
  20. data/lib/gcloud/datastore/properties.rb +14 -1
  21. data/lib/gcloud/datastore/query.rb +188 -52
  22. data/lib/gcloud/datastore/service.rb +161 -0
  23. data/lib/gcloud/datastore/transaction.rb +175 -60
  24. data/lib/gcloud/dns/change/list.rb +2 -4
  25. data/lib/gcloud/dns/record/list.rb +2 -4
  26. data/lib/gcloud/dns/zone/list.rb +2 -4
  27. data/lib/gcloud/grpc_utils.rb +11 -0
  28. data/lib/gcloud/logging/entry.rb +6 -17
  29. data/lib/gcloud/logging/entry/list.rb +8 -9
  30. data/lib/gcloud/logging/metric/list.rb +4 -5
  31. data/lib/gcloud/logging/resource.rb +1 -12
  32. data/lib/gcloud/logging/resource_descriptor.rb +9 -12
  33. data/lib/gcloud/logging/resource_descriptor/list.rb +4 -5
  34. data/lib/gcloud/logging/sink/list.rb +4 -5
  35. data/lib/gcloud/pubsub/message.rb +1 -3
  36. data/lib/gcloud/pubsub/subscription.rb +5 -7
  37. data/lib/gcloud/pubsub/topic.rb +1 -3
  38. data/lib/gcloud/resource_manager/project/list.rb +2 -4
  39. data/lib/gcloud/translate/api.rb +5 -3
  40. data/lib/gcloud/translate/connection.rb +4 -4
  41. data/lib/gcloud/version.rb +1 -1
  42. metadata +9 -20
  43. data/lib/gcloud/datastore/connection.rb +0 -203
  44. data/lib/gcloud/datastore/proto.rb +0 -266
  45. data/lib/gcloud/proto/datastore_v1.pb.rb +0 -377
  46. data/lib/google/protobuf/any.rb +0 -17
  47. data/lib/google/protobuf/api.rb +0 -31
  48. data/lib/google/protobuf/duration.rb +0 -17
  49. data/lib/google/protobuf/empty.rb +0 -15
  50. data/lib/google/protobuf/field_mask.rb +0 -16
  51. data/lib/google/protobuf/source_context.rb +0 -16
  52. data/lib/google/protobuf/struct.rb +0 -35
  53. data/lib/google/protobuf/timestamp.rb +0 -17
  54. data/lib/google/protobuf/type.rb +0 -79
  55. data/lib/google/protobuf/wrappers.rb +0 -48
@@ -1,266 +0,0 @@
1
- # Copyright 2014 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/proto/datastore_v1.pb"
17
- require "gcloud/datastore/errors"
18
- require "stringio"
19
-
20
- module Gcloud
21
- module Datastore
22
- # rubocop:disable all
23
-
24
- ##
25
- # @private
26
- #
27
- # Proto is the namespace that contains all Protocol Buffer objects.
28
- #
29
- # The methods in this module are for convenience in using the
30
- # Protocol Buffer objects and as such can change in the future.
31
- # Neither the convenience methods nor the Protocol Buffer objects
32
- # are not part of the gcloud public API. These methods, and even
33
- # this module's existance, may change in the future.
34
- #
35
- # You have been warned.
36
- module Proto
37
- def self.from_proto_value proto_value
38
- if !proto_value.timestamp_microseconds_value.nil?
39
- microseconds = proto_value.timestamp_microseconds_value
40
- self.time_from_microseconds microseconds
41
- elsif !proto_value.key_value.nil?
42
- Gcloud::Datastore::Key.from_proto(proto_value.key_value)
43
- elsif !proto_value.entity_value.nil?
44
- Gcloud::Datastore::Entity.from_proto(proto_value.entity_value)
45
- elsif !proto_value.boolean_value.nil?
46
- proto_value.boolean_value
47
- elsif !proto_value.double_value.nil?
48
- proto_value.double_value
49
- elsif !proto_value.integer_value.nil?
50
- proto_value.integer_value
51
- elsif !proto_value.string_value.nil?
52
- return proto_value.string_value
53
- elsif !proto_value.list_value.nil?
54
- return Array(proto_value.list_value).map do |item|
55
- from_proto_value item
56
- end
57
- elsif !proto_value.blob_value.nil?
58
- return StringIO.new(proto_value.blob_value.force_encoding("ASCII-8BIT"))
59
- else
60
- nil
61
- end
62
- end
63
-
64
- def self.to_proto_value value
65
- v = Gcloud::Datastore::Proto::Value.new
66
- if Gcloud::Datastore::Key === value
67
- v.key_value = value.to_proto
68
- elsif Gcloud::Datastore::Entity === value
69
- v.entity_value = value.to_proto
70
- elsif NilClass === value
71
- # The correct behavior is to not set a value property
72
- elsif TrueClass === value
73
- v.boolean_value = true
74
- elsif FalseClass === value
75
- v.boolean_value = false
76
- elsif Float === value
77
- v.double_value = value
78
- elsif defined?(BigDecimal) && BigDecimal === value
79
- v.double_value = value
80
- elsif Integer === value
81
- v.integer_value = value
82
- elsif String === value
83
- v.string_value = value
84
- elsif Array === value
85
- v.list_value = value.map { |item| to_proto_value item }
86
- elsif value.respond_to?(:to_time)
87
- v.timestamp_microseconds_value = self.microseconds_from_time value.to_time
88
- elsif value.respond_to?(:read) && value.respond_to?(:rewind)
89
- value.rewind
90
- v.blob_value = value.read.force_encoding("ASCII-8BIT")
91
- else
92
- fail PropertyError, "A property of type #{value.class} is not supported."
93
- end
94
- v
95
- end
96
-
97
- def self.from_proto_properties proto_properties
98
- hash_properties = {}
99
- Array(proto_properties).each do |p|
100
- hash_properties[p.name] = Proto.from_proto_value p.value
101
- end
102
- hash_properties
103
- end
104
-
105
- def self.to_proto_properties hash_properties
106
- hash_properties.map do |name, value|
107
- Proto::Property.new.tap do |p|
108
- p.name = name.to_s
109
- p.value = Proto.to_proto_value value
110
- end
111
- end
112
- end
113
-
114
- def self.microseconds_from_time time
115
- (time.utc.to_f * 1000000).to_i
116
- end
117
-
118
- def self.time_from_microseconds microseconds
119
- Time.at(microseconds / 1000000, microseconds % 1000000).utc
120
- end
121
-
122
- @private
123
- PROP_FILTER_OPS = {
124
- "<" => PropertyFilter::Operator::LESS_THAN,
125
- "lt" => PropertyFilter::Operator::LESS_THAN,
126
- "<=" => PropertyFilter::Operator::LESS_THAN_OR_EQUAL,
127
- "lte" => PropertyFilter::Operator::LESS_THAN_OR_EQUAL,
128
- ">" => PropertyFilter::Operator::GREATER_THAN,
129
- "gt" => PropertyFilter::Operator::GREATER_THAN,
130
- ">=" => PropertyFilter::Operator::GREATER_THAN_OR_EQUAL,
131
- "gte" => PropertyFilter::Operator::GREATER_THAN_OR_EQUAL,
132
- "=" => PropertyFilter::Operator::EQUAL,
133
- "eq" => PropertyFilter::Operator::EQUAL,
134
- "eql" => PropertyFilter::Operator::EQUAL,
135
- "~" => PropertyFilter::Operator::HAS_ANCESTOR,
136
- "~>" => PropertyFilter::Operator::HAS_ANCESTOR,
137
- "ancestor" => PropertyFilter::Operator::HAS_ANCESTOR,
138
- "has_ancestor" => PropertyFilter::Operator::HAS_ANCESTOR,
139
- "has ancestor" => PropertyFilter::Operator::HAS_ANCESTOR }
140
-
141
- def self.to_prop_filter_op str
142
- PROP_FILTER_OPS[str.to_s.downcase] ||
143
- PropertyFilter::Operator::EQUAL
144
- end
145
-
146
- def self.to_prop_order_direction direction
147
- if direction.to_s.downcase.start_with? "d"
148
- PropertyOrder::Direction::DESCENDING
149
- else
150
- PropertyOrder::Direction::ASCENDING
151
- end
152
- end
153
-
154
- def self.encode_cursor cursor
155
- Array(cursor.to_s).pack("m").chomp
156
- end
157
-
158
- def self.decode_cursor cursor
159
- dc = cursor.to_s.unpack("m").first.force_encoding Encoding::ASCII_8BIT
160
- dc = nil if dc.empty?
161
- dc
162
- end
163
-
164
- def self.to_more_results_string more_results
165
- if QueryResultBatch::MoreResultsType::NOT_FINISHED == more_results
166
- "NOT_FINISHED"
167
- elsif QueryResultBatch::MoreResultsType::MORE_RESULTS_AFTER_LIMIT == more_results
168
- "MORE_RESULTS_AFTER_LIMIT"
169
- elsif QueryResultBatch::MoreResultsType::NO_MORE_RESULTS == more_results
170
- "NO_MORE_RESULTS"
171
- else
172
- nil
173
- end
174
- end
175
-
176
- ##
177
- # Convenience methods to create protocol buffer objects
178
-
179
- def self.new_filter
180
- Filter.new
181
- end
182
-
183
- def self.new_composite_filter
184
- CompositeFilter.new.tap do |cf|
185
- cf.operator = Proto::CompositeFilter::Operator::AND
186
- cf.filter = []
187
- end
188
- end
189
-
190
- def self.new_mutation
191
- Mutation.new.tap do |m|
192
- m.upsert = []
193
- m.update = []
194
- m.insert = []
195
- m.insert_auto_id = []
196
- m.delete = []
197
- end
198
- end
199
-
200
- def self.new_property_filter name, operator, value
201
- PropertyFilter.new.tap do |pf|
202
- pf.property = new_property_reference name
203
- pf.operator = Proto.to_prop_filter_op operator
204
- pf.value = Proto.to_proto_value value
205
- end
206
- end
207
-
208
- def self.new_property_expressions *names
209
- names.map do |name|
210
- new_property_expression name
211
- end
212
- end
213
-
214
- def self.new_property_expression name
215
- PropertyExpression.new.tap do |pe|
216
- pe.property = new_property_reference name
217
- end
218
- end
219
-
220
- def self.new_property_references *names
221
- names.map do |name|
222
- new_property_reference name
223
- end
224
- end
225
-
226
- def self.new_property_reference name
227
- PropertyReference.new.tap do |pr|
228
- pr.name = name
229
- end
230
- end
231
-
232
- def self.new_path_element new_kind, new_id_or_name
233
- Key::PathElement.new.tap do |pe|
234
- pe.kind = new_kind
235
- if new_id_or_name.is_a? Integer
236
- pe.id = new_id_or_name
237
- else
238
- pe.name = new_id_or_name
239
- end
240
- end
241
- end
242
-
243
- def self.new_partition_id new_dataset_id, new_namespace
244
- PartitionId.new.tap do |pi|
245
- pi.dataset_id = new_dataset_id
246
- pi.namespace = new_namespace
247
- end
248
- end
249
-
250
- def self.new_run_query_request query_proto
251
- RunQueryRequest.new.tap do |rq|
252
- rq.query = query_proto
253
- end
254
- end
255
-
256
- # @private
257
- class Key
258
- def dup
259
- proto_request_body = ""
260
- self.encode proto_request_body
261
- Key.decode proto_request_body
262
- end
263
- end
264
- end
265
- end
266
- end
@@ -1,377 +0,0 @@
1
- ## Generated from datastore_v1.proto for api.services.datastore
2
- require "beefcake"
3
-
4
- module Gcloud
5
- module Datastore
6
- module Proto
7
-
8
- class PartitionId
9
- include Beefcake::Message
10
- end
11
-
12
- class Key
13
- include Beefcake::Message
14
-
15
- class PathElement
16
- include Beefcake::Message
17
- end
18
- end
19
-
20
- class Value
21
- include Beefcake::Message
22
- end
23
-
24
- class Property
25
- include Beefcake::Message
26
- end
27
-
28
- class Entity
29
- include Beefcake::Message
30
- end
31
-
32
- class EntityResult
33
- include Beefcake::Message
34
-
35
- module ResultType
36
- FULL = 1
37
- PROJECTION = 2
38
- KEY_ONLY = 3
39
- end
40
- end
41
-
42
- class Query
43
- include Beefcake::Message
44
- end
45
-
46
- class KindExpression
47
- include Beefcake::Message
48
- end
49
-
50
- class PropertyReference
51
- include Beefcake::Message
52
- end
53
-
54
- class PropertyExpression
55
- include Beefcake::Message
56
-
57
- module AggregationFunction
58
- FIRST = 1
59
- end
60
- end
61
-
62
- class PropertyOrder
63
- include Beefcake::Message
64
-
65
- module Direction
66
- ASCENDING = 1
67
- DESCENDING = 2
68
- end
69
- end
70
-
71
- class Filter
72
- include Beefcake::Message
73
- end
74
-
75
- class CompositeFilter
76
- include Beefcake::Message
77
-
78
- module Operator
79
- AND = 1
80
- end
81
- end
82
-
83
- class PropertyFilter
84
- include Beefcake::Message
85
-
86
- module Operator
87
- LESS_THAN = 1
88
- LESS_THAN_OR_EQUAL = 2
89
- GREATER_THAN = 3
90
- GREATER_THAN_OR_EQUAL = 4
91
- EQUAL = 5
92
- HAS_ANCESTOR = 11
93
- end
94
- end
95
-
96
- class GqlQuery
97
- include Beefcake::Message
98
- end
99
-
100
- class GqlQueryArg
101
- include Beefcake::Message
102
- end
103
-
104
- class QueryResultBatch
105
- include Beefcake::Message
106
-
107
- module MoreResultsType
108
- NOT_FINISHED = 1
109
- MORE_RESULTS_AFTER_LIMIT = 2
110
- NO_MORE_RESULTS = 3
111
- end
112
- end
113
-
114
- class Mutation
115
- include Beefcake::Message
116
- end
117
-
118
- class MutationResult
119
- include Beefcake::Message
120
- end
121
-
122
- class ReadOptions
123
- include Beefcake::Message
124
-
125
- module ReadConsistency
126
- DEFAULT = 0
127
- STRONG = 1
128
- EVENTUAL = 2
129
- end
130
- end
131
-
132
- class LookupRequest
133
- include Beefcake::Message
134
- end
135
-
136
- class LookupResponse
137
- include Beefcake::Message
138
- end
139
-
140
- class RunQueryRequest
141
- include Beefcake::Message
142
- end
143
-
144
- class RunQueryResponse
145
- include Beefcake::Message
146
- end
147
-
148
- class BeginTransactionRequest
149
- include Beefcake::Message
150
-
151
- module IsolationLevel
152
- SNAPSHOT = 0
153
- SERIALIZABLE = 1
154
- end
155
- end
156
-
157
- class BeginTransactionResponse
158
- include Beefcake::Message
159
- end
160
-
161
- class RollbackRequest
162
- include Beefcake::Message
163
- end
164
-
165
- class RollbackResponse
166
- include Beefcake::Message
167
- end
168
-
169
- class CommitRequest
170
- include Beefcake::Message
171
-
172
- module Mode
173
- TRANSACTIONAL = 1
174
- NON_TRANSACTIONAL = 2
175
- end
176
- end
177
-
178
- class CommitResponse
179
- include Beefcake::Message
180
- end
181
-
182
- class AllocateIdsRequest
183
- include Beefcake::Message
184
- end
185
-
186
- class AllocateIdsResponse
187
- include Beefcake::Message
188
- end
189
-
190
- class PartitionId
191
- optional :dataset_id, :string, 3
192
- optional :namespace, :string, 4
193
- end
194
-
195
- class Key
196
-
197
- class PathElement
198
- required :kind, :string, 1
199
- optional :id, :int64, 2
200
- optional :name, :string, 3
201
- end
202
- optional :partition_id, PartitionId, 1
203
- repeated :path_element, Key::PathElement, 2
204
- end
205
-
206
- class Value
207
- optional :boolean_value, :bool, 1
208
- optional :integer_value, :int64, 2
209
- optional :double_value, :double, 3
210
- optional :timestamp_microseconds_value, :int64, 4
211
- optional :key_value, Key, 5
212
- optional :blob_key_value, :string, 16
213
- optional :string_value, :string, 17
214
- optional :blob_value, :bytes, 18
215
- optional :entity_value, Entity, 6
216
- repeated :list_value, Value, 7
217
- optional :meaning, :int32, 14
218
- optional :indexed, :bool, 15, :default => true
219
- end
220
-
221
- class Property
222
- required :name, :string, 1
223
- required :value, Value, 4
224
- end
225
-
226
- class Entity
227
- optional :key, Key, 1
228
- repeated :property, Property, 2
229
- end
230
-
231
- class EntityResult
232
- required :entity, Entity, 1
233
- end
234
-
235
- class Query
236
- repeated :projection, PropertyExpression, 2
237
- repeated :kind, KindExpression, 3
238
- optional :filter, Filter, 4
239
- repeated :order, PropertyOrder, 5
240
- repeated :group_by, PropertyReference, 6
241
- optional :start_cursor, :bytes, 7
242
- optional :end_cursor, :bytes, 8
243
- optional :offset, :int32, 10, :default => 0
244
- optional :limit, :int32, 11
245
- end
246
-
247
- class KindExpression
248
- required :name, :string, 1
249
- end
250
-
251
- class PropertyReference
252
- required :name, :string, 2
253
- end
254
-
255
- class PropertyExpression
256
- required :property, PropertyReference, 1
257
- optional :aggregation_function, PropertyExpression::AggregationFunction, 2
258
- end
259
-
260
- class PropertyOrder
261
- required :property, PropertyReference, 1
262
- optional :direction, PropertyOrder::Direction, 2, :default => PropertyOrder::Direction::ASCENDING
263
- end
264
-
265
- class Filter
266
- optional :composite_filter, CompositeFilter, 1
267
- optional :property_filter, PropertyFilter, 2
268
- end
269
-
270
- class CompositeFilter
271
- required :operator, CompositeFilter::Operator, 1
272
- repeated :filter, Filter, 2
273
- end
274
-
275
- class PropertyFilter
276
- required :property, PropertyReference, 1
277
- required :operator, PropertyFilter::Operator, 2
278
- required :value, Value, 3
279
- end
280
-
281
- class GqlQuery
282
- required :query_string, :string, 1
283
- optional :allow_literal, :bool, 2, :default => false
284
- repeated :name_arg, GqlQueryArg, 3
285
- repeated :number_arg, GqlQueryArg, 4
286
- end
287
-
288
- class GqlQueryArg
289
- optional :name, :string, 1
290
- optional :value, Value, 2
291
- optional :cursor, :bytes, 3
292
- end
293
-
294
- class QueryResultBatch
295
- required :entity_result_type, EntityResult::ResultType, 1
296
- repeated :entity_result, EntityResult, 2
297
- optional :end_cursor, :bytes, 4
298
- required :more_results, QueryResultBatch::MoreResultsType, 5
299
- optional :skipped_results, :int32, 6
300
- end
301
-
302
- class Mutation
303
- repeated :upsert, Entity, 1
304
- repeated :update, Entity, 2
305
- repeated :insert, Entity, 3
306
- repeated :insert_auto_id, Entity, 4
307
- repeated :delete, Key, 5
308
- optional :force, :bool, 6
309
- end
310
-
311
- class MutationResult
312
- required :index_updates, :int32, 1
313
- repeated :insert_auto_id_key, Key, 2
314
- end
315
-
316
- class ReadOptions
317
- optional :read_consistency, ReadOptions::ReadConsistency, 1, :default => ReadOptions::ReadConsistency::DEFAULT
318
- optional :transaction, :bytes, 2
319
- end
320
-
321
- class LookupRequest
322
- optional :read_options, ReadOptions, 1
323
- repeated :key, Key, 3
324
- end
325
-
326
- class LookupResponse
327
- repeated :found, EntityResult, 1
328
- repeated :missing, EntityResult, 2
329
- repeated :deferred, Key, 3
330
- end
331
-
332
- class RunQueryRequest
333
- optional :read_options, ReadOptions, 1
334
- optional :partition_id, PartitionId, 2
335
- optional :query, Query, 3
336
- optional :gql_query, GqlQuery, 7
337
- end
338
-
339
- class RunQueryResponse
340
- optional :batch, QueryResultBatch, 1
341
- end
342
-
343
- class BeginTransactionRequest
344
- optional :isolation_level, BeginTransactionRequest::IsolationLevel, 1, :default => BeginTransactionRequest::IsolationLevel::SNAPSHOT
345
- end
346
-
347
- class BeginTransactionResponse
348
- optional :transaction, :bytes, 1
349
- end
350
-
351
- class RollbackRequest
352
- required :transaction, :bytes, 1
353
- end
354
-
355
- class RollbackResponse
356
- end
357
-
358
- class CommitRequest
359
- optional :transaction, :bytes, 1
360
- optional :mutation, Mutation, 2
361
- optional :mode, CommitRequest::Mode, 5, :default => CommitRequest::Mode::TRANSACTIONAL
362
- end
363
-
364
- class CommitResponse
365
- optional :mutation_result, MutationResult, 1
366
- end
367
-
368
- class AllocateIdsRequest
369
- repeated :key, Key, 1
370
- end
371
-
372
- class AllocateIdsResponse
373
- repeated :key, Key, 1
374
- end
375
- end
376
- end
377
- end