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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 807c9c7926c022c86b0923b935b7beddf1fae1f5
4
- data.tar.gz: 28977733d1e1c6dcf2181e26733655d536801e6f
3
+ metadata.gz: ea0b1fe4f638f066122fb058652d89453430b162
4
+ data.tar.gz: f8198ed274fc4aa6cea440069106719902773cb9
5
5
  SHA512:
6
- metadata.gz: ce8be2778cb15706eb8d6cfcd4a019fc4ec3c170f8404fde19c939198fb4d027fa6df05d0897c7e0a01a81b4617504bc712b55da3f0d37393cda13ee2980c624
7
- data.tar.gz: feb358e2ba6f5258005ea631caaf96d893081c02da3bcae422902cab32ace9d188fb4b0a32bdd63666a4a3fc52d2f3e2adc245dabcd83bf3e0331d7a09d786fe
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 or folders.
3
+ A simple Dropbox client to download files and folders.
4
4
 
5
5
  ## Installation
6
6
 
7
- $ gem install DropSync --pre
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
File without changes
@@ -5,22 +5,27 @@ module DropSync
5
5
  @client = DropboxClient.new(access_token)
6
6
  end
7
7
 
8
- def download(filename)
9
- puts "> Searching for #{filename}"
10
- url = get_url(filename)
11
- puts '> Downloading file'
12
- Mecha.automatic_download(filename, url)
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(filename)
19
- resp = @client.search('/', clean_up(filename))
20
- for item in resp
21
- path = item['path']
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
- @client.shares(path)['url']
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
@@ -4,21 +4,37 @@ require 'fileutils'
4
4
  module DropSync
5
5
  class Mecha
6
6
 
7
- def self.automatic_download(filename, url)
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
- FileUtils.mkdir(filename)
17
- FileUtils.cd(filename)
18
- system("curl -L -s -o #{download_path}/#{filename}/#{filename}.zip #{link}")
19
- system("unzip #{download_path}/#{filename}/#{filename}.zip > /dev/null 2>&1")
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
- system("rm #{filename}.zip")
37
+ FileUtils.rm_rf("#{filename}.zip")
22
38
  end
23
39
  end
24
- end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module DropSync
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
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.2
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-04-18 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler