fusion_tables_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6457a099c117c227e0d8df8c6e0a34fd0a7986e5
4
- data.tar.gz: 3daee24939615fa42853800d3db11186a168c915
3
+ metadata.gz: 788fd708130a4c637e396d204f146ff45e516532
4
+ data.tar.gz: 80fcf67122e80b21dc0444a44d04f2a723fc7ba2
5
5
  SHA512:
6
- metadata.gz: 86c36ae4a06b359428e41f9e69cbcf7e59dcb06fdafa9c37d719e8c09497895d1b6fe8ed61538352f145e53073d4d37093c9295aeb5eff94cb8ae2df2d645fab
7
- data.tar.gz: 304c0371f04161c141f92333b86997bdb1b42bb35cffe1476ddffdce10917283eafaf8514a69cdcad0c964bd3c84e7f7689f7886f26b5d26abbb45743ef98d30
6
+ metadata.gz: e2bf5ccec320972e4d87ddf6deb95673970702bf24dfcba928df116dcadb0064ba820b95a2d69b2eb5dc6addffebee2306156ffdcdff3ca18d8268a6943f62b8
7
+ data.tar.gz: c25eaad1e965cace106a9ec16208f03fdf00b0a161097f66801e8255b40512fde47f882729ecf427e984a31f546c7e6efc483d48f1dc26c9a008d5654c481e98
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ tmp
19
19
  *.vim
20
20
  *.yml
21
21
  ft_script_test.rb
22
+ *.csv
data/HISTORY.md CHANGED
@@ -1,4 +1,7 @@
1
- # Version 0.0.1 (04-30-2013)
1
+ ## Version 0.0.2 (04-30-2013)
2
+ * Pushed up a small fix
3
+
4
+ ## Version 0.0.1 (04-30-2013)
2
5
  * First release
3
6
  * Get table list is known to work
4
7
  * Truthfully, I was just trying to claim the name for the gem on RubyGems
data/README.md CHANGED
@@ -19,7 +19,25 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- TODO: Write usage instructions here
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
- @oauth_authorization['access_token'] = @access_token
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
- tokens = YAML.load_file(oauth_tokens)
40
- set_access_token(tokens['access_token'])
41
- set_refresh_token(tokens['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
- oauth_authorization ||= @client.authorization.fetch_access_token!
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= nil)
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= nil)
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
@@ -1,3 +1,3 @@
1
1
  class FusionTablesAPI
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusion_tables_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Villena