surely 0.0.1 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/LICENSE +7 -0
- data/README.md +8 -14
- data/lib/surely/daemon.rb +5 -18
- data/lib/surely/uploader.rb +26 -11
- data/lib/surely/version.rb +1 -1
- data/lib/surely.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjA3MTFkMDliOGQxMTEyYTY5MmU3MTZmZmY5NWExMDY3MTgyZTdiNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWRjM2EzM2M2YTdiYjViMjI1YWQ5OWJkYjc0NWI0MmQ3MzJmZDQ0OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2YwYmM0NzYzNmRiNWI1ZjFiMGIyOTQ5MDZkOWVkZmRhY2FjNzg5YWMyOGY2
|
10
|
+
YTM4ODVjM2ZiOWNmOGVhNWQ1Y2E5OGU5ZTMzMmQ4NDE4ODRlYzlkM2I1MWQ0
|
11
|
+
ODNmNWVkOWQ5NWJlMjYyNTYyZmQ5OWU0NzE0ZDM5NThlMzI1NmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Mzg5MTNkMTUxZDMwNmI3N2M3MDU5YWQwNWU1MjFhM2RlYjBiNzE5ZGUzZGU5
|
14
|
+
ODczZTk0OGU2ZmU5ZDE0MDhhMjhiZGYwNmMyN2Y4OGNiYzI4YjlmMjgwMTRk
|
15
|
+
NTIxYTNiNzhkMjU2MGY3NDFkZmU1NWI4MDgyNTg1MDcxMmFmNTI=
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 Rémi Prévost
|
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.
|
data/README.md
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
# Surely
|
2
2
|
|
3
|
-
|
3
|
+
Surely watches your screenshots directory and upload new files to your [imgur](http://imgur.com/) account.
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
6
|
|
7
|
-
```
|
7
|
+
```bash
|
8
|
+
# Install the gem
|
8
9
|
$ gem install surely
|
9
|
-
$ cd surely
|
10
|
-
```
|
11
|
-
|
12
|
-
Configure it:
|
13
10
|
|
14
|
-
|
15
|
-
|
11
|
+
# Configure it (this sucks but that’ll do for now)
|
12
|
+
# Create an imgur application here: https://api.imgur.com/oauth2/addclient
|
16
13
|
export IMGUR_CLIENT_ID=…
|
17
14
|
export IMGUR_CLIENT_SECRET=…
|
18
|
-
```
|
19
|
-
|
20
|
-
Start the daemon:
|
21
15
|
|
22
|
-
|
23
|
-
$ surely
|
16
|
+
# Start the watcher
|
17
|
+
$ DIRECTORY=/path/to/screenshots surely
|
24
18
|
```
|
data/lib/surely/daemon.rb
CHANGED
@@ -4,25 +4,12 @@ module Surely
|
|
4
4
|
@uploader = Uploader.new(env)
|
5
5
|
@uploader.authorize!
|
6
6
|
|
7
|
-
callback = Proc.new do |modified, added, removed|
|
8
|
-
if added.any?
|
9
|
-
puts "Uploading..."
|
10
|
-
@uploader.refresh_token!
|
11
|
-
|
12
|
-
if uploaded_file = @uploader.upload_file(File.join(env['DIRECTORY'], added.first))
|
13
|
-
puts "Done uploading #{uploaded_file['link']}"
|
14
|
-
system "say -v 'Fred' 'Uploaded'"
|
15
|
-
system "echo #{uploaded_file['link']} | pbcopy"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
listener = Listen.to(env["DIRECTORY"])
|
21
|
-
listener.filter(/\.png$/)
|
22
|
-
listener.change(&callback)
|
23
|
-
|
24
7
|
begin
|
25
|
-
puts "Listening to changes on #{env[
|
8
|
+
puts "Listening to changes on #{env['DIRECTORY']}..."
|
9
|
+
|
10
|
+
listener = Listen.to(env['DIRECTORY'])
|
11
|
+
listener.filter(/\.png$/)
|
12
|
+
listener.change(&@uploader.callback)
|
26
13
|
listener.start!
|
27
14
|
ensure
|
28
15
|
exit
|
data/lib/surely/uploader.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Surely
|
2
2
|
class Uploader
|
3
3
|
def initialize(env)
|
4
|
-
@access_token = File.read("#{env['HOME']}/.surely_access_token") rescue nil
|
5
|
-
@refresh_token = File.read("#{env['HOME']}/.surely_refresh_token") rescue nil
|
4
|
+
@access_token = File.read("#{env['HOME']}/.surely_access_token").chomp rescue nil
|
5
|
+
@refresh_token = File.read("#{env['HOME']}/.surely_refresh_token").chomp rescue nil
|
6
6
|
|
7
|
-
@imgur = Faraday.new(:
|
7
|
+
@imgur = Faraday.new(url: 'https://api.imgur.com') do |c|
|
8
8
|
c.request :multipart
|
9
9
|
c.request :url_encoded
|
10
10
|
c.adapter :net_http
|
@@ -16,21 +16,21 @@ module Surely
|
|
16
16
|
def upload_file(file)
|
17
17
|
file = Faraday::UploadIO.new(file, 'image/png')
|
18
18
|
|
19
|
-
response = @imgur.post 'image' do |r|
|
19
|
+
response = @imgur.post '/3/image' do |r|
|
20
20
|
r.headers['Authorization'] = "Bearer #{@access_token}"
|
21
21
|
r.body = { image: file }
|
22
22
|
end
|
23
23
|
|
24
24
|
if response.success?
|
25
|
-
MultiJson.load(response.body)[
|
25
|
+
MultiJson.load(response.body)['data']
|
26
26
|
else
|
27
27
|
nil
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
def update_tokens(token_data)
|
32
|
-
@access_token = token_data[
|
33
|
-
@refresh_token = token_data[
|
32
|
+
@access_token = token_data['access_token']
|
33
|
+
@refresh_token = token_data['refresh_token']
|
34
34
|
File.open("#{@env['HOME']}/.surely_access_token", 'w') { |f| f << @access_token }
|
35
35
|
File.open("#{@env['HOME']}/.surely_refresh_token", 'w') { |f| f << @refresh_token }
|
36
36
|
end
|
@@ -38,15 +38,15 @@ module Surely
|
|
38
38
|
def authorize!
|
39
39
|
return true if @access_token && @refresh_token
|
40
40
|
system "open 'https://api.imgur.com/oauth2/authorize?client_id=#{@env['IMGUR_CLIENT_ID']}&response_type=token'"
|
41
|
-
print
|
41
|
+
print 'Enter your access_token: '
|
42
42
|
access_token = gets.chomp
|
43
|
-
print
|
43
|
+
print 'Enter your refresh_token: '
|
44
44
|
refresh_token = gets.chomp
|
45
|
-
update_tokens(
|
45
|
+
update_tokens('access_token' => access_token, 'refresh_token' => refresh_token)
|
46
46
|
end
|
47
47
|
|
48
48
|
def refresh_token!
|
49
|
-
response = @imgur.post 'oauth2/token' do |r|
|
49
|
+
response = @imgur.post '/oauth2/token' do |r|
|
50
50
|
r.body = {
|
51
51
|
refresh_token: @refresh_token,
|
52
52
|
client_id: @env['IMGUR_CLIENT_ID'],
|
@@ -62,5 +62,20 @@ module Surely
|
|
62
62
|
|
63
63
|
response
|
64
64
|
end
|
65
|
+
|
66
|
+
def callback
|
67
|
+
@callback ||= lambda do |modified, added, removed|
|
68
|
+
if added.any?
|
69
|
+
puts 'Uploading...'
|
70
|
+
refresh_token!
|
71
|
+
|
72
|
+
if uploaded_file = upload_file(File.join(@env['DIRECTORY'], added.first))
|
73
|
+
puts "Done uploading #{uploaded_file['link']}"
|
74
|
+
system "say -v 'Fred' 'Uploaded'"
|
75
|
+
system "echo #{uploaded_file['link']} | pbcopy"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
65
80
|
end
|
66
81
|
end
|
data/lib/surely/version.rb
CHANGED
data/lib/surely.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Prévost
|
@@ -91,6 +91,7 @@ extra_rdoc_files: []
|
|
91
91
|
files:
|
92
92
|
- .gitignore
|
93
93
|
- Gemfile
|
94
|
+
- LICENSE
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- bin/surely
|