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
@@ -76,11 +76,10 @@ module Gcloud
76
76
  metrics = new(Array(grpc_list.metrics).map do |grpc_metric|
77
77
  Metric.from_grpc grpc_metric, service
78
78
  end)
79
- metrics.instance_eval do
80
- @token = grpc_list.next_page_token
81
- @token = nil if @token == ""
82
- @service = service
83
- end
79
+ token = grpc_list.next_page_token
80
+ token = nil if token == ""
81
+ metrics.instance_variable_set "@token", token
82
+ metrics.instance_variable_set "@service", service
84
83
  metrics
85
84
  end
86
85
 
@@ -76,18 +76,7 @@ module Gcloud
76
76
  return new if grpc.nil?
77
77
  new.tap do |r|
78
78
  r.type = grpc.type
79
- r.labels = map_to_hash(grpc.labels)
80
- end
81
- end
82
-
83
- ##
84
- # @private Convert a Google::Protobuf::Map to a Hash
85
- def self.map_to_hash map
86
- if map.respond_to? :to_h
87
- map.to_h
88
- else
89
- # Enumerable doesn't have to_h on ruby 2.0...
90
- Hash[map.to_a]
79
+ r.labels = GRPCUtils.map_to_hash(grpc.labels)
91
80
  end
92
81
  end
93
82
  end
@@ -74,14 +74,13 @@ module Gcloud
74
74
  # Google::Api::MonitoredResourceDescriptor object.
75
75
  def self.from_grpc grpc
76
76
  r = new
77
- r.instance_eval do
78
- @type = grpc.type
79
- @name = grpc.display_name
80
- @description = grpc.description
81
- @labels = Array(grpc.labels).map do |g|
82
- LabelDescriptor.from_grpc g
83
- end
77
+ r.instance_variable_set "@type", grpc.type
78
+ r.instance_variable_set "@name", grpc.display_name
79
+ r.instance_variable_set "@description", grpc.description
80
+ labels = Array(grpc.labels).map do |g|
81
+ LabelDescriptor.from_grpc g
84
82
  end
83
+ r.instance_variable_set "@labels", labels
85
84
  r
86
85
  end
87
86
 
@@ -127,11 +126,9 @@ module Gcloud
127
126
  BOOL: :boolean,
128
127
  INT64: :integer }[grpc.value_type]
129
128
  l = new
130
- l.instance_eval do
131
- @key = grpc.key
132
- @type = type_sym
133
- @description = grpc.description
134
- end
129
+ l.instance_variable_set "@key", grpc.key
130
+ l.instance_variable_set "@type", type_sym
131
+ l.instance_variable_set "@description", grpc.description
135
132
  l
136
133
  end
137
134
  end
@@ -57,11 +57,10 @@ module Gcloud
57
57
  sinks = new(Array(grpc_list.resource_descriptors).map do |grpc|
58
58
  ResourceDescriptor.from_grpc grpc
59
59
  end)
60
- sinks.instance_eval do
61
- @token = grpc_list.next_page_token
62
- @token = nil if @token == ""
63
- @service = service
64
- end
60
+ token = grpc_list.next_page_token
61
+ token = nil if token == ""
62
+ sinks.instance_variable_set "@token", token
63
+ sinks.instance_variable_set "@service", service
65
64
  sinks
66
65
  end
67
66
 
@@ -76,11 +76,10 @@ module Gcloud
76
76
  sinks = new(Array(grpc_list.sinks).map do |grpc|
77
77
  Sink.from_grpc grpc, service
78
78
  end)
79
- sinks.instance_eval do
80
- @token = grpc_list.next_page_token
81
- @token = nil if @token == ""
82
- @service = service
83
- end
79
+ token = grpc_list.next_page_token
80
+ token = nil if token == ""
81
+ sinks.instance_variable_set "@token", token
82
+ sinks.instance_variable_set "@service", service
84
83
  sinks
85
84
  end
86
85
 
@@ -86,9 +86,7 @@ module Gcloud
86
86
  # @private New Message from a Google::Pubsub::V1::PubsubMessage object.
87
87
  def self.from_grpc grpc
88
88
  new.tap do |m|
89
- m.instance_eval do
90
- @grpc = grpc
91
- end
89
+ m.instance_variable_set "@grpc", grpc
92
90
  end
93
91
  end
94
92
  end
@@ -56,14 +56,12 @@ module Gcloud
56
56
  ##
57
57
  # @private New lazy {Topic} object without making an HTTP request.
58
58
  def self.new_lazy name, service, options = {}
59
- sub = new.tap do |f|
60
- f.grpc = nil
61
- f.service = service
62
- end
63
- sub.instance_eval do
64
- @name = service.subscription_path(name, options)
59
+ new.tap do |s|
60
+ s.grpc = nil
61
+ s.service = service
62
+ s.instance_variable_set "@name",
63
+ service.subscription_path(name, options)
65
64
  end
66
- sub
67
65
  end
68
66
 
69
67
  ##
@@ -58,9 +58,7 @@ module Gcloud
58
58
  new.tap do |t|
59
59
  t.grpc = nil
60
60
  t.service = service
61
- t.instance_eval do
62
- @name = service.topic_path(name, options)
63
- end
61
+ t.instance_variable_set "@name", service.topic_path(name, options)
64
62
  end
65
63
  end
66
64
 
@@ -70,10 +70,8 @@ module Gcloud
70
70
  projects = new(Array(resp.data["projects"]).map do |gapi_object|
71
71
  Project.from_gapi gapi_object, manager.connection
72
72
  end)
73
- projects.instance_eval do
74
- @token = resp.data["nextPageToken"]
75
- @manager = manager
76
- end
73
+ projects.instance_variable_set "@token", resp.data["nextPageToken"]
74
+ projects.instance_variable_set "@manager", manager
77
75
  projects
78
76
  end
79
77
 
@@ -148,8 +148,9 @@ module Gcloud
148
148
  to = to.to_s
149
149
  from = from.to_s if from
150
150
  format = format.to_s if format
151
- resp = connection.translate(*text, to: to, from: from,
152
- format: format, cid: cid)
151
+ text = Array(text).flatten
152
+ resp = connection.translate(text, to: to, from: from,
153
+ format: format, cid: cid)
153
154
  fail ApiError.from_response(resp) unless resp.success?
154
155
  Translation.from_response resp, text, to, from
155
156
  end
@@ -194,7 +195,8 @@ module Gcloud
194
195
  #
195
196
  def detect *text
196
197
  return nil if text.empty?
197
- resp = connection.detect(*text)
198
+ text = Array(text).flatten
199
+ resp = connection.detect(text)
198
200
  fail ApiError.from_response(resp) unless resp.success?
199
201
  Detection.from_response resp, text
200
202
  end
@@ -36,8 +36,8 @@ module Gcloud
36
36
  @client.key = key # set key after discovery, helps with tests
37
37
  end
38
38
 
39
- def translate *text, to: nil, from: nil, format: nil, cid: nil
40
- params = { q: text,
39
+ def translate text, to: nil, from: nil, format: nil, cid: nil
40
+ params = { q: Array(text),
41
41
  target: to,
42
42
  source: from,
43
43
  format: format,
@@ -51,10 +51,10 @@ module Gcloud
51
51
  )
52
52
  end
53
53
 
54
- def detect *text
54
+ def detect text
55
55
  @client.execute(
56
56
  api_method: @translate.detections.list,
57
- parameters: { q: text, prettyprint: false }
57
+ parameters: { q: Array(text), prettyprint: false }
58
58
  )
59
59
  end
60
60
 
@@ -14,5 +14,5 @@
14
14
 
15
15
 
16
16
  module Gcloud
17
- VERSION = "0.8.2"
17
+ VERSION = "0.9.0"
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silvano Luciani
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-04 00:00:00.000000000 Z
13
+ date: 2016-05-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grpc
@@ -27,19 +27,19 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: 0.13.1
29
29
  - !ruby/object:Gem::Dependency
30
- name: beefcake
30
+ name: google-protobuf
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: '1.0'
35
+ version: 3.0.0.alpha.5.0.5
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ~>
41
41
  - !ruby/object:Gem::Version
42
- version: '1.0'
42
+ version: 3.0.0.alpha.5.0.5
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: google-api-client
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -291,17 +291,19 @@ files:
291
291
  - lib/gcloud/credentials.rb
292
292
  - lib/gcloud/datastore.rb
293
293
  - lib/gcloud/datastore/commit.rb
294
- - lib/gcloud/datastore/connection.rb
295
294
  - lib/gcloud/datastore/credentials.rb
295
+ - lib/gcloud/datastore/cursor.rb
296
296
  - lib/gcloud/datastore/dataset.rb
297
297
  - lib/gcloud/datastore/dataset/lookup_results.rb
298
298
  - lib/gcloud/datastore/dataset/query_results.rb
299
299
  - lib/gcloud/datastore/entity.rb
300
300
  - lib/gcloud/datastore/errors.rb
301
+ - lib/gcloud/datastore/gql_query.rb
302
+ - lib/gcloud/datastore/grpc_utils.rb
301
303
  - lib/gcloud/datastore/key.rb
302
304
  - lib/gcloud/datastore/properties.rb
303
- - lib/gcloud/datastore/proto.rb
304
305
  - lib/gcloud/datastore/query.rb
306
+ - lib/gcloud/datastore/service.rb
305
307
  - lib/gcloud/datastore/transaction.rb
306
308
  - lib/gcloud/dns.rb
307
309
  - lib/gcloud/dns/change.rb
@@ -335,7 +337,6 @@ files:
335
337
  - lib/gcloud/logging/service.rb
336
338
  - lib/gcloud/logging/sink.rb
337
339
  - lib/gcloud/logging/sink/list.rb
338
- - lib/gcloud/proto/datastore_v1.pb.rb
339
340
  - lib/gcloud/pubsub.rb
340
341
  - lib/gcloud/pubsub/credentials.rb
341
342
  - lib/gcloud/pubsub/message.rb
@@ -403,17 +404,7 @@ files:
403
404
  - lib/google/logging/v2/logging_services.rb
404
405
  - lib/google/longrunning/operations.rb
405
406
  - lib/google/longrunning/operations_services.rb
406
- - lib/google/protobuf/any.rb
407
- - lib/google/protobuf/api.rb
408
407
  - lib/google/protobuf/descriptor.rb
409
- - lib/google/protobuf/duration.rb
410
- - lib/google/protobuf/empty.rb
411
- - lib/google/protobuf/field_mask.rb
412
- - lib/google/protobuf/source_context.rb
413
- - lib/google/protobuf/struct.rb
414
- - lib/google/protobuf/timestamp.rb
415
- - lib/google/protobuf/type.rb
416
- - lib/google/protobuf/wrappers.rb
417
408
  - lib/google/pubsub/v1/pubsub.rb
418
409
  - lib/google/pubsub/v1/pubsub_services.rb
419
410
  - lib/google/pubsub/v1beta2/pubsub.rb
@@ -436,8 +427,6 @@ rdoc_options:
436
427
  - --main
437
428
  - OVERVIEW.md
438
429
  - --exclude
439
- - lib/gcloud/proto/
440
- - --exclude
441
430
  - lib/google/
442
431
  require_paths:
443
432
  - lib
@@ -1,203 +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 "faraday"
17
-
18
- module Gcloud
19
- module Datastore
20
- ##
21
- # @private
22
- #
23
- # Represent the HTTP connection to the Datastore,
24
- # as well as the Datastore API calls.
25
- #
26
- # This class only deals with Protocol Buffer objects,
27
- # and is not part of the public API.
28
- class Connection
29
- API_VERSION = "v1beta2"
30
- API_URL = "https://www.googleapis.com"
31
-
32
- ##
33
- # The project/dataset_id connected to.
34
- attr_accessor :dataset_id
35
-
36
- ##
37
- # The Credentials object for signing HTTP requests.
38
- attr_accessor :credentials
39
-
40
- ##
41
- # Create a new Connection instance.
42
- #
43
- # @example
44
- # conn = Gcloud::Datastore.Connection.new "my-todo-project",
45
- # Gcloud::Datastore::Credentials.new("/path/to/keyfile.json")
46
- #
47
- def initialize dataset_id, credentials
48
- @dataset_id = dataset_id
49
- @credentials = credentials
50
- end
51
-
52
- ##
53
- # Allocate IDs for incomplete keys.
54
- # (This is useful for referencing an entity before it is inserted.)
55
- def allocate_ids *incomplete_keys
56
- allocate_ids = Proto::AllocateIdsRequest.new.tap do |ai|
57
- ai.key = incomplete_keys
58
- end
59
-
60
- rpc_response = rpc("allocateIds", allocate_ids)
61
- Proto::AllocateIdsResponse.decode rpc_response
62
- end
63
-
64
- ##
65
- # Look up entities by keys.
66
- def lookup *keys, consistency: nil, transaction: nil
67
- lookup = Proto::LookupRequest.new key: keys
68
- if consistency == :eventual
69
- lookup.read_options = Proto::ReadOptions.new(read_consistency: 2)
70
- elsif consistency == :strong
71
- lookup.read_options = Proto::ReadOptions.new(read_consistency: 1)
72
- elsif transaction
73
- lookup.read_options = Proto::ReadOptions.new(
74
- transaction: transaction)
75
- end
76
-
77
- Proto::LookupResponse.decode rpc("lookup", lookup)
78
- end
79
-
80
- # Query for entities.
81
- def run_query query, partition = nil, consistency: nil, transaction: nil
82
- run_query = Proto::RunQueryRequest.new.tap do |rq|
83
- rq.query = query
84
- rq.partition_id = partition if partition
85
- end
86
- if consistency == :eventual
87
- run_query.read_options = Proto::ReadOptions.new(read_consistency: 2)
88
- elsif consistency == :strong
89
- run_query.read_options = Proto::ReadOptions.new(read_consistency: 1)
90
- elsif transaction
91
- run_query.read_options = Proto::ReadOptions.new(
92
- transaction: transaction)
93
- end
94
-
95
- Proto::RunQueryResponse.decode rpc("runQuery", run_query)
96
- end
97
-
98
- ##
99
- # Begin a new transaction.
100
- def begin_transaction
101
- tx_request = Proto::BeginTransactionRequest.new
102
-
103
- response_rpc = rpc "beginTransaction", tx_request
104
- Proto::BeginTransactionResponse.decode response_rpc
105
- end
106
-
107
- ##
108
- # Commit a transaction, optionally creating, deleting or modifying
109
- # some entities.
110
- def commit mutation, transaction = nil
111
- mode = Proto::CommitRequest::Mode::NON_TRANSACTIONAL
112
- mode = Proto::CommitRequest::Mode::TRANSACTIONAL if transaction
113
-
114
- commit = Proto::CommitRequest.new.tap do |c|
115
- c.mutation = mutation
116
- c.mode = mode
117
- c.transaction = transaction
118
- end
119
-
120
- Proto::CommitResponse.decode rpc("commit", commit)
121
- end
122
-
123
- ##
124
- # Roll back a transaction.
125
- def rollback transaction
126
- rollback = Proto::RollbackRequest.new.tap do |r|
127
- r.transaction = transaction
128
- end
129
-
130
- Proto::RollbackResponse.decode rpc("rollback", rollback)
131
- end
132
-
133
- ##
134
- # The default HTTP headers to be sent on all API calls.
135
- def default_http_headers
136
- @default_http_headers ||= {
137
- "User-Agent" => "gcloud-node/#{Gcloud::VERSION}",
138
- "Content-Type" => "application/x-protobuf" }
139
- end
140
- ##
141
- # Update the default HTTP headers.
142
- attr_writer :default_http_headers
143
-
144
- ##
145
- # The HTTP object that makes calls to Datastore.
146
- # This must be a Faraday object.
147
- def http
148
- @http ||= Faraday.new url: http_host
149
- end
150
- ##
151
- # Update the HTTP object.
152
- attr_writer :http
153
-
154
- ##
155
- # The Datastore API URL.
156
- def http_host
157
- @http_host || ENV["DATASTORE_HOST"] || API_URL
158
- end
159
-
160
- ##
161
- # Update the Datastore API URL.
162
- def http_host= new_http_host
163
- @http = nil # Reset the HTTP connection when host is set
164
- @http_host = new_http_host
165
- end
166
-
167
- def inspect
168
- "#{self.class}(#{@dataset_id})"
169
- end
170
-
171
- protected
172
-
173
- ##
174
- # Convenience method for making an API call to Datastore.
175
- # Requests will be signed with the credentials object.
176
- def rpc proto_method, proto_request
177
- response = http.post(rpc_path proto_method) do |req|
178
- req.headers.merge! default_http_headers
179
- req.body = get_proto_request_body proto_request
180
-
181
- @credentials.sign_http_request req
182
- end
183
-
184
- fail ApiError.new(proto_method, response) unless response.success?
185
-
186
- response.body
187
- end
188
-
189
- ## Generates the HTTP Path value for the API call.
190
- def rpc_path proto_method
191
- "/datastore/#{API_VERSION}/datasets/#{dataset_id}/#{proto_method}"
192
- end
193
-
194
- ##
195
- # Convenience method for encoding a Beefcake object to a string.
196
- def get_proto_request_body proto_request
197
- proto_request_body = ""
198
- proto_request.encode proto_request_body
199
- proto_request_body
200
- end
201
- end
202
- end
203
- end