fusion_tables_api 0.0.2 → 0.0.3
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/.gitignore +1 -0
- data/HISTORY.md +4 -1
- data/README.md +19 -1
- data/lib/fusion_tables_api/authorization.rb +8 -7
- data/lib/fusion_tables_api/table.rb +12 -4
- data/lib/fusion_tables_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 788fd708130a4c637e396d204f146ff45e516532
|
4
|
+
data.tar.gz: 80fcf67122e80b21dc0444a44d04f2a723fc7ba2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2bf5ccec320972e4d87ddf6deb95673970702bf24dfcba928df116dcadb0064ba820b95a2d69b2eb5dc6addffebee2306156ffdcdff3ca18d8268a6943f62b8
|
7
|
+
data.tar.gz: c25eaad1e965cace106a9ec16208f03fdf00b0a161097f66801e8255b40512fde47f882729ecf427e984a31f546c7e6efc483d48f1dc26c9a008d5654c481e98
|
data/.gitignore
CHANGED
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,25 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
|
22
|
+
cred = {
|
23
|
+
client_id: "check-your-google-api-console-for-this",
|
24
|
+
client_secret: "same-thing-as-above"
|
25
|
+
}
|
26
|
+
|
27
|
+
tokens = {
|
28
|
+
access_token: "if-you-have-the-access-token-then-use-it",
|
29
|
+
refresh_token: "refresh-token-would-be-useful-too"
|
30
|
+
}
|
31
|
+
|
32
|
+
ft = FusionTablesAPI.new(cred, tokens)
|
33
|
+
ft.get_table_list
|
34
|
+
|
35
|
+
OR
|
36
|
+
|
37
|
+
ft = FusionTablesAPI.new("google_oauth_credentials.yml", "google_access_token.yml")
|
38
|
+
ft.get_table_list
|
39
|
+
|
40
|
+
**TODO: Finish this....**
|
23
41
|
|
24
42
|
## Contributing
|
25
43
|
|
@@ -11,9 +11,8 @@ class FusionTablesAPI
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def store_new_access_token
|
14
|
-
@access_token = @client.authorization.access_token
|
15
|
-
|
16
|
-
File.open(GOOGLE_OAUTH_FILENAME, 'w+') { |f| f.write(@oauth_authorization.to_yaml)}
|
14
|
+
@authorization_tokens['access_token'] = @client.authorization.access_token
|
15
|
+
File.open(GOOGLE_OAUTH_TOKEN_FILE, 'w+') { |f| f.write(@authorization_tokens.to_yaml)}
|
17
16
|
end
|
18
17
|
|
19
18
|
# Takes hash or file and loads oauth credentials
|
@@ -33,12 +32,13 @@ class FusionTablesAPI
|
|
33
32
|
|
34
33
|
def load_oauth_tokens(oauth_tokens)
|
35
34
|
if oauth_tokens.is_a?(Hash)
|
35
|
+
# TODO Need to involve instance variable authorization_tokens
|
36
36
|
set_access_token(oauth_tokens[:access_token])
|
37
37
|
set_refresh_token(oauth_tokens[:refresh_token])
|
38
38
|
else
|
39
|
-
|
40
|
-
set_access_token(
|
41
|
-
set_refresh_token(
|
39
|
+
@authorization_tokens = YAML.load_file(oauth_tokens)
|
40
|
+
set_access_token(@authorization_tokens['access_token'])
|
41
|
+
set_refresh_token(@authorization_tokens['refresh_token'])
|
42
42
|
end
|
43
43
|
true
|
44
44
|
end
|
@@ -57,7 +57,8 @@ class FusionTablesAPI
|
|
57
57
|
code = gets.chomp.strip
|
58
58
|
|
59
59
|
@client.authorization.code = code
|
60
|
-
|
60
|
+
# TODO Need to this one below
|
61
|
+
@authorization_tokens ||= @client.authorization.fetch_access_token!
|
61
62
|
|
62
63
|
File.open(GOOGLE_OAUTH_TOKEN_FILE, 'w+') { |f| f.write(oauth_authorization.to_yaml)}
|
63
64
|
puts "Google OAuth Tokens written to #{GOOGLE_OAUTH_TOKEN_FILE}"
|
@@ -1,3 +1,12 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
# TODO May need to change this
|
4
|
+
class String
|
5
|
+
def is_i?
|
6
|
+
!!(self =~/^[-+]?[0-9]+$/)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
1
10
|
class FusionTablesAPI
|
2
11
|
# TODO Might eventually want to create a table class
|
3
12
|
### FusionTables API Table methods ###
|
@@ -25,13 +34,13 @@ class FusionTablesAPI
|
|
25
34
|
request_body = { "columns" => column_names, "isExportable" => false, "name" => File.basename(filename, ".csv") }
|
26
35
|
result = @client.execute(api_method: @fusion_tables_api.table.insert, headers: headers, body: request_body.to_json)
|
27
36
|
parsed_result = JSON.parse(result.body)
|
28
|
-
store_new_access_token if @client.authorization.access_token != @access_token
|
37
|
+
store_new_access_token if @client.authorization.access_token != @authorization_tokens['access_token']
|
29
38
|
|
30
39
|
puts "#### \nCreate Table Response:\n#{result.body}\n####\n"
|
31
40
|
parsed_result # return
|
32
41
|
end
|
33
42
|
|
34
|
-
def import_rows(filename, table_id, start_line=
|
43
|
+
def import_rows(filename, table_id, start_line= 0)
|
35
44
|
headers = Hash.new
|
36
45
|
headers[:content_type] = 'application/octet-stream'
|
37
46
|
params = { tableId: table_id, startLine: start_line, isStrict: false } # May need to set isStrict to false
|
@@ -39,13 +48,12 @@ class FusionTablesAPI
|
|
39
48
|
import_row_url = "https://www.googleapis.com/upload/fusiontables/v1/tables/tableId/import"
|
40
49
|
|
41
50
|
result = @client.execute(uri: import_row_url, http_method: :post, body: request_body, headers: headers, parameters: params )
|
42
|
-
update_fusion_table_row_count(File.basename(filename, '.csv'), result.data["numRowsReceived"].to_i)
|
43
51
|
jj result.data
|
44
52
|
|
45
53
|
true # return
|
46
54
|
end
|
47
55
|
|
48
|
-
def generate_table(filename, start_line=
|
56
|
+
def generate_table(filename, start_line= 0)
|
49
57
|
response = create_table(filename)
|
50
58
|
import_rows(filename, response["tableId"], start_line)
|
51
59
|
end
|