slipsquare 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a010880a46f5c654486ac768be01ea64fc53b4f8
4
+ data.tar.gz: 458574fa784b56fdc85af8b7e77961b3f43bc92b
5
+ SHA512:
6
+ metadata.gz: c09e12099dd70cbbae87f4c9e47951cb634ffddc24e22b030fec3d4591c6e3acc293124bfbf8e5b399922d43967ac418d6469b041b4aa64af338f75f6faa05da
7
+ data.tar.gz: 3bdad2880500f948fff5719ae17d7b915f3bffd667ff5e81657dac6717d467bbed3835cbda799324b9eb3cdedacd975161135432901fa01a92665a2384fac6b7
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *.gem
2
+ *.rbc
3
+ *~
4
+ *.swp
5
+ *.swo
6
+ .bundle
7
+ .rvmrc
8
+ Gemfile.lock
9
+ doc/*
10
+ log/*
11
+ pkg/*
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - 1.8.7
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: 1.8.7
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## 0.0.1 (Unreleased)
2
+
3
+ Initial release.
4
+
5
+ Current Commands:
6
+
7
+ * account
8
+ * authorize
9
+ * chunked-upload [PATH]
10
+ * download [FILENAME]
11
+ * get-keys
12
+ * help [COMMAND]
13
+ * ls
14
+ * mkdir [PATH]
15
+ * upload [PATH]
16
+ * verify
17
+ * version
18
+
19
+ Added but not implemented
20
+
21
+ * delete [PATH] - Need to figure out why it doesnt return a file object from the find command, which I can then call a delete on, I think I have some idea, but I want to release 0.0.1 before the weekend so I'll stub for now...
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,28 @@
1
+ # Contributing
2
+
3
+ 1. Fork it
4
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
5
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
6
+ 4. Push to the branch (`git push origin my-new-feature`)
7
+ 5. Create new Pull Request
8
+
9
+ ## Development Environment
10
+
11
+ To add a feature, fix a bug, or to run a development build of Slipsquare
12
+ on your machine, clone down the repo and run:
13
+
14
+ $ bundle
15
+
16
+ You can then execute slipsquare:
17
+
18
+ $ bundle exec slipsquare [command]
19
+
20
+ As well as run the tests:
21
+
22
+ $ bundle exec rspec
23
+
24
+ To install the gem on your system from source:
25
+
26
+ $ bundle exec rake install
27
+
28
+ If you need help with your environment, feel free to open an issue.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in slipsquare.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Peter Souter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # Slipsquare
2
+
3
+ A work-in-progress command line tool for uploading files to Dropbox, heavily inspired by tools such as
4
+ [Dropbox Uploader](https://github.com/andreafabrizi/Dropbox-Uploader) and [Tugboat](https://github.com/pearkes/tugboat)
5
+
6
+ ### Installation
7
+
8
+ gem install slipsquare
9
+
10
+ Note: Currently not on Rubygems yet...
11
+
12
+ ### Configuration
13
+
14
+ Run the configuration utility, `slipsquare authorize`.
15
+
16
+ ### Download a file
17
+
18
+ ```
19
+ $ slipsquare download miley_cyrus_dubstep.mp3
20
+ Downloading file...
21
+ File 'miley_cyrus_dubstep.mp3' downloaded successfully!
22
+ ```
23
+
24
+ ### Upload a file
25
+
26
+ ```
27
+ $ slipsquare upload secret_plans.doc
28
+ Uploading file...
29
+ File 'secret_plans.doc' uploaded successfully
30
+ ```
31
+
32
+ **Coming soon - Chunked uploads with progress bar!**
33
+
34
+ ### Delete a file
35
+
36
+ *To be implemented*
37
+
38
+ ```
39
+ $ slipsquare delete remove_me.tmp
40
+ Deleting file...
41
+ To be implemented...
42
+ ```
43
+
44
+ ### Create a directory
45
+
46
+ ```
47
+ $ slipsquare mkdir breaking_bad_episodes
48
+ Creating directory on Dropbox...
49
+ Directory `breaking_bad_episodes` created successfully
50
+ ```
51
+
52
+ ### List files on dropbox
53
+
54
+ #### All files/Root
55
+ ```
56
+ $ slipsquare ls
57
+ Listing files from Dropbox
58
+ PATH | MIME_TYPE | SIZE
59
+ -------------------------------|--------------------------|---------
60
+ /what_does_the_fox_say.mp3 | audio/mpeg | 7.6 MB
61
+ /photo_album.zip | application/zip | 83.7 MB
62
+ /Books | Method Missing | 0 bytes
63
+ /Camera Uploads | Method Missing | 0 bytes
64
+ /Comics | Method Missing | 0 bytes
65
+ /Music | Method Missing | 0 bytes
66
+ /Photos | Method Missing | 0 bytes
67
+ /Public | Method Missing | 0 bytes
68
+ ```
69
+
70
+ #### Particular Path
71
+ ```
72
+ $ slipsquare ls music
73
+ PATH | MIME_TYPE | SIZE
74
+ -------------------------------|------------|---------
75
+ /Music/01-paul_oakenfold_-_... | audio/mpeg | 183.9 MB
76
+ /Music/Big Bad Wolf (Dada L... | audio/mpeg | 12.5 MB
77
+ /Music/Drums Of Death - War... | audio/mpeg | 84.6 MB
78
+ /Music/Layo & Bushwacka! - ... | audio/mpeg | 78.8 MB
79
+ /Music/Lost Woods (Crizzly ... | audio/mpeg | 9.7 MB
80
+ /Music/The Glitch Mob -- We... | audio/mpeg | 12.6 MB
81
+ ```
82
+
83
+ ## Help
84
+
85
+ For a complete overview of all of the available commands, run:
86
+
87
+ $ slipsquare help
88
+
89
+ Feel free to open issues in case of bugs or improvments.
90
+
91
+ ## Contributing
92
+
93
+ See the [contributing guide](CONTRIBUTING.md). Pull-requests welcome!
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/slipsquare ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Signal.trap("INT") { exit 1 }
4
+
5
+ require "slipsquare"
6
+
7
+ Slipsquare::CLI.start(ARGV)
data/lib/slipsquare.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'slipsquare/cli'
2
+ require "slipsquare/config"
3
+ require "slipsquare/version"
4
+
5
+ module Slipsquare
6
+ end
@@ -0,0 +1,105 @@
1
+ require 'thor'
2
+
3
+ module Slipsquare
4
+ autoload :Middleware, "slipsquare/middleware"
5
+
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+ ENV['THOR_COLUMNS'] = '120'
9
+
10
+ !check_unknown_options
11
+
12
+ map "--version" => :version,
13
+ "-v" => :version
14
+
15
+ desc "help [COMMAND]", "Describe commands or a specific command"
16
+ def help(meth=nil)
17
+ super
18
+ if !meth
19
+ say "To learn more or to contribute, please see github.com/petems/slipsquare"
20
+ end
21
+ end
22
+
23
+ desc "authorize", "Authorize a Dropbox account with slipsquare"
24
+ long_desc "This takes you through a workflow for adding configuration
25
+ details to slipsquare."
26
+ def authorize
27
+ Middleware.sequence_authorize.call({})
28
+ end
29
+
30
+
31
+ desc "account", "Shows Dropbox account details"
32
+ long_desc "This displays your main Dropbox meta-data, such as
33
+ Display Name, County, Download Quota information and the like"
34
+ def account
35
+ Middleware.sequence_account.call({})
36
+ end
37
+
38
+ desc "download [FILENAME]", "Download a file or directory"
39
+ long_desc "Download or directory from dropbox"
40
+ def download(filename)
41
+ Middleware.sequence_download_file.call({"download_file_name" => filename})
42
+ end
43
+
44
+ desc "verify", "Check your given credentials are valid"
45
+ long_desc "This checks that the credentials in ~/.slipsquare are correct"
46
+ def verify
47
+ Middleware.sequence_verify.call({})
48
+ end
49
+
50
+ desc "ls", "Show files for a particular path"
51
+ method_option "path",
52
+ :type => :string,
53
+ :aliases => "-p",
54
+ :desc => "The path you want to give."
55
+ long_desc "This shows all the files of a given path (defaulting to root)"
56
+ def ls(path=nil)
57
+ Middleware.sequence_ls.call({"list_files_path" => path})
58
+ end
59
+
60
+ desc "mkdir [PATH]", "Make a directory on dropbox"
61
+ long_desc "This creates a directory on Dropbox, it allows you to enter
62
+ multiple directories and all will be created eg. `slipsquare mkdir photos/america/san_fran"
63
+ def mkdir(path)
64
+ Middleware.sequence_mkdir.call({"mkdir_path" => path})
65
+ end
66
+
67
+ desc "delete [PATH]", "Delete a directory or file on Dropbox"
68
+ long_desc "This creates a directory on Dropbox"
69
+ def delete(path)
70
+ Middleware.sequence_delete_file.call({"delete_path" => path})
71
+ end
72
+
73
+ desc "upload [PATH]", "Upload a file or directory"
74
+ long_desc "Upload a file or directory to dropbox"
75
+ def upload(filename)
76
+ Middleware.sequence_upload_file.call({"upload_file_name" => filename})
77
+ end
78
+
79
+ desc "chunked-upload [PATH]", "Chunk Upload a file or directory"
80
+ long_desc "Upload a file or directory to dropbox with chunks, typically
81
+ 4mb in size, allowing a way of showing progress of downloads."
82
+ def chunked_upload(filename)
83
+ Middleware.sequence_chunked_upload_file.call({"chunked_upload_file_name" => filename})
84
+ end
85
+
86
+ desc "get-keys", "Get your app and secret keys"
87
+ def get_keys
88
+ say "Please open this URL from your Browser, and login: https://www2.dropbox.com/developers/apps"
89
+ say "Click \"Create app\" button, and choose the following options:"
90
+ say "Type: Dropbox API app"
91
+ say "Data: Files and Datastores"
92
+ say "Permission type: Full Dropbox"
93
+ say "File Types: All file types"
94
+ say "App name: Slipsquare#{Time.now.to_i}"
95
+ say "Cick on the \"Create\" button, and note down the 'app key' and 'app secret'"
96
+ end
97
+
98
+ desc "version", "Show version"
99
+ def version
100
+ say "Slipsquare #{Slipsquare::VERSION}"
101
+ end
102
+
103
+ end
104
+ end
105
+
@@ -0,0 +1,67 @@
1
+ require 'singleton'
2
+
3
+ module Slipsquare
4
+ # This is the configuration object. It reads in configuration
5
+ # from a .slipsquare file located in the user's home directory
6
+
7
+ class Configuration
8
+ include Singleton
9
+ attr_reader :data
10
+ attr_reader :path
11
+
12
+ FILE_NAME = '.slipsquare'
13
+
14
+ def initialize
15
+ @path = ENV["SLIPSTREAM_CONFIG_PATH"] || File.join(File.expand_path("~"), FILE_NAME)
16
+ @data = self.load_config_file
17
+ end
18
+
19
+ # If we can't load the config file, self.data is nil, which we can
20
+ # check for in CheckConfiguration
21
+ def load_config_file
22
+ require 'yaml'
23
+ YAML.load_file(@path)
24
+ rescue Errno::ENOENT
25
+ return
26
+ end
27
+
28
+ def app_key
29
+ @data['authentication']['app_key']
30
+ end
31
+
32
+ def secret_key
33
+ @data['authentication']['secret_key']
34
+ end
35
+
36
+ def app_token
37
+ @data['client']['app_token']
38
+ end
39
+
40
+ def app_secret
41
+ @data['client']['app_secret']
42
+ end
43
+
44
+ # Re-runs initialize
45
+ def reset!
46
+ self.send(:initialize)
47
+ end
48
+
49
+ # Re-loads the config
50
+ def reload!
51
+ @data = self.load_config_file
52
+ end
53
+
54
+ # Writes a config file
55
+ def create_config_file(app_key, secret_key, app_token, app_secret)
56
+ require 'yaml'
57
+ File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |file|
58
+ data = {
59
+ "authentication" => { "app_key" => app_key, "secret_key" => secret_key },
60
+ "client" => { "app_token" => app_token, "app_secret" => app_secret }
61
+ }
62
+ file.write data.to_yaml
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,106 @@
1
+ require "middleware"
2
+
3
+ module Slipsquare
4
+ module Middleware
5
+ autoload :Base, "slipsquare/middleware/base"
6
+
7
+ autoload :AskForCredentials, "slipsquare/middleware/ask_for_credentials"
8
+ autoload :Account, "slipsquare/middleware/account"
9
+ autoload :CheckConfiguration, "slipsquare/middleware/check_configuration"
10
+ autoload :CheckCredentials, "slipsquare/middleware/check_credentials"
11
+ autoload :ChunkedUpload, "slipsquare/middleware/chunked_upload"
12
+ autoload :DeleteFile, "slipsquare/middleware/delete_file"
13
+ autoload :DownloadFile, "slipsquare/middleware/download_file"
14
+ autoload :InjectClient, "slipsquare/middleware/inject_client"
15
+ autoload :InjectConfiguration, "slipsquare/middleware/inject_configuration"
16
+ autoload :ListFiles, "slipsquare/middleware/list_files"
17
+ autoload :MakeDirectory, "slipsquare/middleware/make_directory"
18
+ autoload :UploadFile, "slipsquare/middleware/upload_file"
19
+
20
+ # Start the authorization flow.
21
+ # This writes a ~/.slipsquare file, which can be edited manually.
22
+ def self.sequence_authorize
23
+ ::Middleware::Builder.new do
24
+ use InjectConfiguration
25
+ use AskForCredentials
26
+ use InjectConfiguration
27
+ use CheckConfiguration
28
+ use InjectClient
29
+ use CheckCredentials
30
+ end
31
+ end
32
+
33
+ def self.sequence_account
34
+ ::Middleware::Builder.new do
35
+ use InjectConfiguration
36
+ use CheckConfiguration
37
+ use InjectClient
38
+ use Account
39
+ end
40
+ end
41
+
42
+ def self.sequence_verify
43
+ ::Middleware::Builder.new do
44
+ use InjectConfiguration
45
+ use CheckConfiguration
46
+ use InjectClient
47
+ use CheckCredentials
48
+ end
49
+ end
50
+
51
+ def self.sequence_ls
52
+ ::Middleware::Builder.new do
53
+ use InjectConfiguration
54
+ use CheckConfiguration
55
+ use InjectClient
56
+ use ListFiles
57
+ end
58
+ end
59
+
60
+ def self.sequence_mkdir
61
+ ::Middleware::Builder.new do
62
+ use InjectConfiguration
63
+ use CheckConfiguration
64
+ use InjectClient
65
+ use MakeDirectory
66
+ end
67
+ end
68
+
69
+ def self.sequence_upload_file
70
+ ::Middleware::Builder.new do
71
+ use InjectConfiguration
72
+ use CheckConfiguration
73
+ use InjectClient
74
+ use UploadFile
75
+ end
76
+ end
77
+
78
+ def self.sequence_download_file
79
+ ::Middleware::Builder.new do
80
+ use InjectConfiguration
81
+ use CheckConfiguration
82
+ use InjectClient
83
+ use DownloadFile
84
+ end
85
+ end
86
+
87
+ def self.sequence_delete_file
88
+ ::Middleware::Builder.new do
89
+ use InjectConfiguration
90
+ use CheckConfiguration
91
+ use InjectClient
92
+ use DeleteFile
93
+ end
94
+ end
95
+
96
+ def self.sequence_chunked_upload_file
97
+ ::Middleware::Builder.new do
98
+ use InjectConfiguration
99
+ use CheckConfiguration
100
+ use InjectClient
101
+ use ChunkedUpload
102
+ end
103
+ end
104
+
105
+ end
106
+ end