dropbox-archive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 842319a02d6fd7c95cdc6f0b2e69ab74934b8bea
4
+ data.tar.gz: 0538226fd058d788f6be0574a3ad56bbd4045f1e
5
+ SHA512:
6
+ metadata.gz: 6a0fdbdca5365965b355f6bf06f0bcd94ca34d890ff5e3fc4e16c29c2443acad4f144f135be0e833d406e8b98f55a4d98a1f7616284a3cd35650cbae822fecba
7
+ data.tar.gz: 1771807b76b7170bc49f616816ee1a66fb2f8f2645ae8cf83b40e9e73a3de1e7cb70d329ba0e8dbc411cb8763ff2a54cc9ae0b17f4d61d023e4a949143b0eb22
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
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
+ - jruby-19mode
7
+ - rbx-19mode
8
+ - ruby-head
9
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dropbox-archive.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Josh McArthur
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,52 @@
1
+ # Dropbox::Archive
2
+
3
+ [![Build Status](https://travis-ci.org/joshmcarthur/dropbox-archive.png?branch=master)](https://travis-ci.org/joshmcarthur/dropbox-archive) [![Code Climate](https://codeclimate.com/github/joshmcarthur/dropbox-archive.png)](https://codeclimate.com/github/joshmcarthur/dropbox-archive)
4
+
5
+ Provides the ability to 'archive' files to your Dropbox account. By 'archive', I mean upload, and then remove from your hard drive, to make the most of your Dropbox storage AND your disk space.
6
+
7
+ ## Background
8
+
9
+ I have a Macbook Air, with 64gb of SSD space. While these specifications are fantastic for my everyday use, I do have some issues with keeping large files around, or large folders of files - the perfect example being photos from my camera. The idea with this gem is to provide the ability to perform a 'one-way sync' from a folder - uploading files, without requiring those files be kept locally.
10
+
11
+ This is similar to Dropbox's 'selective sync' option, but still provides the ability to upload files to the folder.
12
+
13
+
14
+ ## Installation
15
+
16
+ The gem should be installed where you can get to it outside of a gemset or otherwise, especially if you wish to run it as a background process.
17
+
18
+ If you are using system ruby or rbenv, then you should just be able to:
19
+
20
+ $ gem install dropbox-archive
21
+
22
+ If you are using RVM, then you may wish to use a wrapper:
23
+
24
+ $ rvm use default
25
+ $ gem install dropbox-archive
26
+ $ rvm wrapper default dropbox-archive --no-prefix
27
+
28
+
29
+ ## Configuration
30
+
31
+ At the moment, configuration is a four-step process - I'm hoping to streamline this process in the near future, as the configuration so far has been a bit build-as-you-go.
32
+
33
+ 1. Create a file in your home folder, called ".dropbox_archive"
34
+ 2. Go to the [Dropbox Developer Center](https://dropbox.com/developers/apps) and create an application for yourself. This is needed to perform OAuth login, which Dropbox requires for API authentication.
35
+ 3. Run `dropbox-archive setup` for a link to acquire an access token from Dropbox. When this process is complete, you should see a welcome message, with your name, and your access token will have been saved in your settings. If you see an error, lodge an issue, and I'll help you out.
36
+ 4. Open up your `~/.dropbox_archive` file, and add a setting called `directory` that has the full path of the directory you want to watch. When files are added to this directory, they will be uploaded to Dropbox and then deleted from your local filesystem.
37
+
38
+ Once the configuration is done once, it should just continue working as long as you need it to, but if you need to re-generate your access token, then just run `dropbox-archive setup` again. I do appreciate that configuration isn't too easy right now, and plan to integrate many of these steps into the `setup` command.
39
+
40
+
41
+ ## Usage
42
+
43
+ Simply run `dropbox-archive monitor` to begin monitoring the directory you configured in your settings file. Try creating a file in this directory - after a couple of seconds you should receive a notification that the file has been uploaded to Dropbox, and the file will have been removed from local storage.
44
+
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => [:test]
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'dropbox/archive'
5
+
6
+ Dropbox::Archive::CLI.start
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dropbox/archive/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dropbox-archive"
8
+ spec.version = Dropbox::Archive::VERSION
9
+ spec.authors = ["Josh McArthur"]
10
+ spec.email = ["joshua.mcarthur@gmail.com"]
11
+ spec.description = %q{Automatically upload files to dropbox and remove them from the local filesystem when they are added to a folder}
12
+ spec.summary = %q{Upload files to Dropbox and delete from local filesystem.}
13
+ spec.homepage = "https://github.com/joshmcarthur/dropbox-archive"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "mocha"
24
+ spec.add_dependency "dropbox-sdk"
25
+ spec.add_dependency "thor"
26
+ spec.add_dependency "listen"
27
+ end
@@ -0,0 +1,26 @@
1
+ require "dropbox/archive/version"
2
+ require "dropbox/archive/actions"
3
+ require "dropbox/archive/configuration"
4
+ require "dropbox/archive/authorization"
5
+ require "dropbox/archive/cli"
6
+ require "dropbox/archive/monitor"
7
+ require "dropbox_sdk"
8
+
9
+ module Dropbox
10
+ module Archive
11
+ extend Actions
12
+ class << self; attr_accessor :config_path; end
13
+
14
+ def self.config
15
+ @config ||= Configuration.new(self.config_path || "~/.dropbox_archive")
16
+ end
17
+
18
+ def self.client
19
+ if Dropbox::Archive.config.get('dropbox_access_token').nil?
20
+ raise "No access token configured! Please run dropbox-archive setup."
21
+ end
22
+
23
+ @client ||= ::DropboxClient.new(Dropbox::Archive.config.get('dropbox_access_token'))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ module Dropbox
2
+ module Archive
3
+ module Actions
4
+
5
+ def upload(path)
6
+ file = File.open(path)
7
+ Dropbox::Archive.client.put_file(File.basename(path), file)
8
+ return remove(file)
9
+ end
10
+
11
+ def remove(file)
12
+ FileUtils.rm(file)
13
+ return File.path(file)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'dropbox_sdk'
2
+
3
+ module Dropbox
4
+ module Archive
5
+ class Authorization
6
+
7
+ def initialize
8
+ DropboxOAuth2FlowNoRedirect.new(
9
+ Dropbox::Archive.config.get("dropbox_app_key"),
10
+ Dropbox::Archive.config.get("dropbox_app_secret")
11
+ ).tap do |flow|
12
+ authorize_url = flow.start
13
+
14
+ puts "Please authorize this application at: #{authorize_url}"
15
+ puts "Enter authorization code:"
16
+ authorization_code = $stdin.gets.chomp
17
+
18
+ access_token, user_id = flow.finish(authorization_code)
19
+ Dropbox::Archive.config.set("dropbox_access_token", access_token)
20
+ end
21
+
22
+ puts "Welcome, #{Dropbox::Archive.client.account_info['display_name']}!"
23
+ Dropbox::Archive.client
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'thor'
2
+
3
+ class Dropbox::Archive::CLI < Thor
4
+ desc "setup", "setup client"
5
+ def setup
6
+ Dropbox::Archive::Authorization.new
7
+ end
8
+
9
+ desc "monitor", "start monitoring folder"
10
+ def monitor
11
+ Dropbox::Archive::Monitor.new
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ module Dropbox
2
+ module Archive
3
+ class Configuration
4
+
5
+ attr_accessor :config_path, :config_cache
6
+
7
+ def initialize(config_path)
8
+ @config_path = config_path
9
+ end
10
+
11
+ def get(key)
12
+ load
13
+ config_cache[key]
14
+ end
15
+
16
+ def set(key, value)
17
+ load
18
+ config_cache[key] = value
19
+ save
20
+ value
21
+ end
22
+
23
+ private
24
+
25
+ def load
26
+ if !File.exists?(File.expand_path(config_path))
27
+ FileUtils.touch(File.expand_path(config_path))
28
+ end
29
+
30
+ self.config_cache = YAML.load_file(File.expand_path(config_path)) || {}
31
+ end
32
+
33
+ def save
34
+ load unless config_cache
35
+ File.open(File.expand_path(config_path), 'wb') do |f|
36
+ f.write config_cache.to_yaml
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ require 'listen'
2
+
3
+ module Dropbox
4
+ module Archive
5
+ class Monitor
6
+ def initialize
7
+ listener = Listen.to(Dropbox::Archive.config.get('directory')) do |modified, added, removed|
8
+ added.each { |path| Dropbox::Archive.upload(path) }
9
+ modified.each { |path| Dropbox::Archive.upload(path) }
10
+ end
11
+
12
+ listener.start
13
+ sleep
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Dropbox
2
+ module Archive
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class ActionsTest < Test::Unit::TestCase
4
+ def setup
5
+ @test_file_path = File.join(File.dirname(__FILE__), 'fixtures', 'test.txt')
6
+ add_test_file!
7
+ setup_config!
8
+
9
+ @test_file = File.open(@test_file_path)
10
+ end
11
+
12
+ def test_upload_file
13
+ Dropbox::Archive.client
14
+ .expects(:put_file)
15
+ .with("test.txt", instance_of(File))
16
+
17
+ assert_equal @test_file_path,
18
+ Dropbox::Archive.upload(@test_file)
19
+ end
20
+
21
+ def test_remove_file
22
+ assert File.exists?(@test_file_path)
23
+
24
+
25
+ end
26
+
27
+ def add_test_file!
28
+ FileUtils.touch(@test_file_path)
29
+ end
30
+
31
+ def setup_config!
32
+ @filepath = File.join(File.dirname(__FILE__), 'fixtures', 'test_config.yml')
33
+ Dropbox::Archive.config_path = @filepath
34
+ Dropbox::Archive.config
35
+ end
36
+ end
data/test/cli_test.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "test_helper"
2
+
3
+ class CLITest < Test::Unit::TestCase
4
+
5
+ def test_setup_invokes_authorization
6
+ Dropbox::Archive::Authorization.expects(:new)
7
+ Dropbox::Archive::CLI.new.setup
8
+ end
9
+
10
+ def test_monitor_invokes_monitor
11
+ Dropbox::Archive::Monitor.expects(:new)
12
+ Dropbox::Archive::CLI.new.monitor
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require "test_helper"
2
+
3
+ class ConfigurationTest < Test::Unit::TestCase
4
+ def setup
5
+ @filepath = File.join(File.dirname(__FILE__), 'test.yml')
6
+ @configuration = Dropbox::Archive::Configuration.new(@filepath)
7
+ end
8
+
9
+ def teardown
10
+ FileUtils.rm(@filepath)
11
+ end
12
+
13
+ def test_set_key
14
+ @configuration.set("test", "key")
15
+ assert_equal File.read(@filepath), "---\ntest: key\n"
16
+ end
17
+
18
+ def test_get_key
19
+ File.open(@filepath, 'w') { |f| f.write "---\ntest: key\n" }
20
+ assert_equal @configuration.get("test"), "key"
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class DropboxArchiveTest < Test::Unit::TestCase
4
+ def setup
5
+ setup_config!
6
+ end
7
+
8
+ def test_load_config
9
+ config = Dropbox::Archive.config
10
+ assert_not_nil config.get('directory')
11
+ assert_equal config, Dropbox::Archive.config
12
+ end
13
+
14
+ def test_client_access_token_not_present
15
+ Dropbox::Archive.config.stubs(get: nil)
16
+ assert_raise RuntimeError do
17
+ Dropbox::Archive.client
18
+ end
19
+ end
20
+
21
+ def test_client_instantiated
22
+ DropboxClient.expects(:new)
23
+ # Make sure client has not already been set,
24
+ # since the value is cached
25
+ Dropbox::Archive.instance_variable_set("@client", nil)
26
+ Dropbox::Archive.client
27
+ end
28
+
29
+ private
30
+
31
+ def setup_config!
32
+ @filepath = File.join(File.dirname(__FILE__), 'fixtures', 'test_config.yml')
33
+ Dropbox::Archive.config_path = @filepath
34
+ end
35
+
36
+ end
@@ -0,0 +1,5 @@
1
+ ---
2
+ dropbox_app_key: test
3
+ dropbox_app_secret: test
4
+ dropbox_access_token: test
5
+ directory: test/fixtures/sync_test
File without changes
@@ -0,0 +1,6 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ require "dropbox/archive"
5
+ require "test/unit"
6
+ require "mocha/setup"
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ class VersionTest < Test::Unit::TestCase
4
+ def test_version_defined
5
+ assert_not_nil Dropbox::Archive::VERSION
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dropbox-archive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh McArthur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dropbox-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: listen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Automatically upload files to dropbox and remove them from the local
98
+ filesystem when they are added to a folder
99
+ email:
100
+ - joshua.mcarthur@gmail.com
101
+ executables:
102
+ - dropbox-archive
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - .gitignore
107
+ - .travis.yml
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/dropbox-archive
113
+ - dropbox-archive.gemspec
114
+ - lib/dropbox/archive.rb
115
+ - lib/dropbox/archive/actions.rb
116
+ - lib/dropbox/archive/authorization.rb
117
+ - lib/dropbox/archive/cli.rb
118
+ - lib/dropbox/archive/configuration.rb
119
+ - lib/dropbox/archive/monitor.rb
120
+ - lib/dropbox/archive/version.rb
121
+ - test/actions_test.rb
122
+ - test/cli_test.rb
123
+ - test/configuration_test.rb
124
+ - test/dropbox_archive_test.rb
125
+ - test/fixtures/test_config.yml
126
+ - test/monitor_test.rb
127
+ - test/test_helper.rb
128
+ - test/version_test.rb
129
+ homepage: https://github.com/joshmcarthur/dropbox-archive
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.0.3
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Upload files to Dropbox and delete from local filesystem.
153
+ test_files:
154
+ - test/actions_test.rb
155
+ - test/cli_test.rb
156
+ - test/configuration_test.rb
157
+ - test/dropbox_archive_test.rb
158
+ - test/fixtures/test_config.yml
159
+ - test/monitor_test.rb
160
+ - test/test_helper.rb
161
+ - test/version_test.rb