Class: Sendl::Uploader
- Inherits:
-
Object
- Object
- Sendl::Uploader
- Defined in:
- lib/sendl/uploader.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#json_parser ⇒ Object
Returns the value of attribute json_parser.
-
#message ⇒ Object
Returns the value of attribute message.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#share_url ⇒ Object
Returns the value of attribute share_url.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
- #debug(msg) ⇒ Object
-
#initialize(options) ⇒ Uploader
constructor
A new instance of Uploader.
- #success? ⇒ Boolean
- #upload(files, options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ Uploader
Returns a new instance of Uploader.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sendl/uploader.rb', line 6 def initialize() argument_errors = [] argument_errors << "You must pass an API key!" unless [:api_key] argument_errors << "You must specify recipients!" unless [:recipients] raise(ArgumentError, argument_errors.join(", ")) if argument_errors.size > 0 @endpoint = ENV['ENDPOINT'] || 'https://sendcat.com' @api_key = [:api_key] @recipients = de_dupe_recipients([:recipients]) @message = [:message] || "" @debug = [:debug] || false @success = false @errors = [] @share_id = nil @share_id = get_share_id end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def api_key @api_key end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def endpoint @endpoint end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def errors @errors end |
#json_parser ⇒ Object
Returns the value of attribute json_parser.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def json_parser @json_parser end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def @message end |
#recipients ⇒ Object
Returns the value of attribute recipients.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def recipients @recipients end |
#share_url ⇒ Object
Returns the value of attribute share_url.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def share_url @share_url end |
#success ⇒ Object
Returns the value of attribute success.
4 5 6 |
# File 'lib/sendl/uploader.rb', line 4 def success @success end |
Instance Method Details
#debug(msg) ⇒ Object
22 23 24 |
# File 'lib/sendl/uploader.rb', line 22 def debug(msg) @debug && STDERR.puts(msg) end |
#success? ⇒ Boolean
41 42 43 |
# File 'lib/sendl/uploader.rb', line 41 def success? errors.size == 0 end |
#upload(files, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sendl/uploader.rb', line 26 def upload(files, = {}) files.each do |f| upload_file(f) end if success? debug("success? was true, finalising the share") r = Curl::Easy.new(url_for("shares/#{@share_id}/finalise.json")) do |curl| curl.http_post Curl::PostField.content("auth_token", api_key) end else STDERR.puts "Could not complete share as there were errors" end end |