Class: Haste::Uploader
- Inherits:
-
Object
- Object
- Haste::Uploader
- Defined in:
- lib/haste/uploader.rb
Instance Attribute Summary collapse
-
#server_pass ⇒ Object
readonly
Returns the value of attribute server_pass.
-
#server_token ⇒ Object
readonly
Returns the value of attribute server_token.
-
#server_url ⇒ Object
readonly
Returns the value of attribute server_url.
-
#server_user ⇒ Object
readonly
Returns the value of attribute server_user.
-
#share_server_url ⇒ Object
readonly
Returns the value of attribute share_server_url.
-
#ssl_certs ⇒ Object
readonly
Returns the value of attribute ssl_certs.
Instance Method Summary collapse
- #generate_url(url) ⇒ Object
-
#initialize(server_url = nil, server_token = nil, share_server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil) ⇒ Uploader
constructor
A new instance of Uploader.
-
#upload_path(path) ⇒ Object
Take in a path and return a key.
-
#upload_raw(data) ⇒ Object
Take in data and return a key.
Constructor Details
#initialize(server_url = nil, server_token = nil, share_server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil) ⇒ Uploader
14 15 16 17 18 19 20 21 22 |
# File 'lib/haste/uploader.rb', line 14 def initialize(server_url = nil, server_token = nil, share_server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil) @server_url = generate_url(server_url || Haste::DEFAULT_SERVER_URL) @share_server_url = generate_url(share_server_url || Haste::DEFAULT_SHARE_SERVER_URL) @server_user = server_user @server_token = server_token @server_pass = server_pass @ssl_certs = ssl_certs end |
Instance Attribute Details
#server_pass ⇒ Object (readonly)
Returns the value of attribute server_pass.
12 13 14 |
# File 'lib/haste/uploader.rb', line 12 def server_pass @server_pass end |
#server_token ⇒ Object (readonly)
Returns the value of attribute server_token.
12 13 14 |
# File 'lib/haste/uploader.rb', line 12 def server_token @server_token end |
#server_url ⇒ Object (readonly)
Returns the value of attribute server_url.
12 13 14 |
# File 'lib/haste/uploader.rb', line 12 def server_url @server_url end |
#server_user ⇒ Object (readonly)
Returns the value of attribute server_user.
12 13 14 |
# File 'lib/haste/uploader.rb', line 12 def server_user @server_user end |
#share_server_url ⇒ Object (readonly)
Returns the value of attribute share_server_url.
12 13 14 |
# File 'lib/haste/uploader.rb', line 12 def share_server_url @share_server_url end |
#ssl_certs ⇒ Object (readonly)
Returns the value of attribute ssl_certs.
12 13 14 |
# File 'lib/haste/uploader.rb', line 12 def ssl_certs @ssl_certs end |
Instance Method Details
#generate_url(url) ⇒ Object
24 25 26 27 28 |
# File 'lib/haste/uploader.rb', line 24 def generate_url(url) url = url.dup url = url.chop if url.end_with?('/') return url end |
#upload_path(path) ⇒ Object
Take in a path and return a key
31 32 33 34 35 |
# File 'lib/haste/uploader.rb', line 31 def upload_path(path) fail_with 'No input file given' unless path fail_with "#{path}: No such path" unless File.exists?(path) upload_raw open(path).read end |
#upload_raw(data) ⇒ Object
Take in data and return a key
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/haste/uploader.rb', line 38 def upload_raw(data) data.rstrip! response = do_post data if response.status == 200 data = JSON.parse(response.body) data['key'] else fail_with "failure uploading: #{response.body}" end rescue JSON::ParserError => e fail_with "failure parsing response: #{e.}" rescue Errno::ECONNREFUSED => e fail_with "failure connecting: #{e.}" end |