DropSync 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/bin/dropsync +0 -0
- data/lib/dropsync/engine.rb +16 -15
- data/lib/dropsync/mecha.rb +23 -7
- data/lib/dropsync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea0b1fe4f638f066122fb058652d89453430b162
|
4
|
+
data.tar.gz: f8198ed274fc4aa6cea440069106719902773cb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ec176e4194616443a1ddf048c205de6155dfed7191522fafb4208bd69c8f5752a4b5be3d368229d19b4948f3f3e4e69ee175c079e2a0f5447b5f5187096a188
|
7
|
+
data.tar.gz: d076715e9aacf8e98588f7a6fb50bf986a24d8c542acd92656fa883cb6a1888a12b3fca113e3b3996ea65c1df2b7a076ff220bcdbca325ba3f49d264145ded5f
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# DropSync
|
2
2
|
|
3
|
-
A simple Dropbox client to download files
|
3
|
+
A simple Dropbox client to download files and folders.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
$ gem install DropSync
|
7
|
+
$ gem install DropSync
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
@@ -25,4 +25,4 @@ Bug reports and pull requests are welcome!
|
|
25
25
|
## Next steps
|
26
26
|
|
27
27
|
1) Error handling
|
28
|
-
2) Tests
|
28
|
+
2) Tests
|
data/bin/dropsync
CHANGED
File without changes
|
data/lib/dropsync/engine.rb
CHANGED
@@ -5,22 +5,27 @@ module DropSync
|
|
5
5
|
@client = DropboxClient.new(access_token)
|
6
6
|
end
|
7
7
|
|
8
|
-
def download(
|
9
|
-
puts "> Searching for #{
|
10
|
-
url = get_url(
|
11
|
-
puts
|
12
|
-
Mecha.automatic_download(
|
8
|
+
def download(path)
|
9
|
+
puts "> Searching for #{path}"
|
10
|
+
url = get_url(path)
|
11
|
+
puts "> Downloading file"
|
12
|
+
Mecha.automatic_download(path, url)
|
13
13
|
puts '> Download finished!'
|
14
14
|
logout
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
|
-
def get_url(
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def get_url(path)
|
19
|
+
filename = path.split('/').pop
|
20
|
+
resp = @client.search('/', filename)
|
21
|
+
|
22
|
+
for it in resp
|
23
|
+
if it['path'].downcase.include? path.downcase
|
24
|
+
item_path = it['path']
|
25
|
+
end
|
22
26
|
end
|
23
|
-
|
27
|
+
|
28
|
+
@client.shares(item_path)['url']
|
24
29
|
end
|
25
30
|
|
26
31
|
def logout
|
@@ -28,9 +33,5 @@ module DropSync
|
|
28
33
|
exit(0)
|
29
34
|
end
|
30
35
|
|
31
|
-
def clean_up(str)
|
32
|
-
return str.gsub(/^\/+/, '') if str
|
33
|
-
str
|
34
|
-
end
|
35
36
|
end
|
36
|
-
end
|
37
|
+
end
|
data/lib/dropsync/mecha.rb
CHANGED
@@ -4,21 +4,37 @@ require 'fileutils'
|
|
4
4
|
module DropSync
|
5
5
|
class Mecha
|
6
6
|
|
7
|
-
def self.automatic_download(
|
7
|
+
def self.automatic_download(path, url)
|
8
8
|
agent = Mechanize.new do |agent|
|
9
9
|
agent.user_agent_alias = 'Mac Safari'
|
10
10
|
end
|
11
11
|
|
12
|
+
# Gets download link
|
12
13
|
page = agent.get(url)
|
13
14
|
link = page.uri.to_s.gsub('dl=0', 'dl=1')
|
15
|
+
|
16
|
+
# Creates directory
|
14
17
|
download_path = "#{File.expand_path('~')}/Downloads"
|
15
18
|
FileUtils.cd(download_path)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
path.split('/').each do |d|
|
20
|
+
begin
|
21
|
+
FileUtils.mkdir(d)
|
22
|
+
rescue
|
23
|
+
puts "> Directory '#{d}' already exists"
|
24
|
+
FileUtils.rm_rf(d)
|
25
|
+
FileUtils.mkdir(d)
|
26
|
+
end
|
27
|
+
FileUtils.cd(d)
|
28
|
+
end
|
29
|
+
filename = path.split('/').pop
|
30
|
+
|
31
|
+
# Download
|
32
|
+
system("curl -L -s -o #{download_path}/#{path}/#{filename}.zip #{link}")
|
33
|
+
system("unzip #{download_path}/#{path}/#{filename}.zip > /dev/null 2>&1")
|
34
|
+
|
35
|
+
# Cleans directory
|
20
36
|
FileUtils.rm_rf("__MACOSX")
|
21
|
-
|
37
|
+
FileUtils.rm_rf("#{filename}.zip")
|
22
38
|
end
|
23
39
|
end
|
24
|
-
end
|
40
|
+
end
|
data/lib/dropsync/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: DropSync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Kair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|