fx4s 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/fx4s +11 -0
  2. data/bin/fx4s_secure +11 -0
  3. data/lib/fx4s.rb +81 -0
  4. metadata +114 -0
data/bin/fx4s ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby_noexec_wrapper
2
+
3
+ require 'fx4s'
4
+
5
+ fx4s = FX4S.new
6
+
7
+ if ARGV[0].nil?
8
+ fx4s.make_screenshot(false)
9
+ else
10
+ fx4s.share(ARGV[0], false)
11
+ end
data/bin/fx4s_secure ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby_noexec_wrapper
2
+
3
+ require 'fx4s'
4
+
5
+ fx4s = FX4S.new
6
+
7
+ if ARGV[0].nil?
8
+ fx4s.make_screenshot
9
+ else
10
+ fx4s.share(ARGV[0])
11
+ end
data/lib/fx4s.rb ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aws'
4
+ require 'clipboard'
5
+ require 'faraday'
6
+ require 'libnotify'
7
+ require 'time'
8
+ require 'yaml'
9
+
10
+ NON_GEM_DEPENDENCIES = ['xfce4-screenshooter',
11
+ 'xsel2',
12
+ 'xclip']
13
+
14
+ class FX4S
15
+ def initialize
16
+ check_dependencies
17
+ config_path = File.expand_path('~/.fx4s/fx4s.yml')
18
+ @config = YAML.load(File.read(config_path))
19
+
20
+ config_path = File.expand_path('~/.fx4s/aws.yml')
21
+ AWS.config(YAML.load(File.read(config_path)))
22
+ s3 = AWS::S3.new
23
+ @bucket = s3.buckets[@config[:bucket_name]]
24
+ end
25
+
26
+ def make_screenshot(secure=true)
27
+ `xfce4-screenshooter -r -o fx4s#{secure ? '_secure' : ''}`
28
+ end
29
+
30
+ def share(filepath, secure=true)
31
+ unless File.exists?(filepath)
32
+ notify("No such file: #{filepath}")
33
+ return false
34
+ end
35
+ url = upload(filepath, secure)
36
+ url = shorten_link(url)
37
+ set_clipboard(url)
38
+ end
39
+
40
+ private
41
+
42
+ def check_dependencies
43
+ NON_GEM_DEPENDENCIES.each do |executable|
44
+ if `which #{executable}`.empty?
45
+ notify("#{executable} not found")
46
+ exit 1
47
+ end
48
+ end
49
+ end
50
+
51
+ def notify(message)
52
+ Libnotify.show(:body => message, :summary => 'fx4s')
53
+ end
54
+
55
+ def shorten_link(link)
56
+ conn = Faraday.new(url: 'http://is.gd')
57
+ conn.get("create.php?format=simple&url=#{CGI::escape(link)}").body
58
+ end
59
+
60
+ def set_clipboard(data)
61
+ Clipboard.clear
62
+ Clipboard.copy(data)
63
+ notify(data)
64
+ end
65
+
66
+ def upload(filepath, secure=true)
67
+ notify('Uploading...')
68
+ name = Time.now.strftime('%Y%m%dT%H%M%S')
69
+ obj = @bucket.objects[name]
70
+ obj.write(file: filepath,
71
+ reduced_redundancy: true)
72
+ if secure
73
+ obj.url_for(:read,
74
+ expires: @config[:download_expiry]).to_s
75
+ else
76
+ obj.acl = :public_read
77
+ obj.public_url.to_s
78
+ end
79
+ end
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fx4s
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Piotr Sokolowski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: clipboard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: libnotify
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.0
78
+ description: Fast Xfce4 screenshot share
79
+ email: piotr.sokolowski@onet.pl
80
+ executables:
81
+ - fx4s
82
+ - fx4s_secure
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - lib/fx4s.rb
87
+ - bin/fx4s
88
+ - bin/fx4s_secure
89
+ homepage: http://rubygems.org/gems/FX4S
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.25
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Fast Xfce4 screenshot Share
113
+ test_files: []
114
+ has_rdoc: