sendl 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 0.0.6
2
+
3
+ - Allow STDIN to be shared
4
+ - Documentation tweaks
1
5
 
2
6
  0.0.4
3
7
 
data/bin/sendcat CHANGED
@@ -60,19 +60,22 @@ Sending files with Sendcat
60
60
 
61
61
  The simplest way is sending one file:
62
62
 
63
- $ sendcat bob@dingo.com somefile
63
+ $ sendcat somefile
64
+ https://sendc.at/dl/Jqd2ICj5jqkKhpUxkqSJRJLpzRNRFhJUjGqBd6az1v0NEsWKIwIDtpf
65
+ somefile: 100% |========================| 377B 1.2KB/s ETA: 00:00:00
66
+ Files shared successfully (>'.'<)
64
67
 
65
- You can also send multiple files:
68
+ You can then grab the link and send it to someone. You can make it even easier by specifying an email address:
66
69
 
67
- $ sendcat bob@dingo.com somefile otherfile
70
+ $ sendcat somefile bob@dingo.com
68
71
 
69
- You can use wildcards, also order of arguments doesn't matter:
72
+ Sendcat will upload the file and send an email to bob@dingo.com with a link to download the file. You can also send multiple files and/or people at once:
70
73
 
71
- $ sendcat * bob@dingo.com
74
+ $ sendcat bob@dingo.com alice@bob.com somefile otherfile
72
75
 
73
- You can send to multiple people at once too
76
+ You can use wildcards, also order of arguments doesn't matter:
74
77
 
75
- $ sendcat file1 file2 bob@dingo.com alice@bob.com
78
+ $ sendcat * bob@dingo.com
76
79
 
77
80
  You can add a message:
78
81
 
@@ -86,6 +89,10 @@ Sendcat will dump the URL out to stdout, so to easily copy it to your clipboard
86
89
 
87
90
  $ sendcat file1 file2 bob@dingo.com alice@bob.com -m "Sendcat is awesome" | pbcopy
88
91
 
92
+ You don't need to specify an email address if you are going to handle the share link yourself:
93
+
94
+ $ sendcat somefile
95
+
89
96
  You can send files to anyone, they don't need an account at sendcat.com. The recipient will receive an email with download instructions for the file.
90
97
 
91
98
  EOS
@@ -106,13 +113,6 @@ recipients = ARGV.grep(email_regex)
106
113
  # copycat getopt behavior and modify ARGV
107
114
  recipients.each{|r| ARGV.delete(r)}
108
115
 
109
- # anything left in ARGV should be a file
110
- ARGV.each do |f|
111
- files << Sendl::File.new(f)
112
- end
113
-
114
- # debugging
115
-
116
116
  # should handle:
117
117
  # sendl sudara@alonetone.com file
118
118
  # sendl sudara@alonetone.com will@will_j.net file
@@ -120,11 +120,25 @@ end
120
120
  # sendl -t sudara@alonetone.com -t will@will_j.net -f file1 -f file2
121
121
  # sendl -t sudara@alonetone.com -t will@will_j.net file1 file2
122
122
 
123
- # puts recipients.inspect
124
- # puts files.inspect
125
-
126
123
  if not STDIN.tty?
127
- files << Sendl::File.new(STDIN)
124
+ # Buffer STDIN to a temp file.
125
+ stdin_tmpfile = Tempfile.new 'sendcat'
126
+
127
+ at_exit do
128
+ stdin_tmpfile.unlink
129
+ end
130
+
131
+ while data = STDIN.read(10_000)
132
+ stdin_tmpfile.write(data)
133
+ end
134
+ stdin_tmpfile.close
135
+
136
+ files << Sendl::File.new(stdin_tmpfile.path, (opts[:filename] || "STDIN"))
137
+ end
138
+
139
+ # anything left in ARGV should be a file
140
+ ARGV.each do |f|
141
+ files << Sendl::File.new(f)
128
142
  end
129
143
 
130
144
  if files.empty?
data/lib/sendl/file.rb CHANGED
@@ -1,14 +1,11 @@
1
1
  module Sendl
2
2
  class File
3
- attr_reader :filename
4
- attr_reader :size
3
+ attr_reader :filename, :size, :desired_name
5
4
 
6
- def initialize(name)
7
- @filename = name
8
- @size = ::File.size(name)
9
- end
10
-
11
- def upload!(share_id)
5
+ def initialize(file, override_name = nil)
6
+ @desired_name = ::File.basename(override_name || file)
7
+ @filename = file
8
+ @size = ::File.size(file)
12
9
  end
13
10
 
14
11
  def sha512
@@ -46,7 +46,9 @@ module Sendl
46
46
 
47
47
  def upload_file(f)
48
48
  debug("Uploading #{f.filename}")
49
+
49
50
  mime_type = MIME::Types.type_for(f.filename).first || 'application/octet-stream'
51
+
50
52
  debug("Determined MIME Type of #{mime_type}")
51
53
  debug("Uploading by sha")
52
54
  r = Curl::Easy.new(url_for("shares/#{@share_id}/share_files.json")) do |curl|
@@ -56,12 +58,14 @@ module Sendl
56
58
  file_share_id = parse_json(r.body_str)["share_file"]["id"]
57
59
 
58
60
  if r.response_code == 201
59
- STDERR.puts "#{::File.basename(f.filename)} was already uploaded, skipping"
61
+ STDERR.puts "#{::File.basename(f.desired_name)} was already uploaded, skipping"
60
62
  elsif r.response_code == 202
61
63
  debug("Server requests the full file contents")
62
- progress = ProgressBar.new(f.filename.split('/').last, f.size)
64
+
65
+ progress = ProgressBar.new(f.desired_name, f.size)
63
66
  progress.file_transfer_mode
64
67
  progress.bar_mark = "="
68
+
65
69
  r = Curl::Easy.new(url_for("shares/#{@share_id}/share_files/#{file_share_id}.json")) do |curl|
66
70
  curl.multipart_form_post = true
67
71
  curl.on_progress do |dl_total, dl_now, ul_total, ul_now| # callback
@@ -69,7 +73,7 @@ module Sendl
69
73
  progress.set(current)
70
74
  true
71
75
  end
72
- curl.http_post Curl::PostField.content("auth_token", api_key), Curl::PostField.content("_method", "PUT"), Curl::PostField.file("file_data[data]", f.filename)
76
+ curl.http_post Curl::PostField.content("auth_token", api_key), Curl::PostField.content("_method", "PUT"), Curl::PostField.file("file_data[data]", f.filename, f.desired_name)
73
77
  end
74
78
  STDERR.puts
75
79
  else
data/lib/sendl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sendl
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sendl
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Will Jessop
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-28 00:00:00 Z
13
+ date: 2011-05-13 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: getopt