ochibako_share 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -0
- data/bin/ochibako-share +13 -27
- data/bin/ochibako-share-auth +27 -26
- data/lib/ochibako_share.rb +26 -0
- data/license.md +7 -0
- metadata +12 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2099c0f2a6738d13099afe4999d7c2973fed05
|
4
|
+
data.tar.gz: eae4f95ef55164a9fc5ce6f42af112deb7209f83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5de4c2c8787b42cd75b1b01503df43f4d5a4d49296b612831152286c51b99ce2f46b7367589524944962a3e9c5fe3c757374981cf2f61fc0a7110c50c5356cd1
|
7
|
+
data.tar.gz: 57d0ec70bc749a0d56747279e46882ba996c8e4a83da161ee477e76e1adcbef21d89f3241557121005f7e787f41d9774d09f76b931b3a624e765410abdb50a00
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# ochibako-share
|
2
|
+
A Ruby client software to upload files to your Dropbox and
|
3
|
+
obtain URL to share them.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
```
|
7
|
+
$ gem install ochibako_share
|
8
|
+
```
|
9
|
+
|
10
|
+
## Authentication
|
11
|
+
Follow https://www.dropbox.com/developers/core/start/ruby to
|
12
|
+
|
13
|
+
1. Register a new app on the [App Console](https://www.dropbox.com/developers/apps) - Dropbox API app/Need to store Files and datastores/Only needs access to files it creates. app name may include `ochibako-share`
|
14
|
+
2. Store the App key and App secret in `~/.ochibako-share-app` as shown below
|
15
|
+
3. Run `ochibako-share-auth` and follow the instruction to authenticate this application. This will create `~/.ochibako-share-auth`
|
16
|
+
|
17
|
+
`~/.ochibako-share-app`:
|
18
|
+
```
|
19
|
+
APP_KEY = 'INSERT_APP_KEY_HERE'
|
20
|
+
APP_SECRET = 'INSERT_APP_SECRET_HERE'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Upload
|
24
|
+
`$ ochibako-share <files>`
|
25
|
+
|
26
|
+
This shows URL(s) to be shared.
|
27
|
+
|
28
|
+
## License
|
29
|
+
[MIT](license.md)
|
data/bin/ochibako-share
CHANGED
@@ -1,36 +1,22 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# usage: ochibako-share <files-to-upload>
|
3
3
|
# This will upload your file into the App folder
|
4
|
-
require '
|
5
|
-
require 'net/http'
|
6
|
-
require 'uri'
|
4
|
+
require 'ochibako_share'
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
if __FILE__ == $0
|
7
|
+
include OchibakoShare
|
10
8
|
|
11
|
-
|
12
|
-
if Net::HTTPRedirection === res
|
13
|
-
return follow_url(res['location'], limit - 1)
|
14
|
-
else
|
15
|
-
return url
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def db_download_url(url)
|
20
|
-
url.sub(/\?dl=0\z/, '?dl=1')
|
21
|
-
end
|
22
|
-
|
23
|
-
access_token_file = File.expand_path('~/.ochibako-share-auth')
|
24
|
-
load access_token_file
|
9
|
+
load ACCESS_TOKEN_FILE
|
25
10
|
|
26
|
-
client = DropboxClient.new(ACCESS_TOKEN)
|
11
|
+
client = DropboxClient.new(ACCESS_TOKEN)
|
27
12
|
|
28
|
-
$stderr.puts "Uploading files to DropBox as #{client.account_info['email']}"
|
13
|
+
$stderr.puts "Uploading files to DropBox as #{client.account_info['email']}"
|
29
14
|
|
30
|
-
ARGV.each do |src|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
15
|
+
ARGV.each do |src|
|
16
|
+
$stderr.print "#{src} -> "
|
17
|
+
dst = File.basename(src)
|
18
|
+
result = client.put_file(dst, File.read(src))
|
19
|
+
shares = client.shares(dst)
|
20
|
+
$stderr.puts "\n" + db_download_url(follow_url(shares['url']))
|
21
|
+
end
|
36
22
|
end
|
data/bin/ochibako-share-auth
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# Run this file to authenticate this application on your Dropbox account
|
3
3
|
# https://www.dropbox.com/developers/core/start/ruby
|
4
|
-
require '
|
4
|
+
require 'ochibako_share'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
if __FILE__ == $0
|
7
|
+
include OchibakoShare
|
8
8
|
|
9
|
-
begin
|
10
|
-
|
11
|
-
rescue LoadError => err
|
12
|
-
|
13
|
-
|
14
|
-
end
|
9
|
+
begin
|
10
|
+
load APP_KEY_FILE
|
11
|
+
rescue LoadError => err
|
12
|
+
$stderr.puts "Create #{app_key_file} following README.md:\n#{err.message}"
|
13
|
+
exit 1
|
14
|
+
end
|
15
15
|
|
16
|
-
flow = DropboxOAuth2FlowNoRedirect.new(APP_KEY, APP_SECRET)
|
17
|
-
authorize_url = flow.start()
|
18
|
-
$stderr.puts 'Go to the following URL, Click "Allow", and Copy the authorization code.'
|
19
|
-
$stderr.puts authorize_url
|
20
|
-
$stderr.print 'Authorization code: '
|
21
|
-
code = gets.strip
|
16
|
+
flow = DropboxOAuth2FlowNoRedirect.new(APP_KEY, APP_SECRET)
|
17
|
+
authorize_url = flow.start()
|
18
|
+
$stderr.puts 'Go to the following URL, Click "Allow", and Copy the authorization code.'
|
19
|
+
$stderr.puts authorize_url
|
20
|
+
$stderr.print 'Authorization code: '
|
21
|
+
code = gets.strip
|
22
22
|
|
23
|
-
begin
|
24
|
-
|
25
|
-
rescue DropboxError => err
|
26
|
-
|
27
|
-
|
28
|
-
end
|
23
|
+
begin
|
24
|
+
access_token, user_id = flow.finish(code)
|
25
|
+
rescue DropboxError => err
|
26
|
+
$stderr.puts "Invalid authorization code: #{code.inspect}"
|
27
|
+
exit 1
|
28
|
+
end
|
29
29
|
|
30
|
-
File.open(
|
31
|
-
|
32
|
-
|
33
|
-
end
|
30
|
+
File.open(ACCESS_TOKEN_FILE, "w", 0600) do |f|
|
31
|
+
f.puts "#user_id: #{user_id}"
|
32
|
+
f.puts "ACCESS_TOKEN = #{access_token.dump}"
|
33
|
+
end
|
34
34
|
|
35
|
-
$stderr.puts "Access token is stored in: #{
|
35
|
+
$stderr.puts "Access token is stored in: #{ACCESS_TOKEN_FILE}"
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# ochibako_share
|
2
|
+
# A Ruby client software to upload files to your Dropbox and obtain URL
|
3
|
+
require 'dropbox_sdk'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module OchibakoShare
|
8
|
+
VERSION = '0.1.3'
|
9
|
+
APP_KEY_FILE = File.expand_path('~/.ochibako-share-app')
|
10
|
+
ACCESS_TOKEN_FILE = File.expand_path('~/.ochibako-share-auth')
|
11
|
+
|
12
|
+
def follow_url(url, limit = 8)
|
13
|
+
raise RuntimeError, "Too many HTTP redirects" if limit == 0
|
14
|
+
|
15
|
+
res = Net::HTTP.get_response(URI.parse(url))
|
16
|
+
if Net::HTTPRedirection === res
|
17
|
+
return follow_url(res['location'], limit - 1)
|
18
|
+
else
|
19
|
+
return url
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def db_download_url(url)
|
24
|
+
url.sub(/\?dl=0\z/, '?dl=1')
|
25
|
+
end
|
26
|
+
end
|
data/license.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2015 zunda <zundan@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ochibako_share
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zunda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dropbox-sdk
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: A Ruby CLI client to upload files to your Dropbox and obtain URL to share
|
@@ -31,8 +31,13 @@ executables:
|
|
31
31
|
- ochibako-share
|
32
32
|
- ochibako-share-auth
|
33
33
|
extensions: []
|
34
|
-
extra_rdoc_files:
|
34
|
+
extra_rdoc_files:
|
35
|
+
- README.md
|
36
|
+
- license.md
|
35
37
|
files:
|
38
|
+
- lib/ochibako_share.rb
|
39
|
+
- README.md
|
40
|
+
- license.md
|
36
41
|
- bin/ochibako-share
|
37
42
|
- bin/ochibako-share-auth
|
38
43
|
homepage: https://github.com/zunda/ochibako-share#readme
|
@@ -45,12 +50,12 @@ require_paths:
|
|
45
50
|
- lib
|
46
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
52
|
requirements:
|
48
|
-
- -
|
53
|
+
- - ">="
|
49
54
|
- !ruby/object:Gem::Version
|
50
55
|
version: '0'
|
51
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
57
|
requirements:
|
53
|
-
- -
|
58
|
+
- - ">="
|
54
59
|
- !ruby/object:Gem::Version
|
55
60
|
version: '0'
|
56
61
|
requirements: []
|