dewey 0.2.7 → 0.2.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.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +6 -4
- data/autotest/discover.rb +1 -0
- data/dewey.gemspec +26 -0
- data/lib/dewey/core.rb +0 -1
- data/lib/dewey/version.rb +1 -1
- data/rakefile +28 -0
- data/spec/client_auth_spec.rb +86 -0
- data/spec/core/convert_spec.rb +17 -0
- data/spec/core/delete_spec.rb +55 -0
- data/spec/core/get_spec.rb +110 -0
- data/spec/core/put_spec.rb +71 -0
- data/spec/core/search_spec.rb +26 -0
- data/spec/core_spec.rb +10 -0
- data/spec/mime_spec.rb +60 -0
- data/spec/mock_files/bad_mimetype +0 -0
- data/spec/mock_files/sample_document +0 -0
- data/spec/mock_files/sample_document.doc +0 -0
- data/spec/mock_files/sample_document.docx +0 -0
- data/spec/mock_files/sample_document.pdf +0 -0
- data/spec/mock_files/sample_document.rtf +7 -0
- data/spec/mock_files/sample_document.txt +1 -0
- data/spec/mock_files/sample_drawing.png +0 -0
- data/spec/mock_files/sample_drawing.psd +0 -0
- data/spec/mock_files/sample_presentation.ppt +0 -0
- data/spec/mock_files/sample_spreadsheet.csv +45 -0
- data/spec/mock_files/sample_spreadsheet.xls +0 -0
- data/spec/session_token.txt +7 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/utils_spec.rb +23 -0
- data/spec/validation_spec.rb +45 -0
- metadata +72 -27
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2010 Parker Selbert
|
2
|
+
|
3
|
+
The MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
::::::::: :::::::::: ::: ::: :::::::::: ::: :::
|
2
|
-
:+: :+: :+: :+: :+: :+: :+: :+:
|
1
|
+
::::::::: :::::::::: ::: ::: :::::::::: ::: :::
|
2
|
+
:+: :+: :+: :+: :+: :+: :+: :+:
|
3
3
|
+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
|
4
4
|
+#+ +:+ +#++:++# +#+ +:+ +#+ +#++:++# +#++:
|
5
5
|
+#+ +#+ +#+ +#+ +#+#+ +#+ +#+ +#+
|
@@ -15,11 +15,13 @@ great document conversion services.
|
|
15
15
|
|
16
16
|
## Note
|
17
17
|
|
18
|
-
Dewey is
|
18
|
+
Dewey is written against the Google Document List Data API v3, which is prone
|
19
|
+
to changes without warning. Because of this I recommend you be careful when
|
20
|
+
using this in production.
|
19
21
|
|
20
22
|
## Authentication
|
21
23
|
|
22
|
-
You can configure Dewey to connect with ClientLogin.
|
24
|
+
You can configure Dewey to connect with ClientLogin.
|
23
25
|
|
24
26
|
ClientLogin
|
25
27
|
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { 'rspec2' }
|
data/dewey.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'dewey/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'dewey'
|
7
|
+
s.version = Dewey::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Parker Selbert']
|
10
|
+
s.email = ['parker@sorentwo.com']
|
11
|
+
s.homepage = %q{http://github.com/sorentwo/dewey}
|
12
|
+
s.summary = "Simple Google Docs library."
|
13
|
+
s.description = "Light, simple Google Docs library for Ruby."
|
14
|
+
|
15
|
+
s.rubyforge_project = 'dewey'
|
16
|
+
|
17
|
+
s.add_development_dependency 'rake', '~> 0.8.7'
|
18
|
+
s.add_development_dependency 'rspec', '~> 2.3.0'
|
19
|
+
s.add_development_dependency 'webmock', '~> 1.4.0'
|
20
|
+
s.add_development_dependency 'yard', '~> 0.6.8'
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ['lib']
|
26
|
+
end
|
data/lib/dewey/core.rb
CHANGED
data/lib/dewey/version.rb
CHANGED
data/rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding:utf-8
|
2
|
+
$:.unshift 'lib'
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
require 'rspec'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
desc "Run specs"
|
11
|
+
RSpec::Core::RakeTask.new do |t|
|
12
|
+
t.pattern = 'spec/*_spec.rb'
|
13
|
+
t.rspec_opts = %w(-fs --color)
|
14
|
+
end
|
15
|
+
task :spec
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'yard'
|
19
|
+
YARD::Rake::YardocTask.new do |t|
|
20
|
+
t.files = %w(lib/**/*.rb)
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
task :yard do
|
24
|
+
abort "YARD is not available. In order to run yard, you must: gem install yard"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => :spec
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dewey::ClientAuth do
|
4
|
+
|
5
|
+
subject { Dewey::ClientAuth.new('example', 'password') }
|
6
|
+
|
7
|
+
it "initializes unauthenticated" do
|
8
|
+
subject.authenticated?.should be_false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "authenticates for writely by default" do
|
12
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).
|
13
|
+
with(:body => 'accountType=HOSTED_OR_GOOGLE&Email=example&Passwd=password&service=writely').
|
14
|
+
to_return(:body => '=12345')
|
15
|
+
|
16
|
+
subject.authenticate!.should be_true
|
17
|
+
subject.authentications.should have_key(:writely)
|
18
|
+
|
19
|
+
WebMock.should have_requested(:post, Dewey::GOOGLE_LOGIN_URL).with(:body => /.*service=writely.*/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "authenticates for wise" do
|
23
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).
|
24
|
+
with(:body => 'accountType=HOSTED_OR_GOOGLE&Email=example&Passwd=password&service=wise').
|
25
|
+
to_return(:body => '=12345')
|
26
|
+
|
27
|
+
subject.authenticate!(:wise)
|
28
|
+
subject.authentications.should have_key(:wise)
|
29
|
+
|
30
|
+
WebMock.should have_requested(:post, Dewey::GOOGLE_LOGIN_URL).with(:body => /.*service=wise.*/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns false if authorization fails" do
|
34
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:status => 403)
|
35
|
+
|
36
|
+
subject.authenticate!.should be_false
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises when it gets a wacky response" do
|
40
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:status => 500)
|
41
|
+
|
42
|
+
lambda { subject.authenticate! }.should raise_exception(Dewey::DeweyError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "is authenticated with one service" do
|
46
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
47
|
+
subject.authenticate!
|
48
|
+
|
49
|
+
subject.authenticated?.should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can scope authentication to writely" do
|
53
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
54
|
+
|
55
|
+
subject.authenticate!(:writely)
|
56
|
+
subject.authenticated?(:writely).should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can scope authentication to wise" do
|
60
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
61
|
+
subject.authenticate!(:wise)
|
62
|
+
subject.authenticated?(:wise).should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "provides authentication tokens" do
|
66
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
67
|
+
subject.authenticate!(:writely)
|
68
|
+
|
69
|
+
subject.token(:writely).should eq('12345')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "authorizes automatically when a token is requested" do
|
73
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
74
|
+
subject.token(:wise).should eq('12345')
|
75
|
+
end
|
76
|
+
|
77
|
+
it "will correctly map documents to writely" do
|
78
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
79
|
+
subject.token('document').should eq('12345')
|
80
|
+
end
|
81
|
+
|
82
|
+
it "will correctly map spreadsheets to wise" do
|
83
|
+
stub_http_request(:post, Dewey::GOOGLE_LOGIN_URL).to_return(:body => '=12345')
|
84
|
+
subject.token('spreadsheets').should eq('12345')
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Dewey.convert" do
|
4
|
+
before(:each) do
|
5
|
+
stub_dewey_auth
|
6
|
+
|
7
|
+
@txt = sample_file 'sample_document.txt'
|
8
|
+
@doc = sample_file 'sample_document.doc'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should put, get, and delete" do
|
12
|
+
Dewey.should_receive(:put).with(@txt, 'sample').and_return('document:12345')
|
13
|
+
Dewey.should_receive(:get).with('document:12345', :doc).and_return(@doc)
|
14
|
+
Dewey.should_receive(:delete).with('document:12345').and_return(true)
|
15
|
+
Dewey.convert(@txt, :title => 'sample', :format => :doc).should be(@doc)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Dewey.delete" do
|
4
|
+
before(:each) { stub_dewey_auth }
|
5
|
+
|
6
|
+
it "deletes a resource from an id" do
|
7
|
+
stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true")
|
8
|
+
Dewey.delete('document:12345').should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "deletes a resource from a title" do
|
12
|
+
stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true")
|
13
|
+
Dewey.should_receive(:search).with('My Document', { :exact => true }).and_return(['document:12345'])
|
14
|
+
|
15
|
+
Dewey.delete('My Document').should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "uses If-Match in the header to ignore external modifications" do
|
19
|
+
stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true")
|
20
|
+
Dewey.delete('document:12345')
|
21
|
+
|
22
|
+
a_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true").
|
23
|
+
with(:headers => { 'If-Match' => '*' }).should have_been_made
|
24
|
+
end
|
25
|
+
|
26
|
+
it "reports false when a resource can't be found by id" do
|
27
|
+
stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true").to_return(:status => 300)
|
28
|
+
Dewey.delete('document:12345').should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "reports false when a resource can't be found by title" do
|
32
|
+
Dewey.should_receive(:search).with('Not My Document', { :exact => true }).and_return([])
|
33
|
+
|
34
|
+
Dewey.delete('Not My Document').should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "doesn't delete with the trash option" do
|
38
|
+
stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345")
|
39
|
+
Dewey.delete('document:12345', :trash => true).should be_true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Dewey.delete!" do
|
44
|
+
before(:each) { stub_dewey_auth }
|
45
|
+
|
46
|
+
it "raises an error when a resource can't be found" do
|
47
|
+
stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true").to_return(:status => 300)
|
48
|
+
lambda { Dewey.delete!('document:12345') }.should raise_exception(Dewey::DeweyError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "doesn't delete with the trash option" do
|
52
|
+
stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345")
|
53
|
+
Dewey.delete!('document:12345', :trash => true).should be_true
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Dewey.get" do
|
4
|
+
before(:each) { stub_dewey_auth }
|
5
|
+
|
6
|
+
it "raises with an invalid format" do
|
7
|
+
lambda { Dewey.get('document:12345', :format => :psd) }.should raise_exception(Dewey::DeweyError)
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'Returning' do
|
11
|
+
before do
|
12
|
+
stub_request(:get, /.*/).to_return(:body => sample_file('sample_document.txt'))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns a type of file" do
|
16
|
+
Dewey.get('document:12345').should be_kind_of(File)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the tempfile at position 0" do
|
20
|
+
Dewey.get('document:12345').pos.should be_zero
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns an exact copy of the body" do
|
24
|
+
Dewey.get('document:12345').read.should eq(sample_file('sample_document.txt').read)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "downloads a document by id" do
|
29
|
+
stub_request(:get, "#{Dewey::GOOGLE_DOCUMENT_URL}?id=12345").
|
30
|
+
to_return(:body => sample_file('sample_document.txt'))
|
31
|
+
|
32
|
+
Dewey.get('document:12345').should_not be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "sets the export format when format is provided" do
|
36
|
+
stub_request(:get, "#{Dewey::GOOGLE_DOCUMENT_URL}?id=12345&exportFormat=doc&format=doc").
|
37
|
+
to_return(:body => sample_file('sample_document.doc'))
|
38
|
+
|
39
|
+
Dewey.get('document:12345', :format => :doc).should_not be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns nil when the id can't be found" do
|
43
|
+
stub_request(:get, "#{Dewey::GOOGLE_DOCUMENT_URL}?id=12345").
|
44
|
+
to_return(:status => 301)
|
45
|
+
|
46
|
+
Dewey.get('document:12345').should be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "downloads a document by title" do
|
50
|
+
Dewey.should_receive(:search).with('My Document', { :exact => true }).and_return(['document:12345'])
|
51
|
+
stub_request(:get, "#{Dewey::GOOGLE_DOCUMENT_URL}?id=12345").
|
52
|
+
to_return(:body => sample_file('sample_document.doc'))
|
53
|
+
|
54
|
+
Dewey.get('My Document').should_not be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns nil when the title can't be found" do
|
58
|
+
Dewey.should_receive(:search).with('My Document', { :exact => true }).and_return([])
|
59
|
+
|
60
|
+
Dewey.get('My Document').should be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "is able to download a drawing" do
|
64
|
+
stub_request(:get, "#{Dewey::GOOGLE_DRAWING_URL}?id=12345").
|
65
|
+
to_return(:body => sample_file('sample_document.pdf'))
|
66
|
+
|
67
|
+
Dewey.get('drawing:12345').should_not be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "is able to download a presentation" do
|
71
|
+
stub_request(:get, "#{Dewey::GOOGLE_PRESENTATION_URL}?id=12345").
|
72
|
+
to_return(:body => sample_file('sample_document.pdf'))
|
73
|
+
|
74
|
+
Dewey.get('presentation:12345').should_not be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it "is able to download a spreadsheet" do
|
78
|
+
stub_request(:get, "#{Dewey::GOOGLE_SPREADSHEET_URL}?key=12345").
|
79
|
+
to_return(:body => sample_file('sample_spreadsheet.csv'))
|
80
|
+
|
81
|
+
Dewey.get('spreadsheet:12345').should_not be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should download a single spreadsheet format sheet" do
|
85
|
+
stub_request(:get, "#{Dewey::GOOGLE_SPREADSHEET_URL}?key=12345&exportFormat=csv&gid=1").
|
86
|
+
to_return(:body => sample_file('sample_spreadsheet.csv'))
|
87
|
+
|
88
|
+
Dewey.get('spreadsheet:12345', :format => :csv, :sheet => 1).should_not be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not download a full spreadsheet sheet" do
|
92
|
+
stub_request(:get, "#{Dewey::GOOGLE_SPREADSHEET_URL}?key=12345").
|
93
|
+
to_return(:body => sample_file('sample_spreadsheet.xls'))
|
94
|
+
|
95
|
+
Dewey.get('spreadsheet:12345', :sheet => 1).should_not be_nil
|
96
|
+
end
|
97
|
+
|
98
|
+
it "raises when using an unrecognized resourceID" do
|
99
|
+
lambda { Dewey.get('video:12345') }.should raise_exception(Dewey::DeweyError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'does not set the content type' do
|
103
|
+
stub_request(:get, /.*/).to_return(:body => sample_file('sample_document.txt'))
|
104
|
+
|
105
|
+
Dewey.get('document:12345')
|
106
|
+
|
107
|
+
a_request(:get, /.*/).
|
108
|
+
with(:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }).should_not have_been_made
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Dewey.put' do
|
4
|
+
before(:each) { stub_dewey_auth }
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@psd = sample_file 'sample_drawing.psd'
|
8
|
+
@txt = sample_file 'sample_document.txt'
|
9
|
+
@spr = sample_file 'sample_spreadsheet.xls'
|
10
|
+
@bad = sample_file 'bad_mimetype'
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
[@psd, @txt, @spr, @bad].map(&:close)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise when uploading unsupported file types" do
|
18
|
+
lambda { Dewey.put(@psd) }.should raise_exception(Dewey::DeweyError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise when uploading a document with a bad mimetype" do
|
22
|
+
lambda { Dewey.put(@bad) }.should raise_exception(Dewey::DeweyError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return nil on a failed request" do
|
26
|
+
stub_request(:post, Dewey::GOOGLE_FEED_URL).to_return(:status => 300)
|
27
|
+
|
28
|
+
Dewey.put(@txt).should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "get a resource id after putting a document" do
|
32
|
+
stub_request(:post, Dewey::GOOGLE_FEED_URL).
|
33
|
+
to_return(:status => 201, :body => "<feed><entry><id>https://docs.google.com/feeds/id/document:12345</id></entry></feed>")
|
34
|
+
|
35
|
+
Dewey.put(@txt).should eq('document:12345')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "get a resource id after putting a spreadsheet" do
|
39
|
+
stub_request(:post, Dewey::GOOGLE_FEED_URL).
|
40
|
+
to_return(:status => 201, :body => "<feed><entry><id>https://docs.google.com/feeds/id/spreadsheet:12345</id></entry></feed>")
|
41
|
+
|
42
|
+
Dewey.put(@spr).should eq('spreadsheet:12345')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "specifies an optional title in the header" do
|
46
|
+
stub_request(:post, Dewey::GOOGLE_FEED_URL)
|
47
|
+
Dewey.put(@txt, :title => 'Secret')
|
48
|
+
|
49
|
+
a_request(:post, Dewey::GOOGLE_FEED_URL).
|
50
|
+
with(:headers => { 'Slug' => 'Secret' }).should have_been_made
|
51
|
+
end
|
52
|
+
|
53
|
+
it "specifies the filesize in the header" do
|
54
|
+
stub_request(:post, Dewey::GOOGLE_FEED_URL)
|
55
|
+
|
56
|
+
Dewey.put(@txt)
|
57
|
+
|
58
|
+
a_request(:post, Dewey::GOOGLE_FEED_URL).
|
59
|
+
with(:headers => { 'Content-Length' => @txt.size }).should have_been_made
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "Dewey.put!" do
|
64
|
+
before(:each) { stub_dewey_auth }
|
65
|
+
|
66
|
+
it "raises an error on a failed request" do
|
67
|
+
txt = sample_file 'sample_document.txt'
|
68
|
+
stub_request(:post, Dewey::GOOGLE_FEED_URL).to_return(:status => 300)
|
69
|
+
lambda { Dewey.put!(txt) }.should raise_exception(Dewey::DeweyError)
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Dewey.search" do
|
4
|
+
before(:each) { stub_dewey_auth }
|
5
|
+
|
6
|
+
it "can exactly match a single document" do
|
7
|
+
stub_request(:get, "#{Dewey::GOOGLE_FEED_URL}?title=HR+Handbook&title-exact=true").
|
8
|
+
to_return(:body => '<feed><id>https://docs.google.com/feeds/default/private/full</id><entry><id>document:12345</id></entry></feed>')
|
9
|
+
|
10
|
+
Dewey.search('HR Handbook', :exact => true).should eq(['document:12345'])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can partially match a single document" do
|
14
|
+
stub_request(:get, "#{Dewey::GOOGLE_FEED_URL}?title=Spec+101").
|
15
|
+
to_return(:body => '<feed><entry><id>document:12345</id></entry></feed>')
|
16
|
+
|
17
|
+
Dewey.search('Spec 101').should eq(['document:12345'])
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can partially match multiple document" do
|
21
|
+
stub_request(:get, "#{Dewey::GOOGLE_FEED_URL}?title=notes").
|
22
|
+
to_return(:body => '<feed><entry><id>document:123</id></entry><entry><id>document:456</id></entry></feed>')
|
23
|
+
|
24
|
+
Dewey.search('notes').should eq(['document:123', 'document:456'])
|
25
|
+
end
|
26
|
+
end
|
data/spec/core_spec.rb
ADDED
data/spec/mime_spec.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dewey::Mime do
|
4
|
+
|
5
|
+
describe "Interpreting mime types from files" do
|
6
|
+
it "should provide the correct document mime type" do
|
7
|
+
@doc = sample_file 'sample_document.doc'
|
8
|
+
@pdf = sample_file 'sample_document.pdf'
|
9
|
+
@rtf = sample_file 'sample_document.rtf'
|
10
|
+
|
11
|
+
Dewey::Mime.mime_type(@doc).should eq('application/msword')
|
12
|
+
Dewey::Mime.mime_type(@pdf).should eq('application/pdf')
|
13
|
+
Dewey::Mime.mime_type(@rtf).should eq('application/rtf')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should provide the correct drawing mime type" do
|
17
|
+
@png = sample_file 'sample_drawing.png'
|
18
|
+
|
19
|
+
Dewey::Mime.mime_type(@png).should eq('image/png')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should provide the correct presentation mime type" do
|
23
|
+
@ppt = sample_file 'sample_presentation.ppt'
|
24
|
+
|
25
|
+
Dewey::Mime.mime_type(@ppt).should eq('application/vnd.ms-powerpoint')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should provide the correct spreadsheet mime type" do
|
29
|
+
@xls = sample_file 'sample_spreadsheet.xls'
|
30
|
+
@csv = sample_file 'sample_spreadsheet.csv'
|
31
|
+
|
32
|
+
Dewey::Mime.mime_type(@xls).should eq('application/vnd.ms-excel')
|
33
|
+
Dewey::Mime.mime_type(@csv).should eq('text/csv')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should coerce problematic mime types" do
|
37
|
+
@docx = sample_file 'sample_document.docx'
|
38
|
+
|
39
|
+
Dewey::Mime.mime_type(@docx).should eq('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should correctly guess from a file without an extension" do
|
43
|
+
@noext = sample_file 'sample_document'
|
44
|
+
|
45
|
+
Dewey::Mime.mime_type(@noext).should eq('application/msword')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Guessing the service from a mime type" do
|
50
|
+
it "should correctly guess service when given a known type" do
|
51
|
+
Dewey::Mime.guess_service('application/msword').should eq(:document)
|
52
|
+
Dewey::Mime.guess_service('application/vnd.ms-powerpoint').should eq(:presentation)
|
53
|
+
Dewey::Mime.guess_service('application/x-vnd.oasis.opendocument.spreadsheet').should eq(:spreadsheet)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return nil for an unknown type" do
|
57
|
+
Dewey::Mime.guess_service('bad/example').should be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf290
|
2
|
+
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
3
|
+
{\colortbl;\red255\green255\blue255;}
|
4
|
+
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
|
5
|
+
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
|
6
|
+
|
7
|
+
\f0\fs24 \cf0 This is a file full of random nothingness.}
|
@@ -0,0 +1 @@
|
|
1
|
+
This is a file full of random nothingness.
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
,,,,,,,,,,,,
|
2
|
+
,This,is,a,sample,spreadsheet.,,,,,,,
|
3
|
+
,,,,,,,,,,,,
|
4
|
+
,,,,,,,,,,,,
|
5
|
+
,,,,,,,,,,,,
|
6
|
+
,,,,,,,,,,,,
|
7
|
+
,,,,,,,,,,,,
|
8
|
+
,,,,,,,,,,,,
|
9
|
+
,,,,,,,,,,,,
|
10
|
+
,,,,,,,,,,,,
|
11
|
+
,,,,,,,,,,,,
|
12
|
+
,,,,,,,,,,,,
|
13
|
+
,,,,,,,,,,,,
|
14
|
+
,,,,,,,,,,,,
|
15
|
+
,,,,,,,,,,,,
|
16
|
+
,,,,,,,,,,,,
|
17
|
+
,,,,,,,,,,,,
|
18
|
+
,,,,,,,,,,,,
|
19
|
+
,,,,,,,,,,,,
|
20
|
+
,,,,,,,,,,,,
|
21
|
+
,,,,,,,,,,,,
|
22
|
+
,,,,,,,,,,,,
|
23
|
+
,,,,,,,,,,,,
|
24
|
+
,,,,,,,,,,,,
|
25
|
+
,,,,,,,,,,,,
|
26
|
+
,,,,,,,,,,,,
|
27
|
+
,,,,,,,,,,,,
|
28
|
+
,,,,,,,,,,,,
|
29
|
+
,,,,,,,,,,,,
|
30
|
+
,,,,,,,,,,,,
|
31
|
+
,,,,,,,,,,,,
|
32
|
+
,,,,,,,,,,,,
|
33
|
+
,,,,,,,,,,,,
|
34
|
+
,,,,,,,,,,,,
|
35
|
+
,,,,,,,,,,,,
|
36
|
+
,,,,,,,,,,,,
|
37
|
+
,,,,,,,,,,,,
|
38
|
+
,,,,,,,,,,,,
|
39
|
+
,,,,,,,,,,,,
|
40
|
+
,,,,,,,,,,,,
|
41
|
+
,,,,,,,,,,,,
|
42
|
+
,,,,,,,,,,,,
|
43
|
+
,,,,,,,,,,,,
|
44
|
+
,,,,,,,,,,,,
|
45
|
+
,,,,,,,,,,,,
|
Binary file
|
@@ -0,0 +1,7 @@
|
|
1
|
+
HTTP/1.0 200 OK
|
2
|
+
Server: GFE/1.3
|
3
|
+
Content-Type: text/plain
|
4
|
+
|
5
|
+
SID=DQAAAHYAAABY9SD8uAyL0luY6Vi0Fte50TmZP2BrTkJZIOHsoaXS5t-CuNsxnjkDVoyPaikWkGcr0GyB-PJB_HPHPVS3Y9oqPeWsB36oJwknYAI3Irt1vrppxN4e8_Gki-lK3bl-0HSeTAXfU9OnpKoWdBW4oPVkYcEgaanj-0O39kfa-MSecQ
|
6
|
+
LSID=DQAAAHcAAAAr5Fat8hQJqEKT8w31ajlMgHcwFk_p7ryzLkSeaOq2-fXURIuAB33GiZ2PbsZT25c5vMKElcF7YJS4wDlIvPjUvGef7C-sSqJTTEJ8dXDl9snLkpjl9m7-2z94iyPZ2jzDRZzSJpaAZu6H0G4l6oY1i97vIAw-g9wxBP4ZByvLbA
|
7
|
+
Auth=DQAAAHcAAAAr5Fat8hQJqEKT8w31ajlMgHcwFk_p7ryzLkSeaOq2-fXURIuAB33GiZ2PbsZT25ewrhsCefgeGhzeSkY6_MMhbi1PIt-MW14Mz3ZSZ6P1yWmqDhpz47w5SpvYA1CBslUVL6YUtrAR43TT1JvguDMqPBLaXDefQDZXZY0L-1d7kQ
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + '/../lib/dewey'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.include WebMock::API
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_dewey_auth
|
12
|
+
Dewey.stub_chain(:authenticator, :token).and_return('12345')
|
13
|
+
end
|
14
|
+
|
15
|
+
def sample_file(filename)
|
16
|
+
File.new(File.join(File.dirname(__FILE__), 'mock_files', filename))
|
17
|
+
end
|
data/spec/utils_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Dewey::Utils do
|
6
|
+
describe '#slug' do
|
7
|
+
it "should not replace spaces with '+'" do
|
8
|
+
Dewey::Utils.slug('this has spaces').should eq('this has spaces')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should ignore most printing characters" do
|
12
|
+
Dewey::Utils.slug(' !"#$').should eq(' !"#$')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should escape %" do
|
16
|
+
Dewey::Utils.slug('%').should eq('%25')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should percent encode foreign characters" do
|
20
|
+
Dewey::Utils.slug('ø').should eq('%C3')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dewey::Validation do
|
4
|
+
|
5
|
+
it "should return true for valid upload formats" do
|
6
|
+
Dewey::Validation.valid_upload_format?(:txt, :document).should be_true
|
7
|
+
Dewey::Validation.valid_upload_format?(:svg, :drawing).should be_true
|
8
|
+
Dewey::Validation.valid_upload_format?(:ppt, :presentation).should be_true
|
9
|
+
Dewey::Validation.valid_upload_format?(:csv, :spreadsheet).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return false for invalid upload formats" do
|
13
|
+
Dewey::Validation.valid_upload_format?(:png, :document).should_not be_true
|
14
|
+
Dewey::Validation.valid_upload_format?(:doc, :drawing).should_not be_true
|
15
|
+
Dewey::Validation.valid_upload_format?(:txt, :presentation).should_not be_true
|
16
|
+
Dewey::Validation.valid_upload_format?(:pdf, :spreadsheet).should_not be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should default to document" do
|
20
|
+
Dewey::Validation.valid_upload_format?(:txt).should be_true
|
21
|
+
Dewey::Validation.valid_upload_format?(:txt, nil).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise when given an invalid upload service" do
|
25
|
+
lambda { Dewey::Validation.valid_upload_format?(:ical, :cl) }.should raise_exception(Dewey::DeweyError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return true for valid export formats" do
|
29
|
+
Dewey::Validation.valid_export_format?(:txt, :document).should be_true
|
30
|
+
Dewey::Validation.valid_export_format?(:svg, :drawing).should be_true
|
31
|
+
Dewey::Validation.valid_export_format?(:pdf, :presentation).should be_true
|
32
|
+
Dewey::Validation.valid_export_format?(:csv, :spreadsheet).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return false for invalid export formats" do
|
36
|
+
Dewey::Validation.valid_export_format?(:jpg, :document).should be_false
|
37
|
+
Dewey::Validation.valid_export_format?(:txt, :drawing).should be_false
|
38
|
+
Dewey::Validation.valid_export_format?(:txt, :presentation).should be_false
|
39
|
+
Dewey::Validation.valid_export_format?(:txt, :spreadsheet).should be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise when given an invalid export service" do
|
43
|
+
lambda { Dewey::Validation.valid_export_format?(:ical, :cl) }.should raise_exception(Dewey::DeweyError)
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dewey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 7
|
9
|
-
version: 0.2.7
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.8
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Parker Selbert
|
@@ -14,35 +10,53 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-04-19 00:00:00 -05:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
-
prerelease: false
|
17
|
+
name: rake
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
19
|
none: false
|
25
20
|
requirements:
|
26
|
-
- -
|
21
|
+
- - ~>
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
version: "0"
|
23
|
+
version: 0.8.7
|
31
24
|
type: :development
|
25
|
+
prerelease: false
|
32
26
|
version_requirements: *id001
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
35
|
-
prerelease: false
|
28
|
+
name: rspec
|
36
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
30
|
none: false
|
38
31
|
requirements:
|
39
|
-
- -
|
32
|
+
- - ~>
|
40
33
|
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
- 0
|
43
|
-
version: "0"
|
34
|
+
version: 2.3.0
|
44
35
|
type: :development
|
36
|
+
prerelease: false
|
45
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: webmock
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.4.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: yard
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.6.8
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
46
60
|
description: Light, simple Google Docs library for Ruby.
|
47
61
|
email:
|
48
62
|
- parker@sorentwo.com
|
@@ -53,6 +67,15 @@ extensions: []
|
|
53
67
|
extra_rdoc_files: []
|
54
68
|
|
55
69
|
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- CHANGELOG.md
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE
|
75
|
+
- README.md
|
76
|
+
- autotest/discover.rb
|
77
|
+
- dewey.gemspec
|
78
|
+
- lib/dewey.rb
|
56
79
|
- lib/dewey/client_auth.rb
|
57
80
|
- lib/dewey/core.rb
|
58
81
|
- lib/dewey/https.rb
|
@@ -60,9 +83,31 @@ files:
|
|
60
83
|
- lib/dewey/utils.rb
|
61
84
|
- lib/dewey/validation.rb
|
62
85
|
- lib/dewey/version.rb
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
86
|
+
- rakefile
|
87
|
+
- spec/client_auth_spec.rb
|
88
|
+
- spec/core/convert_spec.rb
|
89
|
+
- spec/core/delete_spec.rb
|
90
|
+
- spec/core/get_spec.rb
|
91
|
+
- spec/core/put_spec.rb
|
92
|
+
- spec/core/search_spec.rb
|
93
|
+
- spec/core_spec.rb
|
94
|
+
- spec/mime_spec.rb
|
95
|
+
- spec/mock_files/bad_mimetype
|
96
|
+
- spec/mock_files/sample_document
|
97
|
+
- spec/mock_files/sample_document.doc
|
98
|
+
- spec/mock_files/sample_document.docx
|
99
|
+
- spec/mock_files/sample_document.pdf
|
100
|
+
- spec/mock_files/sample_document.rtf
|
101
|
+
- spec/mock_files/sample_document.txt
|
102
|
+
- spec/mock_files/sample_drawing.png
|
103
|
+
- spec/mock_files/sample_drawing.psd
|
104
|
+
- spec/mock_files/sample_presentation.ppt
|
105
|
+
- spec/mock_files/sample_spreadsheet.csv
|
106
|
+
- spec/mock_files/sample_spreadsheet.xls
|
107
|
+
- spec/session_token.txt
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/utils_spec.rb
|
110
|
+
- spec/validation_spec.rb
|
66
111
|
has_rdoc: true
|
67
112
|
homepage: http://github.com/sorentwo/dewey
|
68
113
|
licenses: []
|
@@ -77,6 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
122
|
requirements:
|
78
123
|
- - ">="
|
79
124
|
- !ruby/object:Gem::Version
|
125
|
+
hash: 3186217541912544096
|
80
126
|
segments:
|
81
127
|
- 0
|
82
128
|
version: "0"
|
@@ -85,15 +131,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
131
|
requirements:
|
86
132
|
- - ">="
|
87
133
|
- !ruby/object:Gem::Version
|
134
|
+
hash: 3186217541912544096
|
88
135
|
segments:
|
89
|
-
-
|
90
|
-
|
91
|
-
- 6
|
92
|
-
version: 1.3.6
|
136
|
+
- 0
|
137
|
+
version: "0"
|
93
138
|
requirements: []
|
94
139
|
|
95
140
|
rubyforge_project: dewey
|
96
|
-
rubygems_version: 1.
|
141
|
+
rubygems_version: 1.6.2
|
97
142
|
signing_key:
|
98
143
|
specification_version: 3
|
99
144
|
summary: Simple Google Docs library.
|