gimite-google-spreadsheet-ruby 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- This is a library to read/write Google Spreadsheet.
1
+ This is a Ruby 1.8/1.9 library to read/write Google Spreadsheet.
2
2
 
3
3
 
4
4
  = How to install
@@ -51,6 +51,11 @@ http://github.com/gimite/google-spreadsheet-ruby/tree/master
51
51
  The license of this source is "New BSD Licence"
52
52
 
53
53
 
54
+ = Supported environments
55
+
56
+ Ruby 1.8.x and Ruby 1.9.x. Checked with Ruby 1.8.7 and Ruby 1.9.1.
57
+
58
+
54
59
  = Author
55
60
 
56
61
  Hiroshi Ichikawa - http://gimite.net/en/index.php?Contact
@@ -10,6 +10,19 @@ require "hpricot"
10
10
  Net::HTTP.version_1_2
11
11
 
12
12
 
13
+ if RUBY_VERSION < "1.9.0"
14
+
15
+ class String
16
+
17
+ def force_encoding(encoding)
18
+ return self
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
13
26
  module GoogleSpreadsheet
14
27
 
15
28
  # Authenticates with given +mail+ and +password+, and returns GoogleSpreadsheet::Session
@@ -27,10 +40,18 @@ module GoogleSpreadsheet
27
40
  def self.saved_session(path = ENV["HOME"] + "/.ruby_google_spreadsheet.token")
28
41
  session = Session.new(File.exist?(path) ? File.read(path) : nil)
29
42
  session.on_auth_fail = proc() do
30
- require "password"
31
- $stderr.print("Mail: ")
32
- mail = $stdin.gets().chomp()
33
- password = Password.get()
43
+ begin
44
+ require "highline2"
45
+ rescue LoadError
46
+ raise(LoadError,
47
+ "GoogleSpreadsheet.saved_session requires Highline library.\n" +
48
+ "Run\n" +
49
+ " \$ sudo gem install highline\n" +
50
+ "to install it.")
51
+ end
52
+ highline = HighLine.new()
53
+ mail = highline.ask("Mail: ")
54
+ password = highline.ask("Password: "){ |q| q.echo = false }
34
55
  session.login(mail, password)
35
56
  open(path, "w", 0600){ |f| f.write(session.auth_token) }
36
57
  true
@@ -78,6 +99,10 @@ module GoogleSpreadsheet
78
99
  return CGI.escapeHTML(str.to_s())
79
100
  end
80
101
 
102
+ def as_utf8(str)
103
+ str.force_encoding("UTF-8")
104
+ end
105
+
81
106
  end
82
107
 
83
108
 
@@ -190,9 +215,9 @@ module GoogleSpreadsheet
190
215
  doc = get("http://spreadsheets.google.com/feeds/spreadsheets/private/full?#{query}")
191
216
  result = []
192
217
  for entry in doc.search("entry")
193
- title = entry.search("title").text
194
- url = entry.search(
195
- "link[@rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed']")[0]["href"]
218
+ title = as_utf8(entry.search("title").text)
219
+ url = as_utf8(entry.search(
220
+ "link[@rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed']")[0]["href"])
196
221
  result.push(Spreadsheet.new(self, url, title))
197
222
  end
198
223
  return result
@@ -280,9 +305,9 @@ module GoogleSpreadsheet
280
305
  doc = @session.get(@worksheets_feed_url)
281
306
  result = []
282
307
  for entry in doc.search("entry")
283
- title = entry.search("title").text
284
- url = entry.search(
285
- "link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"]
308
+ title = as_utf8(entry.search("title").text)
309
+ url = as_utf8(entry.search(
310
+ "link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"])
286
311
  result.push(Worksheet.new(@session, self, url, title))
287
312
  end
288
313
  return result.freeze()
@@ -299,8 +324,8 @@ module GoogleSpreadsheet
299
324
  </entry>
300
325
  EOS
301
326
  doc = @session.post(@worksheets_feed_url, xml)
302
- url = doc.search(
303
- "link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"]
327
+ url = as_utf8(doc.search(
328
+ "link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"])
304
329
  return Worksheet.new(@session, self, url, title)
305
330
  end
306
331
 
@@ -320,8 +345,8 @@ module GoogleSpreadsheet
320
345
 
321
346
  def initialize(session, entry) #:nodoc:
322
347
  @columns = {}
323
- @worksheet_title = entry.search("gs:worksheet")[0]["name"]
324
- @records_url = entry.search("content")[0]["src"]
348
+ @worksheet_title = as_utf8(entry.search("gs:worksheet")[0]["name"])
349
+ @records_url = as_utf8(entry.search("content")[0]["src"])
325
350
  @session = session
326
351
  end
327
352
 
@@ -357,8 +382,8 @@ module GoogleSpreadsheet
357
382
 
358
383
  def initialize(session, entry) #:nodoc:
359
384
  @session = session
360
- for field in entry.search('gs:field')
361
- self[field["name"]] = field.inner_text
385
+ for field in entry.search("gs:field")
386
+ self[as_utf8(field["name"])] = as_utf8(field.inner_text)
362
387
  end
363
388
  end
364
389
 
@@ -517,7 +542,7 @@ module GoogleSpreadsheet
517
542
  doc = @session.get(@cells_feed_url)
518
543
  @max_rows = doc.search("gs:rowCount").text.to_i()
519
544
  @max_cols = doc.search("gs:colCount").text.to_i()
520
- @title = doc.search("title").text
545
+ @title = as_utf8(doc.search("title").text)
521
546
 
522
547
  @cells = {}
523
548
  @input_values = {}
@@ -525,8 +550,8 @@ module GoogleSpreadsheet
525
550
  cell = entry.search("gs:cell")[0]
526
551
  row = cell["row"].to_i()
527
552
  col = cell["col"].to_i()
528
- @cells[[row, col]] = cell.inner_text
529
- @input_values[[row, col]] = cell["inputValue"]
553
+ @cells[[row, col]] = as_utf8(cell.inner_text)
554
+ @input_values[[row, col]] = as_utf8(cell["inputValue"])
530
555
  end
531
556
  @modified.clear()
532
557
  @meta_modified = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gimite-google-spreadsheet-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Ichikawa
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-13 00:00:00 -07:00
12
+ date: 2009-09-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,16 +30,17 @@ executables: []
30
30
  extensions: []
31
31
 
32
32
  extra_rdoc_files:
33
- - README.txt
33
+ - README.rdoc
34
34
  files:
35
- - README.txt
35
+ - README.rdoc
36
36
  - lib/google_spreadsheet.rb
37
37
  has_rdoc: true
38
38
  homepage: http://github.com/gimite/google-spreadsheet-ruby/tree/master
39
+ licenses:
39
40
  post_install_message:
40
41
  rdoc_options:
41
42
  - --main
42
- - README.txt
43
+ - README.rdoc
43
44
  require_paths:
44
45
  - lib
45
46
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
58
  requirements: []
58
59
 
59
60
  rubyforge_project:
60
- rubygems_version: 1.2.0
61
+ rubygems_version: 1.3.5
61
62
  signing_key:
62
63
  specification_version: 2
63
64
  summary: This is a library to read/write Google Spreadsheet.