sendl 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 0.0.4
3
+
4
+ - Dump out share URL on stdout as soon as it is created.
5
+
6
+ 0.0.3
7
+
8
+ - Bail if no files were shared
data/bin/sendcat CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: UTF-8
2
3
 
3
- # require 'bundler'
4
- # Bundler.setup
4
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
5
 
6
6
  require 'sendl'
7
+ require 'sendl/version'
7
8
  require 'trollop'
8
9
  require 'yajl'
9
10
  require 'yaml'
@@ -48,6 +49,46 @@ email_regex = /^#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}$/i
48
49
  opts = Trollop::options do
49
50
  opt :message, "Message to the recipients", :allow_blank => true, :default => ""
50
51
  opt :debug, "Dump debug output"
52
+ version "sendcat #{Sendl::VERSION}"
53
+ banner <<-EOS
54
+
55
+ ==================== (>'.'<) ====================
56
+
57
+ Sending files with Sendcat
58
+
59
+ ==================== (>'.'<) ====================
60
+
61
+ The simplest way is sending one file:
62
+
63
+ $ sendcat bob@dingo.com somefile
64
+
65
+ You can also send multiple files:
66
+
67
+ $ sendcat bob@dingo.com somefile otherfile
68
+
69
+ You can use wildcards, also order of arguments doesn't matter:
70
+
71
+ $ sendcat * bob@dingo.com
72
+
73
+ You can send to multiple people at once too
74
+
75
+ $ sendcat file1 file2 bob@dingo.com alice@bob.com
76
+
77
+ You can add a message:
78
+
79
+ $ sendcat file1 file2 bob@dingo.com alice@bob.com -m # Launches your editor
80
+
81
+ or…
82
+
83
+ $ sendcat file1 file2 bob@dingo.com alice@bob.com -m "Sendcat is awesome"
84
+
85
+ Sendcat will dump the URL out to stdout, so to easily copy it to your clipboard use:
86
+
87
+ $ sendcat file1 file2 bob@dingo.com alice@bob.com -m "Sendcat is awesome" | pbcopy
88
+
89
+ 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
+
91
+ EOS
51
92
  end
52
93
 
53
94
  if opts[:message].nil?
@@ -82,20 +123,29 @@ end
82
123
  # puts recipients.inspect
83
124
  # puts files.inspect
84
125
 
85
-
86
126
  if not STDIN.tty?
87
127
  files << Sendl::File.new(STDIN)
88
128
  end
89
129
 
130
+ if files.empty?
131
+ STDERR.puts "Uh-oh, you didn't specify any files to share!"
132
+ exit(1)
133
+ end
134
+
90
135
  s = Sendl::Uploader.new(:api_key => ENV['API_KEY'] || YAML::load_file("#{ENV['HOME']}/.sendcat")[:api_key], :recipients => recipients, :message => message, :debug => opts[:debug])
91
136
 
137
+ puts s.share_url
138
+
139
+ if not STDOUT.tty?
140
+ STDERR.puts "A link to your share was send to stdout, looks like you took care of that."
141
+ end
142
+
92
143
  s.upload(files)
93
144
 
94
145
  if s.success?
95
- puts
96
- puts "Files shared successfully (>'.'<)"
146
+ STDERR.puts "Files shared successfully (>'.'<)"
97
147
  else
98
- puts "There were errors uploading:"
99
- puts s.errors.join("\n")
148
+ STDERR.puts "There were errors uploading:"
149
+ STDERR.puts s.errors.join("\n")
100
150
  exit 1
101
151
  end
@@ -1,7 +1,7 @@
1
1
  module Sendl
2
2
  class Uploader
3
3
 
4
- attr_accessor :endpoint, :api_key, :success, :errors, :recipients, :json_parser, :message
4
+ attr_accessor :endpoint, :api_key, :success, :errors, :recipients, :json_parser, :message, :share_url
5
5
 
6
6
  def initialize(options)
7
7
  argument_errors = []
@@ -16,15 +16,14 @@ module Sendl
16
16
  @success = false
17
17
  @errors = []
18
18
  @share_id = nil
19
+ @share_id = get_share_id
19
20
  end
20
21
 
21
22
  def debug(msg)
22
- @debug && puts(msg)
23
+ @debug && STDERR.puts(msg)
23
24
  end
24
25
 
25
26
  def upload(files, options = {})
26
- @share_id = get_share_id
27
-
28
27
  files.each do |f|
29
28
  upload_file(f)
30
29
  end
@@ -57,7 +56,7 @@ module Sendl
57
56
  file_share_id = parse_json(r.body_str)["share_file"]["id"]
58
57
 
59
58
  if r.response_code == 201
60
- puts "#{::File.basename(f.filename)} was already uploaded, skipping"
59
+ STDERR.puts "#{::File.basename(f.filename)} was already uploaded, skipping"
61
60
  elsif r.response_code == 202
62
61
  debug("Server requests the full file contents")
63
62
  progress = ProgressBar.new(f.filename.split('/').last, f.size)
@@ -72,7 +71,7 @@ module Sendl
72
71
  end
73
72
  curl.http_post Curl::PostField.content("auth_token", api_key), Curl::PostField.content("_method", "PUT"), Curl::PostField.file("file_data[data]", f.filename)
74
73
  end
75
- puts
74
+ STDERR.puts
76
75
  else
77
76
  @errors << "Could not create share_file, response was #{r.response_code}"
78
77
  end
@@ -84,11 +83,13 @@ module Sendl
84
83
  end
85
84
 
86
85
  if r.response_code != 201
87
- @errors << "Could not create share, response was #{r.response_code}"
88
- return false
86
+ STDERR.puts "Could not create share, HTTP response was #{r.response_code} (expected 201)"
87
+ exit 1
89
88
  end
90
-
91
- @share_id = parse_json(r.body_str)["share"]["id"]
89
+
90
+ share = parse_json(r.body_str)
91
+ @share_url = share["url"]
92
+ @share_id = share["share"]["id"]
92
93
  end
93
94
 
94
95
  # FIXME: de-duplicate
data/lib/sendl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sendl
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendl
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 3
9
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.0.5
10
6
  platform: ruby
11
7
  authors:
12
8
  - Will Jessop
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-04-15 00:00:00 +01:00
18
- default_executable:
13
+ date: 2011-04-28 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: getopt
@@ -25,10 +20,6 @@ dependencies:
25
20
  requirements:
26
21
  - - ~>
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 4
31
- - 0
32
23
  version: 1.4.0
33
24
  type: :runtime
34
25
  version_requirements: *id001
@@ -40,10 +31,6 @@ dependencies:
40
31
  requirements:
41
32
  - - ~>
42
33
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 8
46
- - 1
47
34
  version: 0.8.1
48
35
  type: :runtime
49
36
  version_requirements: *id002
@@ -55,10 +42,6 @@ dependencies:
55
42
  requirements:
56
43
  - - ~>
57
44
  - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 7
61
- - 15
62
45
  version: 0.7.15
63
46
  type: :runtime
64
47
  version_requirements: *id003
@@ -70,9 +53,6 @@ dependencies:
70
53
  requirements:
71
54
  - - ~>
72
55
  - !ruby/object:Gem::Version
73
- segments:
74
- - 1
75
- - 16
76
56
  version: "1.16"
77
57
  type: :runtime
78
58
  version_requirements: *id004
@@ -84,10 +64,6 @@ dependencies:
84
64
  requirements:
85
65
  - - ~>
86
66
  - !ruby/object:Gem::Version
87
- segments:
88
- - 1
89
- - 16
90
- - 3
91
67
  version: 1.16.3
92
68
  type: :runtime
93
69
  version_requirements: *id005
@@ -99,10 +75,6 @@ dependencies:
99
75
  requirements:
100
76
  - - ~>
101
77
  - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
- - 0
105
- - 9
106
78
  version: 0.0.9
107
79
  type: :runtime
108
80
  version_requirements: *id006
@@ -114,10 +86,6 @@ dependencies:
114
86
  requirements:
115
87
  - - ~>
116
88
  - !ruby/object:Gem::Version
117
- segments:
118
- - 2
119
- - 5
120
- - 0
121
89
  version: 2.5.0
122
90
  type: :development
123
91
  version_requirements: *id007
@@ -129,10 +97,6 @@ dependencies:
129
97
  requirements:
130
98
  - - ~>
131
99
  - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
- - 9
135
- - 12
136
100
  version: 0.9.12
137
101
  type: :development
138
102
  version_requirements: *id008
@@ -148,6 +112,7 @@ extra_rdoc_files: []
148
112
 
149
113
  files:
150
114
  - .gitignore
115
+ - CHANGELOG
151
116
  - Gemfile
152
117
  - README.markdown
153
118
  - Rakefile
@@ -160,7 +125,6 @@ files:
160
125
  - sendl.gemspec
161
126
  - spec/file_spec.rb
162
127
  - spec/spec_helper.rb
163
- has_rdoc: true
164
128
  homepage: http://sendcat.com/
165
129
  licenses: []
166
130
 
@@ -174,21 +138,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
138
  requirements:
175
139
  - - ">="
176
140
  - !ruby/object:Gem::Version
177
- segments:
178
- - 0
179
141
  version: "0"
180
142
  required_rubygems_version: !ruby/object:Gem::Requirement
181
143
  none: false
182
144
  requirements:
183
145
  - - ">="
184
146
  - !ruby/object:Gem::Version
185
- segments:
186
- - 0
187
147
  version: "0"
188
148
  requirements: []
189
149
 
190
150
  rubyforge_project: sendl
191
- rubygems_version: 1.3.7
151
+ rubygems_version: 1.7.2
192
152
  signing_key:
193
153
  specification_version: 3
194
154
  summary: Lib for accessing the sendcat file sending service