Skip to content

Commit 92152c0

Browse files
committed
Merge pull request abronte#37 from kysnm/add-method-table-raw-data
Add method table_raw_data
2 parents 1de4415 + 9e980f1 commit 92152c0

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/big_query/client/tables.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,28 @@ def tables_formatted(dataset = @dataset)
3131
tables(dataset).map { |t| t['tableReference']['tableId'] }
3232
end
3333

34-
# Returns all rows of table data
34+
# Returns entire response of table data
3535
#
3636
# @param tableId [String] id of the table to look for
3737
# @param dataset [String] dataset to look for
3838
# @param options [Hash] hash of optional query parameters (maxResults, startIndex)
3939
# @return [Hash] json api response
40-
def table_data(tableId, dataset = @dataset, options = {})
40+
def table_raw_data(tableId, dataset = @dataset, options = {})
4141
parameters = { 'datasetId' => dataset, 'tableId' => tableId }
4242
parameters['maxResults'] = options[:maxResults] if options[:maxResults]
4343
parameters['startIndex'] = options[:startIndex] if options[:startIndex]
44-
response = api(api_method: @bq.tabledata.list,
44+
api(api_method: @bq.tabledata.list,
4545
parameters: parameters)
46+
end
47+
48+
# Returns all rows of table data
49+
#
50+
# @param tableId [String] id of the table to look for
51+
# @param dataset [String] dataset to look for
52+
# @param options [Hash] hash of optional query parameters (maxResults, startIndex)
53+
# @return [Hash] json api response
54+
def table_data(tableId, dataset = @dataset, options = {})
55+
response = table_raw_data(tableId, dataset, options)
4656
response['rows'] || []
4757
end
4858

test/bigquery.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ def test_for_tables_formatted
4242
assert_includes result, 'test'
4343
end
4444

45-
def test_for_table_data
46-
result = @bq.table_data('test')
45+
def test_for_table_raw_data
46+
result = @bq.table_raw_data('test')
4747

48-
assert_kind_of Array, result
48+
assert_kind_of Hash, result
49+
assert_equal result['kind'], "bigquery#tableDataList"
4950
end
5051

5152
def test_for_table_data_maxResults

0 commit comments

Comments
 (0)