slipsquare 0.0.1

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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.md +21 -0
  5. data/CONTRIBUTING.md +28 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.md +22 -0
  8. data/README.md +93 -0
  9. data/Rakefile +6 -0
  10. data/bin/slipsquare +7 -0
  11. data/lib/slipsquare.rb +6 -0
  12. data/lib/slipsquare/cli.rb +105 -0
  13. data/lib/slipsquare/config.rb +67 -0
  14. data/lib/slipsquare/middleware.rb +106 -0
  15. data/lib/slipsquare/middleware/account.rb +14 -0
  16. data/lib/slipsquare/middleware/ask_for_credentials.rb +39 -0
  17. data/lib/slipsquare/middleware/base.rb +28 -0
  18. data/lib/slipsquare/middleware/check_configuration.rb +18 -0
  19. data/lib/slipsquare/middleware/check_credentials.rb +27 -0
  20. data/lib/slipsquare/middleware/chunked_upload.rb +29 -0
  21. data/lib/slipsquare/middleware/delete_file.rb +13 -0
  22. data/lib/slipsquare/middleware/download_file.rb +25 -0
  23. data/lib/slipsquare/middleware/inject_client.rb +27 -0
  24. data/lib/slipsquare/middleware/inject_configuration.rb +15 -0
  25. data/lib/slipsquare/middleware/list_files.rb +19 -0
  26. data/lib/slipsquare/middleware/make_directory.rb +25 -0
  27. data/lib/slipsquare/middleware/upload_file.rb +17 -0
  28. data/lib/slipsquare/version.rb +3 -0
  29. data/slipsquare.gemspec +34 -0
  30. data/spec/cli/account.rb +24 -0
  31. data/spec/cli/authorize_spec.rb +46 -0
  32. data/spec/cli/chunked_upload_spec.rb +39 -0
  33. data/spec/cli/delete_file.rb +23 -0
  34. data/spec/cli/download_file.rb +43 -0
  35. data/spec/cli/get_keys_spec.rb +30 -0
  36. data/spec/cli/help_cli_spec.rb +17 -0
  37. data/spec/cli/ls_spec.rb +36 -0
  38. data/spec/cli/mkdir_spec.rb +52 -0
  39. data/spec/cli/upload_file.rb +33 -0
  40. data/spec/cli/verify_spec.rb +33 -0
  41. data/spec/cli/version_cli_spec.rb +16 -0
  42. data/spec/config_spec.rb +70 -0
  43. data/spec/fixtures/account.json +11 -0
  44. data/spec/fixtures/chunked_upload.json +5 -0
  45. data/spec/fixtures/commit_chunked_upload.json +13 -0
  46. data/spec/fixtures/find_foo_directory.json +15 -0
  47. data/spec/fixtures/ls_path_success.json +29 -0
  48. data/spec/fixtures/ls_success.json +14 -0
  49. data/spec/fixtures/mkdir_success.json +12 -0
  50. data/spec/fixtures/mkdir_success_multiple_path.json +12 -0
  51. data/spec/fixtures/upload_success.json +13 -0
  52. data/spec/fixtures/verify_success.json +14 -0
  53. data/spec/middleware/base_spec.rb +15 -0
  54. data/spec/middleware/check_configuration_spec.rb +16 -0
  55. data/spec/middleware/inject_configuration_spec.rb +16 -0
  56. data/spec/shared/environment.rb +49 -0
  57. data/spec/spec_helper.rb +20 -0
  58. data/tmp/.gitkeep +0 -0
  59. metadata +270 -0
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ describe "delete" do
7
+ it "deletes a folder" do
8
+
9
+ stub_request(:get, "https://api.dropbox.com/1/metadata/dropbox/foo?").
10
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'User-Agent'=>'OAuth gem v0.4.7'}).
11
+ to_return(:status => 200, :body => fixture('find_foo_directory'))
12
+
13
+ @cli.delete('foo')
14
+ expect($stdout.string).to eq <<-eos
15
+ Deleting file on Dropbox...
16
+ To be implemented...
17
+ eos
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ after :each do
7
+ File.delete("otacon.txt") if File.exist?("otacon.txt")
8
+ end
9
+
10
+ describe "download" do
11
+
12
+ it "downloads a simple text file" do
13
+
14
+ stub_request(:get, "https://api-content.dropbox.com/1/files/dropbox/otacon.txt?").
15
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'User-Agent'=>'OAuth gem v0.4.7'}).
16
+ to_return(:status => 200, :body => "Do you think love can bloom even on a battlefield?")
17
+
18
+ @cli.download('otacon.txt')
19
+ expect($stdout.string).to eq <<-eos
20
+ Download file...
21
+ File 'otacon.txt' downloaded successfully!
22
+ eos
23
+
24
+ File.read("otacon.txt").should eql "Do you think love can bloom even on a battlefield?"
25
+ end
26
+
27
+ it "outputs a message if file not found" do
28
+
29
+ stub_request(:get, "https://api-content.dropbox.com/1/files/dropbox/ghost.txt?").
30
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'User-Agent'=>'OAuth gem v0.4.7'}).
31
+ to_return(:status => 404)
32
+
33
+ expect { @cli.download('ghost.txt') }.to raise_error(SystemExit)
34
+ expect($stdout.string).to eq <<-eos
35
+ Download file...
36
+ File Not Found! Could not download
37
+ eos
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ describe "get-keys" do
7
+
8
+ before(:each) do
9
+ Time.stub!(:now).and_return('123456')
10
+ end
11
+
12
+ it "shows the keys helper text" do
13
+
14
+ @cli.options = @cli.options.merge(:get_keys => true)
15
+ @cli.get_keys
16
+
17
+ expect($stdout.string).to eq <<-eos
18
+ Please open this URL from your Browser, and login: https://www2.dropbox.com/developers/apps
19
+ Click \"Create app\" button, and choose the following options:
20
+ Type: Dropbox API app
21
+ Data: Files and Datastores
22
+ Permission type: Full Dropbox
23
+ File Types: All file types
24
+ App name: Slipsquare123456
25
+ Cick on the \"Create\" button, and note down the 'app key' and 'app secret'
26
+ eos
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ describe "help" do
7
+ it "shows a help message" do
8
+ @cli.help
9
+ expect($stdout.string).to match("Commands:")
10
+ end
11
+
12
+ it "shows a help message for specific commands" do
13
+ @cli.help "authorize"
14
+ expect($stdout.string).to match("Usage:")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ describe "ls called with no path" do
7
+ it "returns confirmation text when verify passes" do
8
+ stub_request(:get, "https://api.dropbox.com/1/metadata/dropbox/?").
9
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=> /OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'User-Agent'=>'OAuth gem v0.4.7'}).
10
+ to_return(:status => 200, :body => fixture("ls_success"))
11
+ @cli.ls
12
+ expect($stdout.string).to eq <<-eos
13
+ Listing files from Dropbox...
14
+ PATH | MIME_TYPE | SIZE
15
+ ------------------------------------------------
16
+ /Getting_Started.pdf | application/pdf | 225.4KB
17
+ eos
18
+ end
19
+
20
+ it "ls called with basic path" do
21
+ stub_request(:get, "https://api.dropbox.com/1/metadata/dropbox/awesome?").
22
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=> /OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'User-Agent'=>'OAuth gem v0.4.7'}).
23
+ to_return(:status => 200, :body => fixture("ls_path_success"))
24
+ @cli.ls('awesome')
25
+ expect($stdout.string).to eq <<-eos
26
+ Listing files from Dropbox...
27
+ PATH | MIME_TYPE | SIZE
28
+ ------------------------------------------
29
+ /Awesome/latest.txt | text/plain | 0 bytes
30
+ eos
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ describe "mkdir" do
7
+ it "creates the folder" do
8
+ stub_request(:post, "https://api.dropbox.com/1/fileops/create_folder").
9
+ with(
10
+ :body => {"path"=>"new_folder", "root"=>"dropbox"},
11
+ :headers => {'Accept'=>'*/*', 'Authorization'=> /OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'Content-Length'=>'0', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'OAuth gem v0.4.7'}).
12
+ to_return(:status => 200, :body => fixture("mkdir_success"))
13
+ @cli.mkdir('new_folder')
14
+ expect($stdout.string).to eq <<-eos
15
+ Creating directory on Dropbox...
16
+ Directory `new_folder` created successfully
17
+ eos
18
+ end
19
+
20
+ it "creates the folder within a folder" do
21
+ stub_request(:post, "https://api.dropbox.com/1/fileops/create_folder").
22
+ with(
23
+ :body => {"path"=>"/qux/foo/bar", "root"=>"dropbox"},
24
+ :headers => {'Accept'=>'*/*', 'Authorization'=> /OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'Content-Length'=>'0', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'OAuth gem v0.4.7'}).
25
+ to_return(:status => 200, :body => fixture("mkdir_success"))
26
+ @cli.mkdir('/qux/foo/bar')
27
+ expect($stdout.string).to eq <<-eos
28
+ Creating directory on Dropbox...
29
+ Directory `/qux/foo/bar` created successfully
30
+ eos
31
+ end
32
+
33
+ it "still creates folders with illegal characters" do
34
+ stub_request(:post, "https://api.dropbox.com/1/fileops/create_folder").
35
+ with(
36
+ :body => {"path"=>"new_folder", "root"=>"dropbox"},
37
+ :headers => {'Accept'=>'*/*', 'Authorization'=> /OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'Content-Length'=>'0', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'OAuth gem v0.4.7'}).
38
+ to_return(:status => 200, :body => fixture("mkdir_success"))
39
+ @cli.mkdir('\\\:\?\*\new_folder<\>\"\|')
40
+ expect($stdout.string).to eq <<-eos
41
+ Creating directory on Dropbox...
42
+ Illegal character found! Escaping...
43
+ Escaped directory path: new_folder
44
+ Directory `new_folder` created successfully
45
+ eos
46
+ end
47
+
48
+
49
+ end
50
+
51
+ end
52
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ before :each do
7
+ File.open("foo.txt", 'w') {|f| f.write("Laugh and grow fat...") }
8
+ end
9
+
10
+ after :each do
11
+ File.delete("foo.txt") if File.exist?("foo.txt")
12
+ end
13
+
14
+ describe "upload" do
15
+
16
+ it "uploads a simple text file" do
17
+
18
+ stub_request(:put, "https://api-content.dropbox.com/1/files_put/dropbox/foo.txt?").
19
+ with(:body => "Laugh and grow fat...",
20
+ :headers => {'Accept'=>'*/*', 'Authorization'=>/OAuth oauth_body_hash="\S+", oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'Content-Length'=>'21', 'Content-Type'=>'application/octet-stream', 'User-Agent'=>'OAuth gem v0.4.7'}).
21
+ to_return(:status => 200, :body => fixture('upload_success'))
22
+
23
+ @cli.upload('foo.txt')
24
+ expect($stdout.string).to eq <<-eos
25
+ Uploading file...
26
+ File 'foo.txt' uploaded successfully
27
+ eos
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ describe "verify" do
7
+ it "returns confirmation text when verify passes" do
8
+ stub_request(:get, "https://api.dropbox.com/1/metadata/dropbox/?").
9
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=> /OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'User-Agent'=>'OAuth gem v0.4.7'}).
10
+ to_return(:status => 200, :body => fixture("verify_success"))
11
+ @cli.verify
12
+ expect($stdout.string).to eq <<-eos
13
+ Checking credentials with Dropbox...
14
+ Connection to dropbox successful!
15
+ eos
16
+ end
17
+
18
+ it "returns error string when verify fails" do
19
+ stub_request(:get, "https://api.dropbox.com/1/metadata/dropbox/?").
20
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=> /OAuth oauth_consumer_key="#{app_key}", oauth_nonce="\S+", oauth_signature="\S+", oauth_signature_method="HMAC-SHA1", oauth_timestamp="\S+", oauth_token="#{app_token}", oauth_version="1.0"/, 'User-Agent'=>'OAuth gem v0.4.7'}).
21
+ to_return(:status => 401, :body => "", :headers => {})
22
+ expect { @cli.verify }.to raise_error(SystemExit)
23
+ expect($stdout.string).to eq <<-eos
24
+ Checking credentials with Dropbox...
25
+ Connection to Dropbox failed (401 - Bad or expired token)
26
+ Check your .slipsquare file, and double check your credentials are correct
27
+ eos
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::CLI do
4
+ include_context "spec"
5
+
6
+ describe "version" do
7
+ it "shows the correct version" do
8
+
9
+ @cli.options = @cli.options.merge(:version => true)
10
+ @cli.version
11
+
12
+ expect($stdout.string.chomp).to eq("Slipsquare #{Slipsquare::VERSION.to_s}")
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slipsquare::Configuration do
4
+ include_context "spec"
5
+
6
+ let(:tmp_path) { project_path + "/tmp/slipsquare" }
7
+
8
+ after :each do
9
+ # Clean up the temp file.
10
+ File.delete(project_path + "/tmp/slipsquare") if File.exist?(project_path + "/tmp/slipsquare")
11
+ end
12
+
13
+ it "is a singleton" do
14
+ expect(Slipsquare::Configuration).to be_a Class
15
+ expect do
16
+ Slipsquare::Configuration.new
17
+ end.to raise_error(NoMethodError, /private method `new' called/)
18
+ end
19
+
20
+ it "has a data attribute" do
21
+ config = Slipsquare::Configuration.instance
22
+ expect(config.data).to be
23
+ end
24
+
25
+ describe "the file" do
26
+ let(:app_key) { "foo" }
27
+ let(:secret_key) { "bar" }
28
+ let(:app_token) { "baz" }
29
+ let(:app_secret) { "blegga" }
30
+
31
+ let(:config) { config = Slipsquare::Configuration.instance }
32
+
33
+ before :each do
34
+ # Create a temporary file
35
+ config.create_config_file(app_key, secret_key, app_token, app_secret)
36
+ end
37
+
38
+ it "can be created" do
39
+ expect(File.exist?(tmp_path)).to be_true
40
+ end
41
+
42
+ it "can be loaded" do
43
+ data = config.load_config_file
44
+ expect(data).to_not be_nil
45
+ end
46
+
47
+ describe "the file format"
48
+ let(:data) { YAML.load_file(tmp_path) }
49
+
50
+ it "should have an app key" do
51
+ auth = data["authentication"]
52
+ expect(auth).to have_key("app_key")
53
+ end
54
+
55
+ it "should have a secret key" do
56
+ auth = data["authentication"]
57
+ expect(auth).to have_key("secret_key")
58
+ end
59
+
60
+ it "should have an app token" do
61
+ client = data["client"]
62
+ expect(client).to have_key("app_token")
63
+ end
64
+
65
+ it "should have an app secret" do
66
+ client = data["client"]
67
+ expect(client).to have_key("app_secret")
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ {
2
+ "referral_link": "https://www.dropbox.com/referrals/r1a2n3d4m5s6t7",
3
+ "display_name": "John P. User",
4
+ "uid": 12345678,
5
+ "country": "US",
6
+ "quota_info": {
7
+ "shared": 253738410565,
8
+ "quota": 107374182400000,
9
+ "normal": 680031877871
10
+ }
11
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "upload_id": "v0k84B0AT9fYkfMUp0sBTA",
3
+ "offset": 21,
4
+ "expires": "Tue, 19 Jul 2011 21:55:38 +0000"
5
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "size": "225.4KB",
3
+ "rev": "35e97029684fe",
4
+ "thumb_exists": false,
5
+ "bytes": 230783,
6
+ "modified": "Tue, 19 Jul 2011 21:55:38 +0000",
7
+ "path": "/foo.txt",
8
+ "is_dir": false,
9
+ "icon": "page_white_acrobat",
10
+ "root": "dropbox",
11
+ "mime_type": "application/pdf",
12
+ "revision": 220823
13
+ }
@@ -0,0 +1,15 @@
1
+ [
2
+ {
3
+ "size": "0 bytes",
4
+ "rev": "35c1f029684fe",
5
+ "thumb_exists": false,
6
+ "bytes": 0,
7
+ "modified": "Mon, 18 Jul 2011 20:13:43 +0000",
8
+ "path": "/Foo/",
9
+ "is_dir": false,
10
+ "icon": "page_white_text",
11
+ "root": "dropbox",
12
+ "mime_type": "text/plain",
13
+ "revision": 220191
14
+ }
15
+ ]
@@ -0,0 +1,29 @@
1
+ {
2
+ "size": "0 bytes",
3
+ "hash": "37eb1ba1849d4b0fb0b28caf7ef3af52",
4
+ "bytes": 0,
5
+ "thumb_exists": false,
6
+ "rev": "714f029684fe",
7
+ "modified": "Wed, 27 Apr 2011 22:18:51 +0000",
8
+ "path": "/Awesome",
9
+ "is_dir": true,
10
+ "icon": "folder_public",
11
+ "root": "dropbox",
12
+ "contents": [
13
+ {
14
+ "size": "0 bytes",
15
+ "rev": "35c1f029684fe",
16
+ "thumb_exists": false,
17
+ "bytes": 0,
18
+ "modified": "Mon, 18 Jul 2011 20:13:43 +0000",
19
+ "client_mtime": "Wed, 20 Apr 2011 16:20:19 +0000",
20
+ "path": "/Awesome/latest.txt",
21
+ "is_dir": false,
22
+ "icon": "page_white_text",
23
+ "root": "dropbox",
24
+ "mime_type": "text/plain",
25
+ "revision": 220191
26
+ }
27
+ ],
28
+ "revision": 29007
29
+ }