google_drive 0.3.11 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -7
  2. data/README.rdoc +27 -10
  3. data/lib/google_drive/acl.rb +40 -58
  4. data/lib/google_drive/acl_entry.rb +76 -56
  5. data/lib/google_drive/api_client_fetcher.rb +49 -0
  6. data/lib/google_drive/collection.rb +69 -71
  7. data/lib/google_drive/file.rb +171 -128
  8. data/lib/google_drive/session.rb +234 -268
  9. data/lib/google_drive/spreadsheet.rb +19 -163
  10. data/lib/google_drive/util.rb +126 -17
  11. data/lib/google_drive/worksheet.rb +108 -80
  12. data/lib/google_drive.rb +63 -57
  13. data/lib/google_drive_v1/acl.rb +115 -0
  14. data/lib/google_drive_v1/acl_entry.rb +100 -0
  15. data/lib/google_drive_v1/api_client_fetcher.rb +47 -0
  16. data/lib/google_drive_v1/authentication_error.rb +14 -0
  17. data/lib/{google_drive → google_drive_v1}/basic_fetcher.rb +1 -1
  18. data/lib/{google_drive → google_drive_v1}/client_login_fetcher.rb +2 -2
  19. data/lib/google_drive_v1/collection.rb +167 -0
  20. data/lib/google_drive_v1/error.rb +12 -0
  21. data/lib/google_drive_v1/file.rb +258 -0
  22. data/lib/google_drive_v1/list.rb +119 -0
  23. data/lib/google_drive_v1/list_row.rb +88 -0
  24. data/lib/{google_drive → google_drive_v1}/oauth1_fetcher.rb +1 -1
  25. data/lib/{google_drive → google_drive_v1}/oauth2_fetcher.rb +2 -2
  26. data/lib/google_drive_v1/record.rb +31 -0
  27. data/lib/google_drive_v1/session.rb +522 -0
  28. data/lib/google_drive_v1/spreadsheet.rb +248 -0
  29. data/lib/google_drive_v1/table.rb +60 -0
  30. data/lib/google_drive_v1/util.rb +73 -0
  31. data/lib/google_drive_v1/worksheet.rb +498 -0
  32. data/lib/google_drive_v1.rb +148 -0
  33. metadata +112 -77
  34. data/doc_src/google_drive/acl_entry.rb +0 -33
@@ -0,0 +1,119 @@
1
+ # Author: Hiroshi Ichikawa <http://gimite.net/>
2
+ # The license of this source is "New BSD Licence"
3
+
4
+ require "google_drive_v1/util"
5
+ require "google_drive_v1/error"
6
+ require "google_drive_v1/list_row"
7
+
8
+
9
+ module GoogleDriveV1
10
+
11
+ # Provides access to cells using column names.
12
+ # Use GoogleDriveV1::Worksheet#list to get GoogleDriveV1::List object.
13
+ #--
14
+ # This is implemented as wrapper of GoogleDriveV1::Worksheet i.e. using cells
15
+ # feed, not list feed. In this way, we can easily provide consistent API as
16
+ # GoogleDriveV1::Worksheet using save()/reload().
17
+ class List
18
+
19
+ include(Enumerable)
20
+
21
+ def initialize(worksheet) #:nodoc:
22
+ @worksheet = worksheet
23
+ end
24
+
25
+ # Number of non-empty rows in the worksheet excluding the first row.
26
+ def size
27
+ return @worksheet.num_rows - 1
28
+ end
29
+
30
+ # Returns Hash-like object (GoogleDriveV1::ListRow) for the row with the
31
+ # index. Keys of the object are colum names (the first row).
32
+ # The second row has index 0.
33
+ #
34
+ # Note that updates to the returned object are not sent to the server until
35
+ # you call GoogleDriveV1::Worksheet#save().
36
+ def [](index)
37
+ return ListRow.new(self, index)
38
+ end
39
+
40
+ # Updates the row with the index with the given Hash object.
41
+ # Keys of +hash+ are colum names (the first row).
42
+ # The second row has index 0.
43
+ #
44
+ # Note that update is not sent to the server until
45
+ # you call GoogleDriveV1::Worksheet#save().
46
+ def []=(index, hash)
47
+ self[index].replace(hash)
48
+ end
49
+
50
+ # Iterates over Hash-like object (GoogleDriveV1::ListRow) for each row
51
+ # (except for the first row).
52
+ # Keys of the object are colum names (the first row).
53
+ def each(&block)
54
+ for i in 0...self.size
55
+ yield(self[i])
56
+ end
57
+ end
58
+
59
+ # Column names i.e. the contents of the first row.
60
+ # Duplicates are removed.
61
+ def keys
62
+ return (1..@worksheet.num_cols).map(){ |i| @worksheet[1, i] }.uniq()
63
+ end
64
+
65
+ # Updates column names i.e. the contents of the first row.
66
+ #
67
+ # Note that update is not sent to the server until
68
+ # you call GoogleDriveV1::Worksheet#save().
69
+ def keys=(ary)
70
+ for i in 1..ary.size
71
+ @worksheet[1, i] = ary[i - 1]
72
+ end
73
+ for i in (ary.size + 1)..@worksheet.num_cols
74
+ @worksheet[1, i] = ""
75
+ end
76
+ end
77
+
78
+ # Adds a new row to the bottom.
79
+ # Keys of +hash+ are colum names (the first row).
80
+ # Returns GoogleDriveV1::ListRow for the new row.
81
+ #
82
+ # Note that update is not sent to the server until
83
+ # you call GoogleDriveV1::Worksheet#save().
84
+ def push(hash)
85
+ row = self[self.size]
86
+ row.update(hash)
87
+ return row
88
+ end
89
+
90
+ # Returns all rows (except for the first row) as Array of Hash.
91
+ # Keys of Hash objects are colum names (the first row).
92
+ def to_hash_array()
93
+ return self.map(){ |r| r.to_hash() }
94
+ end
95
+
96
+ def get(index, key) #:nodoc:
97
+ return @worksheet[index + 2, key_to_col(key)]
98
+ end
99
+
100
+ def numeric_value(index, key) #:nodoc:
101
+ return @worksheet.numeric_value(index + 2, key_to_col(key))
102
+ end
103
+
104
+ def set(index, key, value) #:nodoc:
105
+ @worksheet[index + 2, key_to_col(key)] = value
106
+ end
107
+
108
+ private
109
+
110
+ def key_to_col(key)
111
+ key = key.to_s()
112
+ col = (1..@worksheet.num_cols).find(){ |c| @worksheet[1, c] == key }
113
+ raise(GoogleDriveV1::Error, "Column doesn't exist: %p" % key) if !col
114
+ return col
115
+ end
116
+
117
+ end
118
+
119
+ end
@@ -0,0 +1,88 @@
1
+ # Author: Hiroshi Ichikawa <http://gimite.net/>
2
+ # The license of this source is "New BSD Licence"
3
+
4
+ require "forwardable"
5
+
6
+ require "google_drive_v1/util"
7
+ require "google_drive_v1/error"
8
+
9
+
10
+ module GoogleDriveV1
11
+
12
+ # Hash-like object returned by GoogleDriveV1::List#[].
13
+ class ListRow
14
+
15
+ include(Enumerable)
16
+ extend(Forwardable)
17
+
18
+ def_delegators(:to_hash,
19
+ :keys, :values, :each_key, :each_value, :each, :each_pair, :hash,
20
+ :assoc, :fetch, :flatten, :key, :invert, :size, :length, :rassoc,
21
+ :merge, :reject, :select, :sort, :to_a, :values_at)
22
+
23
+ def initialize(list, index) #:nodoc:
24
+ @list = list
25
+ @index = index
26
+ end
27
+
28
+ def [](key)
29
+ return @list.get(@index, key)
30
+ end
31
+
32
+ def numeric_value(key)
33
+ return @list.numeric_value(@index, key)
34
+ end
35
+
36
+ def []=(key, value)
37
+ @list.set(@index, key, value)
38
+ end
39
+
40
+ def has_key?(key)
41
+ return @list.keys.include?(key)
42
+ end
43
+
44
+ alias include? has_key?
45
+ alias key? has_key?
46
+ alias member? has_key?
47
+
48
+ def update(hash)
49
+ for k, v in hash
50
+ self[k] = v
51
+ end
52
+ end
53
+
54
+ alias merge! update
55
+
56
+ def replace(hash)
57
+ clear()
58
+ update(hash)
59
+ end
60
+
61
+ def clear()
62
+ for key in @list.keys
63
+ self[key] = ""
64
+ end
65
+ end
66
+
67
+ def to_hash()
68
+ result = {}
69
+ for key in @list.keys
70
+ result[key] = self[key]
71
+ end
72
+ return result
73
+ end
74
+
75
+ def ==(other)
76
+ return self.class == other.class && self.to_hash() == other.to_hash()
77
+ end
78
+
79
+ alias === ==
80
+ alias eql? ==
81
+
82
+ def inspect
83
+ return "\#<%p %p>" % [self.class, to_hash()]
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -5,7 +5,7 @@ require "rubygems"
5
5
  require "oauth"
6
6
 
7
7
 
8
- module GoogleDrive
8
+ module GoogleDriveV1
9
9
 
10
10
  class OAuth1Fetcher #:nodoc:
11
11
 
@@ -1,10 +1,10 @@
1
1
  # Author: Hiroshi Ichikawa <http://gimite.net/>
2
2
  # The license of this source is "New BSD Licence"
3
3
 
4
- require "google_drive/basic_fetcher"
4
+ require "google_drive_v1/basic_fetcher"
5
5
 
6
6
 
7
- module GoogleDrive
7
+ module GoogleDriveV1
8
8
 
9
9
  class OAuth2Fetcher < BasicFetcher #:nodoc:
10
10
 
@@ -0,0 +1,31 @@
1
+ # Author: Hiroshi Ichikawa <http://gimite.net/>
2
+ # The license of this source is "New BSD Licence"
3
+
4
+ require "google_drive_v1/util"
5
+ require "google_drive_v1/error"
6
+
7
+
8
+ module GoogleDriveV1
9
+
10
+ # DEPRECATED: Table and Record feeds are deprecated and they will not be available after
11
+ # March 2012.
12
+ #
13
+ # Use GoogleDriveV1::Table#records to get GoogleDriveV1::Record objects.
14
+ class Record < Hash
15
+ include(Util)
16
+
17
+ def initialize(session, entry) #:nodoc:
18
+ @session = session
19
+ entry.css("gs|field").each() do |field|
20
+ self[field["name"]] = field.inner_text
21
+ end
22
+ end
23
+
24
+ def inspect #:nodoc:
25
+ content = self.map(){ |k, v| "%p => %p" % [k, v] }.join(", ")
26
+ return "\#<%p:{%s}>" % [self.class, content]
27
+ end
28
+
29
+ end
30
+
31
+ end