google_drive2 3.0.8

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.
@@ -0,0 +1,89 @@
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/util'
7
+ require 'google_drive/error'
8
+
9
+ module GoogleDrive
10
+ # Hash-like object returned by GoogleDrive::List#[].
11
+ class ListRow
12
+ include(Enumerable)
13
+ extend(Forwardable)
14
+
15
+ def_delegators(:to_hash,
16
+ :keys, :values, :each_key, :each_value, :each, :each_pair,
17
+ :hash, :assoc, :fetch, :flatten, :key, :invert, :size,
18
+ :length, :rassoc, :merge, :reject, :select, :sort, :to_a,
19
+ :values_at)
20
+
21
+ # @api private
22
+ def initialize(list, index)
23
+ @list = list
24
+ @index = index
25
+ end
26
+
27
+ def [](key)
28
+ @list.get(@index, key)
29
+ end
30
+
31
+ def numeric_value(key)
32
+ @list.numeric_value(@index, key)
33
+ end
34
+
35
+ def input_value(key)
36
+ @list.input_value(@index, key)
37
+ end
38
+
39
+ def []=(key, value)
40
+ @list.set(@index, key, value)
41
+ end
42
+
43
+ def has_key?(key)
44
+ @list.keys.include?(key)
45
+ end
46
+
47
+ alias include? has_key?
48
+ alias key? has_key?
49
+ alias member? has_key?
50
+
51
+ def update(hash)
52
+ hash.each do |k, v|
53
+ self[k] = v
54
+ end
55
+ end
56
+
57
+ alias merge! update
58
+
59
+ def replace(hash)
60
+ clear
61
+ update(hash)
62
+ end
63
+
64
+ def clear
65
+ @list.keys.each do |key|
66
+ self[key] = ''
67
+ end
68
+ end
69
+
70
+ def to_hash
71
+ result = {}
72
+ @list.keys.each do |key|
73
+ result[key] = self[key]
74
+ end
75
+ result
76
+ end
77
+
78
+ def ==(other)
79
+ self.class == other.class && to_hash == other.to_hash
80
+ end
81
+
82
+ alias === ==
83
+ alias eql? ==
84
+
85
+ def inspect
86
+ format("\#<%p %p>", self.class, to_hash)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,23 @@
1
+ # Author: Hiroshi Ichikawa <http://gimite.net/>
2
+ # The license of this source is "New BSD Licence"
3
+
4
+ require 'cgi'
5
+
6
+ require 'google_drive/error'
7
+
8
+ module GoogleDrive
9
+ # Raised when an HTTP request has returned an unexpected response code.
10
+ class ResponseCodeError < GoogleDrive::Error
11
+ # @api private
12
+ def initialize(code, body, method, url)
13
+ @code = code
14
+ @body = body
15
+ super(format(
16
+ 'Response code %s for %s %s: %s',
17
+ code, method, url, CGI.unescapeHTML(body)
18
+ ))
19
+ end
20
+
21
+ attr_reader(:code, :body)
22
+ end
23
+ end