dewey 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +23 -14
- data/dewey.gemspec +3 -3
- data/lib/dewey.rb +2 -2
- data/lib/dewey/client_auth.rb +4 -4
- data/lib/dewey/core.rb +25 -25
- data/lib/dewey/mime.rb +49 -21
- data/lib/dewey/validation.rb +4 -4
- data/lib/dewey/version.rb +1 -1
- data/spec/client_auth_spec.rb +11 -11
- data/spec/core/convert_spec.rb +1 -1
- data/spec/core/get_spec.rb +7 -7
- data/spec/core/put_spec.rb +5 -5
- data/spec/core/search_spec.rb +4 -4
- data/spec/core_spec.rb +1 -1
- data/spec/mime_spec.rb +30 -13
- data/spec/validation_spec.rb +1 -1
- metadata +46 -54
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.2.9 (October 2, 2011)
|
2
|
+
|
3
|
+
* Better support for files without an extension (Cory Schires)
|
4
|
+
* Don't fail when `docx` has a mime type of `application/zip` (Cory Schires)
|
5
|
+
|
6
|
+
## 0.2.8 (April 19, 2011)
|
7
|
+
|
8
|
+
* Remove x-www-form-urlencoded header for compatiblity with latest API
|
9
|
+
|
1
10
|
## 0.2.7 (December 12, 2010)
|
2
11
|
|
3
12
|
* Documents, Drawings and Presentations are actually downloadable again. The
|
@@ -6,19 +15,19 @@
|
|
6
15
|
* Minor internal improvements
|
7
16
|
|
8
17
|
## 0.2.6 (November 3, 2010)
|
9
|
-
|
18
|
+
|
10
19
|
* Downloaded files are automatically rewound
|
11
20
|
|
12
21
|
## 0.2.5 (November 3, 2010)
|
13
|
-
|
22
|
+
|
14
23
|
* Sheet (gid) support for spreadsheets
|
15
24
|
* Delegate authentication, more reliable and no need for eval + alias_method
|
16
25
|
* Fix spreadsheet calls not authenticating
|
17
26
|
|
18
27
|
## 0.2.4 (November 2, 2010)
|
19
|
-
|
28
|
+
|
20
29
|
Additions:
|
21
|
-
|
30
|
+
|
22
31
|
- Support downloading drawings
|
23
32
|
- Support downloading presentations
|
24
33
|
- Drawing mime support and validation
|
@@ -29,7 +38,7 @@
|
|
29
38
|
- Add support for new style export options (exportFormat & format)
|
30
39
|
|
31
40
|
Bugfixes:
|
32
|
-
|
41
|
+
|
33
42
|
- Fix search results pulling the feed id and not just the entry id
|
34
43
|
- Fix entries pulling the feed along with the resource id
|
35
44
|
- Remove calls to blank?
|
@@ -37,13 +46,13 @@
|
|
37
46
|
## 0.2.3 (October 30, 2010)
|
38
47
|
|
39
48
|
Additions:
|
40
|
-
|
49
|
+
|
41
50
|
- #delete and #delete! accept an optional :trash option to send a resource
|
42
51
|
to the trash, rather than being fully deleted.
|
43
52
|
- #get and #elete by title. Handles exact matches only.
|
44
|
-
|
53
|
+
|
45
54
|
Bugfixes:
|
46
|
-
|
55
|
+
|
47
56
|
- Not setting the :format option on #get no longers raises
|
48
57
|
|
49
58
|
## 0.2.2 (October 27, 2010)
|
@@ -70,28 +79,28 @@ Bugfixes:
|
|
70
79
|
## 0.2.0 (October 20, 2010)
|
71
80
|
|
72
81
|
Additions:
|
73
|
-
|
82
|
+
|
74
83
|
- Class-wide authentication. You only have to set up authentication once and
|
75
84
|
then utilize that in all successive calls.
|
76
85
|
- All file operations are stateless (Dewey.put, Dewey.get, etc)
|
77
86
|
- Store multiple authorizations simultaneously.
|
78
|
-
|
87
|
+
|
79
88
|
Changes:
|
80
89
|
|
81
90
|
- Convert API change. Format is required, not an option.
|
82
91
|
- No longer supports upload or download, instead use put or get.
|
83
92
|
|
84
93
|
## 0.1.4 (October 19, 2010)
|
85
|
-
|
94
|
+
|
86
95
|
Additions:
|
87
|
-
|
96
|
+
|
88
97
|
- Handle bad mimetypes.
|
89
98
|
- Modular validation
|
90
99
|
- Removed service option, needless.
|
91
100
|
- Automatic implicit authorization, removes need to call authorize! manually.
|
92
101
|
|
93
102
|
Bugfixes:
|
94
|
-
|
103
|
+
|
95
104
|
- Prevent peer certificate warnings in 1.9
|
96
105
|
- Fixed id extraction regex that prevented resources with dashes or underscores
|
97
106
|
from being pulled.
|
@@ -111,7 +120,7 @@ Features:
|
|
111
120
|
Bugfixes:
|
112
121
|
|
113
122
|
- Handle files with no extension
|
114
|
-
|
123
|
+
|
115
124
|
---
|
116
125
|
## 0.1.1 (June 28, 2010)
|
117
126
|
|
data/dewey.gemspec
CHANGED
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubyforge_project = 'dewey'
|
16
16
|
|
17
17
|
s.add_development_dependency 'rake', '~> 0.8.7'
|
18
|
-
s.add_development_dependency 'rspec', '~> 2.
|
19
|
-
s.add_development_dependency 'webmock', '~> 1.
|
20
|
-
s.add_development_dependency 'yard', '~> 0.
|
18
|
+
s.add_development_dependency 'rspec', '~> 2.6.0'
|
19
|
+
s.add_development_dependency 'webmock', '~> 1.7.6'
|
20
|
+
s.add_development_dependency 'yard', '~> 0.7.2'
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
23
23
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
data/lib/dewey.rb
CHANGED
@@ -2,13 +2,13 @@ module Dewey
|
|
2
2
|
GOOGLE_DOCS_URL = "https://docs.google.com"
|
3
3
|
GOOGLE_SPRD_URL = "https://spreadsheets.google.com"
|
4
4
|
GOOGLE_LOGIN_URL = "https://www.google.com/accounts/ClientLogin"
|
5
|
-
|
5
|
+
|
6
6
|
GOOGLE_FEED_URL = GOOGLE_DOCS_URL + "/feeds/default/private/full"
|
7
7
|
GOOGLE_DOCUMENT_URL = GOOGLE_DOCS_URL + "/feeds/download/documents/Export"
|
8
8
|
GOOGLE_DRAWING_URL = GOOGLE_DOCS_URL + "/feeds/download/drawings/Export"
|
9
9
|
GOOGLE_PRESENTATION_URL = GOOGLE_DOCS_URL + "/feeds/download/presentations/Export"
|
10
10
|
GOOGLE_SPREADSHEET_URL = GOOGLE_SPRD_URL + "/feeds/download/spreadsheets/Export"
|
11
|
-
|
11
|
+
|
12
12
|
class DeweyError < StandardError; end
|
13
13
|
class DeweyAuthorizationError < StandardError; end
|
14
14
|
end
|
data/lib/dewey/client_auth.rb
CHANGED
@@ -2,7 +2,7 @@ module Dewey
|
|
2
2
|
class ClientAuth
|
3
3
|
attr_reader :authentications
|
4
4
|
|
5
|
-
def initialize(email, password)
|
5
|
+
def initialize(email, password)
|
6
6
|
@email = email
|
7
7
|
@password = password
|
8
8
|
@authentications = {}
|
@@ -12,10 +12,10 @@ module Dewey
|
|
12
12
|
if service
|
13
13
|
@authentications.has_key?(service)
|
14
14
|
else
|
15
|
-
@authentications.any?
|
15
|
+
@authentications.any?
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def authenticate!(service = nil)
|
20
20
|
service ||= :writely
|
21
21
|
|
@@ -39,7 +39,7 @@ module Dewey
|
|
39
39
|
raise DeweyError, "Unexpected response: #{response}"
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def token(service = nil)
|
44
44
|
service = guard(service)
|
45
45
|
authenticate!(service) unless authenticated?(service)
|
data/lib/dewey/core.rb
CHANGED
@@ -5,7 +5,7 @@ require 'tempfile'
|
|
5
5
|
|
6
6
|
module Dewey
|
7
7
|
class << self
|
8
|
-
|
8
|
+
|
9
9
|
# Set the authentication strategy. You can currently only use ClientAuth,
|
10
10
|
# but you must provide +email+ and +password+ options. You must set up
|
11
11
|
# authentication before using any file operations.
|
@@ -16,14 +16,14 @@ module Dewey
|
|
16
16
|
@@authenticator = Dewey::ClientAuth.new(options[:email], options[:password])
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# Report whether Dewey has both an authentication strategy selected, and has
|
21
21
|
# been authenticated. Delegates to the chosen authenticator.
|
22
22
|
#
|
23
23
|
def authenticated?
|
24
24
|
!@@authenticator.nil? && @@authenticator.authenticated?
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# Tell the authentication strategy to authenticate. Not necessary though, as
|
28
28
|
# any file operation will authenticate automatically.
|
29
29
|
#
|
@@ -31,7 +31,7 @@ module Dewey
|
|
31
31
|
@@authenticator.authenticate!
|
32
32
|
end
|
33
33
|
|
34
|
-
# Queries the document list for a particular title. Titles can be either
|
34
|
+
# Queries the document list for a particular title. Titles can be either
|
35
35
|
# full or partial matches. Matches are returned as an array of ids.
|
36
36
|
#
|
37
37
|
# @param [String] query The title to be matched
|
@@ -46,7 +46,7 @@ module Dewey
|
|
46
46
|
url = "#{GOOGLE_FEED_URL}?title=#{title}"
|
47
47
|
url << "&title-exact=true" if options[:exact]
|
48
48
|
response = http_request(:get, url, headers)
|
49
|
-
|
49
|
+
|
50
50
|
response.kind_of?(Net::HTTPOK) ? extract_ids(response.body) : []
|
51
51
|
end
|
52
52
|
|
@@ -57,27 +57,27 @@ module Dewey
|
|
57
57
|
# @param [Hash] options Options for uploading the file
|
58
58
|
# @option options [Symbol] :title An alternative title, to be used instead
|
59
59
|
# of the filename
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# @return [String, nil] The id if upload was successful, nil otherwise
|
62
62
|
def put(file, options = {})
|
63
|
-
extension =
|
63
|
+
extension = Dewey::Mime.extension(file)
|
64
64
|
basename = File.basename(file.path, ".#{extension}")
|
65
65
|
mimetype = Dewey::Mime.mime_type(file)
|
66
66
|
service = Dewey::Mime.guess_service(mimetype)
|
67
67
|
title = options[:title] || basename
|
68
|
-
|
68
|
+
|
69
69
|
raise DeweyError, "Invalid file type: #{extension}" unless Dewey::Validation.valid_upload_format?(extension, service)
|
70
|
-
|
70
|
+
|
71
71
|
headers = base_headers
|
72
72
|
headers['Content-Length'] = File.size?(file).to_s
|
73
73
|
headers['Slug'] = Dewey::Utils.slug(title)
|
74
74
|
headers['Content-Type'] = mimetype unless mimetype =~ /Can't expand summary_info/
|
75
|
-
|
75
|
+
|
76
76
|
# Rewind the file in the case of multiple uploads, or conversions
|
77
77
|
file.rewind
|
78
|
-
|
78
|
+
|
79
79
|
response = http_request(:post, GOOGLE_FEED_URL, headers, file.read.to_s)
|
80
|
-
|
80
|
+
|
81
81
|
if response.kind_of?(Net::HTTPCreated)
|
82
82
|
extract_ids(response.body).first
|
83
83
|
else
|
@@ -98,7 +98,7 @@ module Dewey
|
|
98
98
|
# `My Document` for example
|
99
99
|
# @param [Hash] options Options for downloading the document
|
100
100
|
# @option options [Symbol] :format The output format
|
101
|
-
#
|
101
|
+
#
|
102
102
|
# @return [Tempfile, nil] The downloaded file, otherwise `nil` if the file
|
103
103
|
# couldn't be found.
|
104
104
|
#
|
@@ -137,12 +137,12 @@ module Dewey
|
|
137
137
|
url << "&format=#{format}" if service == 'document'
|
138
138
|
url << "&gid=#{options[:sheet]}" if service == 'spreadsheet' && options[:sheet]
|
139
139
|
else
|
140
|
-
raise DeweyError, "Invalid format: #{format}"
|
140
|
+
raise DeweyError, "Invalid format: #{format}"
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
response = http_request(:get, url, base_headers(service))
|
145
|
-
|
145
|
+
|
146
146
|
if response.kind_of?(Net::HTTPOK)
|
147
147
|
file = Tempfile.new([id, format].join('.')).binmode
|
148
148
|
file.write(response.body)
|
@@ -154,7 +154,7 @@ module Dewey
|
|
154
154
|
end
|
155
155
|
|
156
156
|
# Deletes a document. The default behavior is to delete the document
|
157
|
-
# permanently, rather than trashing it.
|
157
|
+
# permanently, rather than trashing it.
|
158
158
|
#
|
159
159
|
# @param [String] query A resource id or title. If a title is provided
|
160
160
|
# a search will be performed automatically.
|
@@ -166,23 +166,23 @@ module Dewey
|
|
166
166
|
def delete(query, options = {})
|
167
167
|
|
168
168
|
# We use 'If-Match' => '*' to make sure we delete regardless of others
|
169
|
-
headers = base_headers.merge({'If-Match' => '*'})
|
169
|
+
headers = base_headers.merge({'If-Match' => '*'})
|
170
170
|
trash = options.delete(:trash) || false
|
171
171
|
id = (is_id?(query)) ? query : search(query, :exact => true).first
|
172
|
-
|
172
|
+
|
173
173
|
return false if id.nil?
|
174
174
|
|
175
175
|
url = "#{GOOGLE_FEED_URL}/#{URI.escape(id)}"
|
176
176
|
url << "?delete=true" unless trash
|
177
177
|
|
178
178
|
response = http_request(:delete, url, headers)
|
179
|
-
|
179
|
+
|
180
180
|
response.kind_of?(Net::HTTPOK)
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
# The same as delete, except that it will raise `Dewey::DeweyError` if
|
184
184
|
# the request fails.
|
185
|
-
#
|
185
|
+
#
|
186
186
|
# @see #delete
|
187
187
|
def delete!(query, options = {})
|
188
188
|
delete(query, options) || raise(DeweyError, "Unable to delete document")
|
@@ -204,9 +204,9 @@ module Dewey
|
|
204
204
|
def convert(file, options = {})
|
205
205
|
id = put(file, options[:title])
|
206
206
|
converted = get(id, options[:format])
|
207
|
-
|
207
|
+
|
208
208
|
delete(id)
|
209
|
-
|
209
|
+
|
210
210
|
converted
|
211
211
|
end
|
212
212
|
|
@@ -218,7 +218,7 @@ module Dewey
|
|
218
218
|
end
|
219
219
|
|
220
220
|
# Perform the actual request heavy lifting
|
221
|
-
def http_request(method, url, headers, data = nil) #:nodoc:
|
221
|
+
def http_request(method, url, headers, data = nil) #:nodoc:
|
222
222
|
url = URI.parse(url) if url.kind_of? String
|
223
223
|
|
224
224
|
connection = (url.scheme == 'https') ? Net::HTTPS.new(url.host, url.port) : Net::HTTP.new(url.host, url.port)
|
@@ -243,7 +243,7 @@ module Dewey
|
|
243
243
|
base = {}
|
244
244
|
base['GData-Version'] = '3.0'
|
245
245
|
base['Authorization'] = "GoogleLogin auth=#{authenticator.token(service)}"
|
246
|
-
|
246
|
+
|
247
247
|
base
|
248
248
|
end
|
249
249
|
|
data/lib/dewey/mime.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Dewey
|
2
|
-
|
2
|
+
|
3
3
|
DOCUMENT_MIMETYPES = {
|
4
|
-
:doc => 'application/msword',
|
5
|
-
:docx => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
4
|
+
:doc => ['application/msword', 'application/vnd.ms-office'],
|
5
|
+
:docx => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/x-docx', 'application/zip'],
|
6
6
|
:htm => 'text/html',
|
7
7
|
:html => 'text/html',
|
8
8
|
:odt => 'application/vnd.oasis.opendocument.text',
|
@@ -17,12 +17,12 @@ module Dewey
|
|
17
17
|
:png => 'image/png',
|
18
18
|
:svg => 'image/svg+xml'
|
19
19
|
}
|
20
|
-
|
20
|
+
|
21
21
|
PRESENTATION_MIMETYPES = {
|
22
22
|
:pps => 'application/vnd.ms-powerpoint',
|
23
23
|
:ppt => 'application/vnd.ms-powerpoint'
|
24
24
|
}
|
25
|
-
|
25
|
+
|
26
26
|
SPREADSHEET_MIMETYPES = {
|
27
27
|
:csv => 'text/csv',
|
28
28
|
:ods => 'application/x-vnd.oasis.opendocument.spreadsheet',
|
@@ -31,14 +31,24 @@ module Dewey
|
|
31
31
|
:xls => 'application/vnd.ms-excel',
|
32
32
|
:xlsx => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
33
33
|
}
|
34
|
-
|
34
|
+
|
35
35
|
class Mime
|
36
|
+
# Determine file extension by parsing the filename. When the filename has no extension,
|
37
|
+
# then instead examine the file's mime type and intuit the extension.
|
38
|
+
def self.extension(file)
|
39
|
+
extension = File.extname(file.path).sub('.', '')
|
40
|
+
if extension.nil? || extension == ''
|
41
|
+
mime_type = (`file --mime-type #{file.path}`).split(':').last.strip
|
42
|
+
extension = mime_type_to_extension_mapping[mime_type]
|
43
|
+
end
|
44
|
+
extension.to_s.downcase
|
45
|
+
end
|
46
|
+
|
36
47
|
# Attempts to provide a mime_type that Google Docs finds acceptable. Certain
|
37
48
|
# types, when gathered from +file+ require extra coercion and will be handled
|
38
49
|
# automatically.
|
39
50
|
def self.mime_type(file)
|
40
|
-
type = (file
|
41
|
-
case type
|
51
|
+
type = case extension(file)
|
42
52
|
when /csv/ then SPREADSHEET_MIMETYPES[:csv]
|
43
53
|
when /doc$/ then DOCUMENT_MIMETYPES[:doc]
|
44
54
|
when /docx/ then DOCUMENT_MIMETYPES[:docx]
|
@@ -58,31 +68,49 @@ module Dewey
|
|
58
68
|
when /txt/ then DOCUMENT_MIMETYPES[:txt]
|
59
69
|
when /xls$/ then SPREADSHEET_MIMETYPES[:xls]
|
60
70
|
when /xlsx/ then SPREADSHEET_MIMETYPES[:xlsx]
|
61
|
-
else
|
62
|
-
Mime.coerce((`file --mime-type #{file.path}`).split(':').last.strip) rescue "application/#{type}"
|
63
71
|
end
|
72
|
+
type.is_a?(Array) ? type.first : type
|
64
73
|
end
|
65
74
|
|
66
|
-
#
|
67
|
-
#
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
75
|
+
# Merges then inverts all the mime type constants to make a new hash with mime types as keys
|
76
|
+
# and the corresponding file extensions as values. For example this:
|
77
|
+
#
|
78
|
+
# :doc => ['application/msword', 'application/vnd.ms-office'],
|
79
|
+
#
|
80
|
+
# Becomes:
|
81
|
+
#
|
82
|
+
# 'application/msword' => :doc,
|
83
|
+
# 'application/vnd.ms-office' => :doc
|
84
|
+
#
|
85
|
+
# This is useful for intuiting file extensions based on mime types, which is handy when the
|
86
|
+
# filename doesn't have an extension (e.g. when doing post-processing with paperclip).
|
87
|
+
#
|
88
|
+
def self.mime_type_to_extension_mapping
|
89
|
+
doc_types = [DOCUMENT_MIMETYPES, DRAWING_MIMETYPES, PRESENTATION_MIMETYPES, SPREADSHEET_MIMETYPES]
|
90
|
+
extensions = {}
|
91
|
+
mime_types = {}
|
92
|
+
doc_types.each { |doc_type| extensions.merge!(doc_type) }
|
93
|
+
|
94
|
+
extensions.each do |extension, mime|
|
95
|
+
if mime.is_a?(Array)
|
96
|
+
mime.each { |m| mime_types[m] = extension }
|
97
|
+
else
|
98
|
+
mime_types[mime] = extension
|
99
|
+
end
|
73
100
|
end
|
101
|
+
mime_types
|
74
102
|
end
|
75
|
-
|
103
|
+
|
76
104
|
def self.guess_service(mime_type)
|
77
105
|
services = { :document => DOCUMENT_MIMETYPES,
|
78
106
|
:drawing => DRAWING_MIMETYPES,
|
79
107
|
:presentation => PRESENTATION_MIMETYPES,
|
80
108
|
:spreadsheet => SPREADSHEET_MIMETYPES }
|
81
|
-
|
109
|
+
|
82
110
|
services.each_key do |service|
|
83
|
-
return service if services[service].
|
111
|
+
return service if services[service].values.flatten.include?(mime_type)
|
84
112
|
end
|
85
|
-
|
113
|
+
|
86
114
|
nil
|
87
115
|
end
|
88
116
|
end
|
data/lib/dewey/validation.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Dewey
|
2
|
-
|
2
|
+
|
3
3
|
DOCUMENT_EXPORT_FORMATS = [:txt, :odt, :pdf, :html, :rtf, :doc, :png, :zip]
|
4
4
|
DRAWING_EXPORT_FORMATS = [:jpeg, :pdf, :png, :svg]
|
5
5
|
PRESENTATION_EXPORT_FORMATS = [:swf, :pdf, :png, :ppt]
|
6
6
|
SPREADSHEET_EXPORT_FORMATS = [:xls, :csv, :pdf, :ods, :tsv, :html]
|
7
|
-
|
7
|
+
|
8
8
|
# Utility methods to check that a format is accepted for a particular service
|
9
9
|
#
|
10
10
|
class Validation
|
11
|
-
|
11
|
+
|
12
12
|
class << self
|
13
13
|
# Determine wether or not a format is available for download.
|
14
14
|
#
|
@@ -44,7 +44,7 @@ module Dewey
|
|
44
44
|
# @raise [DeweyError] Raised when an unknown service is given
|
45
45
|
def valid_export_format?(format, service = nil)
|
46
46
|
format = format.to_sym
|
47
|
-
service = default_service(service)
|
47
|
+
service = default_service(service)
|
48
48
|
|
49
49
|
case service
|
50
50
|
when :document then Dewey::DOCUMENT_EXPORT_FORMATS.include?(format)
|
data/lib/dewey/version.rb
CHANGED
data/spec/client_auth_spec.rb
CHANGED
@@ -12,24 +12,24 @@ describe Dewey::ClientAuth do
|
|
12
12
|
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).
|
13
13
|
with(:body => 'accountType=HOSTED_OR_GOOGLE&Email=example&Passwd=password&service=writely').
|
14
14
|
to_return(:body => '=12345')
|
15
|
-
|
15
|
+
|
16
16
|
subject.authenticate!.should be_true
|
17
17
|
subject.authentications.should have_key(:writely)
|
18
18
|
|
19
19
|
WebMock.should have_requested(:post, Dewey::GOOGLE_LOGIN_URL).with(:body => /.*service=writely.*/)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "authenticates for wise" do
|
23
23
|
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).
|
24
24
|
with(:body => 'accountType=HOSTED_OR_GOOGLE&Email=example&Passwd=password&service=wise').
|
25
25
|
to_return(:body => '=12345')
|
26
|
-
|
26
|
+
|
27
27
|
subject.authenticate!(:wise)
|
28
28
|
subject.authentications.should have_key(:wise)
|
29
|
-
|
29
|
+
|
30
30
|
WebMock.should have_requested(:post, Dewey::GOOGLE_LOGIN_URL).with(:body => /.*service=wise.*/)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "returns false if authorization fails" do
|
34
34
|
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:status => 403)
|
35
35
|
|
@@ -48,11 +48,11 @@ describe Dewey::ClientAuth do
|
|
48
48
|
|
49
49
|
subject.authenticated?.should be_true
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "can scope authentication to writely" do
|
53
53
|
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
54
|
-
|
55
|
-
subject.authenticate!(:writely)
|
54
|
+
|
55
|
+
subject.authenticate!(:writely)
|
56
56
|
subject.authenticated?(:writely).should be_true
|
57
57
|
end
|
58
58
|
|
@@ -61,11 +61,11 @@ describe Dewey::ClientAuth do
|
|
61
61
|
subject.authenticate!(:wise)
|
62
62
|
subject.authenticated?(:wise).should be_true
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "provides authentication tokens" do
|
66
66
|
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
67
67
|
subject.authenticate!(:writely)
|
68
|
-
|
68
|
+
|
69
69
|
subject.token(:writely).should eq('12345')
|
70
70
|
end
|
71
71
|
|
@@ -81,6 +81,6 @@ describe Dewey::ClientAuth do
|
|
81
81
|
|
82
82
|
it "will correctly map spreadsheets to wise" do
|
83
83
|
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
84
|
-
subject.token('spreadsheets').should eq('12345')
|
84
|
+
subject.token('spreadsheets').should eq('12345')
|
85
85
|
end
|
86
86
|
end
|
data/spec/core/convert_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Dewey.convert" do
|
|
7
7
|
@txt = sample_file 'sample_document.txt'
|
8
8
|
@doc = sample_file 'sample_document.doc'
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "should put, get, and delete" do
|
12
12
|
Dewey.should_receive(:put).with(@txt, 'sample').and_return('document:12345')
|
13
13
|
Dewey.should_receive(:get).with('document:12345', :doc).and_return(@doc)
|
data/spec/core/get_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Dewey.get" do
|
3
|
+
describe "Dewey.get" do
|
4
4
|
before(:each) { stub_dewey_auth }
|
5
5
|
|
6
6
|
it "raises with an invalid format" do
|
@@ -28,14 +28,14 @@ describe "Dewey.get" do
|
|
28
28
|
it "downloads a document by id" do
|
29
29
|
stub_request(:get, "#{Dewey::GOOGLE_DOCUMENT_URL}?id=12345").
|
30
30
|
to_return(:body => sample_file('sample_document.txt'))
|
31
|
-
|
31
|
+
|
32
32
|
Dewey.get('document:12345').should_not be_nil
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "sets the export format when format is provided" do
|
36
36
|
stub_request(:get, "#{Dewey::GOOGLE_DOCUMENT_URL}?id=12345&exportFormat=doc&format=doc").
|
37
37
|
to_return(:body => sample_file('sample_document.doc'))
|
38
|
-
|
38
|
+
|
39
39
|
Dewey.get('document:12345', :format => :doc).should_not be_nil
|
40
40
|
end
|
41
41
|
|
@@ -53,7 +53,7 @@ describe "Dewey.get" do
|
|
53
53
|
|
54
54
|
Dewey.get('My Document').should_not be_nil
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "returns nil when the title can't be found" do
|
58
58
|
Dewey.should_receive(:search).with('My Document', { :exact => true }).and_return([])
|
59
59
|
|
@@ -77,7 +77,7 @@ describe "Dewey.get" do
|
|
77
77
|
it "is able to download a spreadsheet" do
|
78
78
|
stub_request(:get, "#{Dewey::GOOGLE_SPREADSHEET_URL}?key=12345").
|
79
79
|
to_return(:body => sample_file('sample_spreadsheet.csv'))
|
80
|
-
|
80
|
+
|
81
81
|
Dewey.get('spreadsheet:12345').should_not be_nil
|
82
82
|
end
|
83
83
|
|
@@ -91,7 +91,7 @@ describe "Dewey.get" do
|
|
91
91
|
it "should not download a full spreadsheet sheet" do
|
92
92
|
stub_request(:get, "#{Dewey::GOOGLE_SPREADSHEET_URL}?key=12345").
|
93
93
|
to_return(:body => sample_file('sample_spreadsheet.xls'))
|
94
|
-
|
94
|
+
|
95
95
|
Dewey.get('spreadsheet:12345', :sheet => 1).should_not be_nil
|
96
96
|
end
|
97
97
|
|
data/spec/core/put_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Dewey.put' do
|
4
4
|
before(:each) { stub_dewey_auth }
|
5
|
-
|
5
|
+
|
6
6
|
before(:all) do
|
7
7
|
@psd = sample_file 'sample_drawing.psd'
|
8
8
|
@txt = sample_file 'sample_document.txt'
|
@@ -17,7 +17,7 @@ describe 'Dewey.put' do
|
|
17
17
|
it "should raise when uploading unsupported file types" do
|
18
18
|
lambda { Dewey.put(@psd) }.should raise_exception(Dewey::DeweyError)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should raise when uploading a document with a bad mimetype" do
|
22
22
|
lambda { Dewey.put(@bad) }.should raise_exception(Dewey::DeweyError)
|
23
23
|
end
|
@@ -31,14 +31,14 @@ describe 'Dewey.put' do
|
|
31
31
|
it "get a resource id after putting a document" do
|
32
32
|
stub_request(:post, Dewey::GOOGLE_FEED_URL).
|
33
33
|
to_return(:status => 201, :body => "<feed><entry><id>https://docs.google.com/feeds/id/document:12345</id></entry></feed>")
|
34
|
-
|
34
|
+
|
35
35
|
Dewey.put(@txt).should eq('document:12345')
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "get a resource id after putting a spreadsheet" do
|
39
39
|
stub_request(:post, Dewey::GOOGLE_FEED_URL).
|
40
40
|
to_return(:status => 201, :body => "<feed><entry><id>https://docs.google.com/feeds/id/spreadsheet:12345</id></entry></feed>")
|
41
|
-
|
41
|
+
|
42
42
|
Dewey.put(@spr).should eq('spreadsheet:12345')
|
43
43
|
end
|
44
44
|
|
data/spec/core/search_spec.rb
CHANGED
@@ -6,21 +6,21 @@ describe "Dewey.search" do
|
|
6
6
|
it "can exactly match a single document" do
|
7
7
|
stub_request(:get, "#{Dewey::GOOGLE_FEED_URL}?title=HR+Handbook&title-exact=true").
|
8
8
|
to_return(:body => '<feed><id>https://docs.google.com/feeds/default/private/full</id><entry><id>document:12345</id></entry></feed>')
|
9
|
-
|
9
|
+
|
10
10
|
Dewey.search('HR Handbook', :exact => true).should eq(['document:12345'])
|
11
11
|
end
|
12
12
|
|
13
13
|
it "can partially match a single document" do
|
14
14
|
stub_request(:get, "#{Dewey::GOOGLE_FEED_URL}?title=Spec+101").
|
15
15
|
to_return(:body => '<feed><entry><id>document:12345</id></entry></feed>')
|
16
|
-
|
16
|
+
|
17
17
|
Dewey.search('Spec 101').should eq(['document:12345'])
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "can partially match multiple document" do
|
21
21
|
stub_request(:get, "#{Dewey::GOOGLE_FEED_URL}?title=notes").
|
22
22
|
to_return(:body => '<feed><entry><id>document:123</id></entry><entry><id>document:456</id></entry></feed>')
|
23
|
-
|
23
|
+
|
24
24
|
Dewey.search('notes').should eq(['document:123', 'document:456'])
|
25
25
|
end
|
26
26
|
end
|
data/spec/core_spec.rb
CHANGED
data/spec/mime_spec.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Dewey::Mime do
|
4
|
-
|
4
|
+
|
5
5
|
describe "Interpreting mime types from files" do
|
6
6
|
it "should provide the correct document mime type" do
|
7
7
|
@doc = sample_file 'sample_document.doc'
|
8
8
|
@pdf = sample_file 'sample_document.pdf'
|
9
9
|
@rtf = sample_file 'sample_document.rtf'
|
10
|
-
|
10
|
+
|
11
11
|
Dewey::Mime.mime_type(@doc).should eq('application/msword')
|
12
12
|
Dewey::Mime.mime_type(@pdf).should eq('application/pdf')
|
13
13
|
Dewey::Mime.mime_type(@rtf).should eq('application/rtf')
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "should provide the correct drawing mime type" do
|
17
17
|
@png = sample_file 'sample_drawing.png'
|
18
18
|
|
@@ -21,38 +21,55 @@ describe Dewey::Mime do
|
|
21
21
|
|
22
22
|
it "should provide the correct presentation mime type" do
|
23
23
|
@ppt = sample_file 'sample_presentation.ppt'
|
24
|
-
|
24
|
+
|
25
25
|
Dewey::Mime.mime_type(@ppt).should eq('application/vnd.ms-powerpoint')
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should provide the correct spreadsheet mime type" do
|
29
29
|
@xls = sample_file 'sample_spreadsheet.xls'
|
30
30
|
@csv = sample_file 'sample_spreadsheet.csv'
|
31
|
-
|
31
|
+
|
32
32
|
Dewey::Mime.mime_type(@xls).should eq('application/vnd.ms-excel')
|
33
33
|
Dewey::Mime.mime_type(@csv).should eq('text/csv')
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should coerce problematic mime types" do
|
37
37
|
@docx = sample_file 'sample_document.docx'
|
38
|
-
|
38
|
+
|
39
39
|
Dewey::Mime.mime_type(@docx).should eq('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should correctly guess from a file without an extension" do
|
43
43
|
@noext = sample_file 'sample_document'
|
44
|
-
|
44
|
+
|
45
45
|
Dewey::Mime.mime_type(@noext).should eq('application/msword')
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
|
-
describe "
|
48
|
+
|
49
|
+
describe "Determining file extesion from files" do
|
50
|
+
context "when the filename has an extension" do
|
51
|
+
it "should pull the extension off the filename" do
|
52
|
+
@docx = sample_file 'sample_document.docx'
|
53
|
+
|
54
|
+
Dewey::Mime.extension(@docx).should eq('docx')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
context "when the filename does not have an extension" do
|
58
|
+
it "should pull the extension off the filename" do
|
59
|
+
@docx = sample_file 'sample_document'
|
60
|
+
|
61
|
+
Dewey::Mime.extension(@docx).should eq('doc')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "Guessing the service from a mime type" do
|
50
67
|
it "should correctly guess service when given a known type" do
|
51
68
|
Dewey::Mime.guess_service('application/msword').should eq(:document)
|
52
69
|
Dewey::Mime.guess_service('application/vnd.ms-powerpoint').should eq(:presentation)
|
53
70
|
Dewey::Mime.guess_service('application/x-vnd.oasis.opendocument.spreadsheet').should eq(:spreadsheet)
|
54
71
|
end
|
55
|
-
|
72
|
+
|
56
73
|
it "should return nil for an unknown type" do
|
57
74
|
Dewey::Mime.guess_service('bad/example').should be_nil
|
58
75
|
end
|
data/spec/validation_spec.rb
CHANGED
metadata
CHANGED
@@ -1,72 +1,68 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dewey
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.9
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.8
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Parker Selbert
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-04-19 00:00:00 -05:00
|
12
|
+
date: 2011-10-02 00:00:00.000000000 -05:00
|
14
13
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
17
16
|
name: rake
|
18
|
-
requirement: &
|
17
|
+
requirement: &2156571360 !ruby/object:Gem::Requirement
|
19
18
|
none: false
|
20
|
-
requirements:
|
19
|
+
requirements:
|
21
20
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
21
|
+
- !ruby/object:Gem::Version
|
23
22
|
version: 0.8.7
|
24
23
|
type: :development
|
25
24
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
version_requirements: *2156571360
|
26
|
+
- !ruby/object:Gem::Dependency
|
28
27
|
name: rspec
|
29
|
-
requirement: &
|
28
|
+
requirement: &2156570320 !ruby/object:Gem::Requirement
|
30
29
|
none: false
|
31
|
-
requirements:
|
30
|
+
requirements:
|
32
31
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 2.
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.0
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: *2156570320
|
37
|
+
- !ruby/object:Gem::Dependency
|
39
38
|
name: webmock
|
40
|
-
requirement: &
|
39
|
+
requirement: &2156569560 !ruby/object:Gem::Requirement
|
41
40
|
none: false
|
42
|
-
requirements:
|
41
|
+
requirements:
|
43
42
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.7.6
|
46
45
|
type: :development
|
47
46
|
prerelease: false
|
48
|
-
version_requirements: *
|
49
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: *2156569560
|
48
|
+
- !ruby/object:Gem::Dependency
|
50
49
|
name: yard
|
51
|
-
requirement: &
|
50
|
+
requirement: &2156568900 !ruby/object:Gem::Requirement
|
52
51
|
none: false
|
53
|
-
requirements:
|
52
|
+
requirements:
|
54
53
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 0.
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.7.2
|
57
56
|
type: :development
|
58
57
|
prerelease: false
|
59
|
-
version_requirements: *
|
58
|
+
version_requirements: *2156568900
|
60
59
|
description: Light, simple Google Docs library for Ruby.
|
61
|
-
email:
|
60
|
+
email:
|
62
61
|
- parker@sorentwo.com
|
63
62
|
executables: []
|
64
|
-
|
65
63
|
extensions: []
|
66
|
-
|
67
64
|
extra_rdoc_files: []
|
68
|
-
|
69
|
-
files:
|
65
|
+
files:
|
70
66
|
- .gitignore
|
71
67
|
- .rspec
|
72
68
|
- CHANGELOG.md
|
@@ -111,36 +107,32 @@ files:
|
|
111
107
|
has_rdoc: true
|
112
108
|
homepage: http://github.com/sorentwo/dewey
|
113
109
|
licenses: []
|
114
|
-
|
115
110
|
post_install_message:
|
116
111
|
rdoc_options: []
|
117
|
-
|
118
|
-
require_paths:
|
112
|
+
require_paths:
|
119
113
|
- lib
|
120
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
115
|
none: false
|
122
|
-
requirements:
|
123
|
-
- -
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
|
126
|
-
segments:
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
127
121
|
- 0
|
128
|
-
|
129
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
hash: -1290362203853795856
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
124
|
none: false
|
131
|
-
requirements:
|
132
|
-
- -
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
|
135
|
-
segments:
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
segments:
|
136
130
|
- 0
|
137
|
-
|
131
|
+
hash: -1290362203853795856
|
138
132
|
requirements: []
|
139
|
-
|
140
133
|
rubyforge_project: dewey
|
141
134
|
rubygems_version: 1.6.2
|
142
135
|
signing_key:
|
143
136
|
specification_version: 3
|
144
137
|
summary: Simple Google Docs library.
|
145
138
|
test_files: []
|
146
|
-
|