kura 0.2.24 → 0.2.25
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.
- checksums.yaml +4 -4
- data/ChangeLog.md +6 -0
- data/lib/kura/client.rb +36 -11
- data/lib/kura/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9aa09afac8e59350c4f5fb2ea7e348c877a84d9
|
4
|
+
data.tar.gz: 8f89772e36d77680832ce10e6a2d261dbfb8dc94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de549701afd6b948b7e524148386ecc1e327ddfb6a7cb54078d5879ac6e6656939d207c6eaa33c86cbaf29ddbda7c911b004b6ef4da535bab0f92b39b5a50180
|
7
|
+
data.tar.gz: 472330c158606f51a0af6bf7d2930c75862735f171ed6bd8165f8ea38283b1d411008a6dc492b515d958b2ec4b2bf14e8353a1a65d5253fe22bcb6bc162a538b
|
data/ChangeLog.md
CHANGED
data/lib/kura/client.rb
CHANGED
@@ -229,18 +229,43 @@ module Kura
|
|
229
229
|
process_error($!)
|
230
230
|
end
|
231
231
|
|
232
|
-
def
|
232
|
+
def _convert_tabledata_field(x, field_info)
|
233
|
+
if x.nil? and field_info["mode"] == "NULLABLE"
|
234
|
+
return nil
|
235
|
+
end
|
236
|
+
case field_info["type"]
|
237
|
+
when "STRING"
|
238
|
+
x.to_s
|
239
|
+
when "INTEGER"
|
240
|
+
Integer(x)
|
241
|
+
when "FLOAT"
|
242
|
+
Float(x)
|
243
|
+
when "BOOLEAN"
|
244
|
+
x.to_s == "true"
|
245
|
+
when "RECORD"
|
246
|
+
_convert_tabledata_row(x, field_info["fields"])
|
247
|
+
else
|
248
|
+
x
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def _convert_tabledata_row(row, schema)
|
253
|
+
(row.respond_to?(:f) ? row.f : row["f"]).zip(schema).each_with_object({}) do |(v, s), tbl|
|
254
|
+
v = JSON.parse(v.to_json)
|
255
|
+
if s["mode"] == "REPEATED"
|
256
|
+
tbl[s["name"]] = v["v"].map{|c| _convert_tabledata_field(c["v"], s) }
|
257
|
+
else
|
258
|
+
tbl[s["name"]] = _convert_tabledata_field(v["v"], s)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def format_tabledata(r, schema)
|
233
264
|
{
|
234
265
|
total_rows: r.total_rows.to_i,
|
235
266
|
next_token: r.page_token,
|
236
267
|
rows: (r.rows || []).map do |row|
|
237
|
-
row
|
238
|
-
if v.v.is_a?(Array)
|
239
|
-
tbl[fn] = v.v.map{|c| c["v"] }
|
240
|
-
else
|
241
|
-
tbl[fn] = v.v
|
242
|
-
end
|
243
|
-
end
|
268
|
+
_convert_tabledata_row(row, schema)
|
244
269
|
end
|
245
270
|
}
|
246
271
|
end
|
@@ -248,18 +273,18 @@ module Kura
|
|
248
273
|
|
249
274
|
def list_tabledata(dataset_id, table_id, project_id: @default_project_id, start_index: 0, max_result: 100, page_token: nil, schema: nil, &blk)
|
250
275
|
schema ||= table(dataset_id, table_id, project_id: project_id).schema.fields
|
251
|
-
|
276
|
+
schema = schema.map{|s| JSON.parse(s.to_json) }
|
252
277
|
|
253
278
|
if blk
|
254
279
|
@api.list_table_data(project_id, dataset_id, table_id, max_results: max_result, start_index: start_index, page_token: page_token) do |r, err|
|
255
280
|
if r
|
256
|
-
r = format_tabledata(r,
|
281
|
+
r = format_tabledata(r, schema)
|
257
282
|
end
|
258
283
|
blk.call(r, err)
|
259
284
|
end
|
260
285
|
else
|
261
286
|
r = @api.list_table_data(project_id, dataset_id, table_id, max_results: max_result, start_index: start_index, page_token: page_token)
|
262
|
-
format_tabledata(r,
|
287
|
+
format_tabledata(r, schema)
|
263
288
|
end
|
264
289
|
rescue
|
265
290
|
process_error($!)
|
data/lib/kura/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chikanaga Tomoyuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|