Class: Zm::Client::RestAccountConnector
- Inherits:
-
Object
- Object
- Zm::Client::RestAccountConnector
- Defined in:
- lib/zm/client/connector/rest_account.rb
Instance Attribute Summary collapse
-
#follow_location ⇒ Object
readonly
Returns the value of attribute follow_location.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #cookies(cookies) ⇒ Object
- #download(url, dest_file_path) ⇒ Object
-
#initialize ⇒ RestAccountConnector
constructor
A new instance of RestAccountConnector.
- #upload(url, src_file_path) ⇒ Object
- #verbose! ⇒ Object
Constructor Details
#initialize ⇒ RestAccountConnector
8 9 10 11 12 |
# File 'lib/zm/client/connector/rest_account.rb', line 8 def initialize @verbose = false @follow_location = true @curl = easy_curl end |
Instance Attribute Details
#follow_location ⇒ Object (readonly)
Returns the value of attribute follow_location.
6 7 8 |
# File 'lib/zm/client/connector/rest_account.rb', line 6 def follow_location @follow_location end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/zm/client/connector/rest_account.rb', line 6 def verbose @verbose end |
Instance Method Details
#cookies(cookies) ⇒ Object
19 20 21 |
# File 'lib/zm/client/connector/rest_account.rb', line 19 def () @curl. = end |
#download(url, dest_file_path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zm/client/connector/rest_account.rb', line 23 def download(url, dest_file_path) @curl.url = url File.open(dest_file_path, 'wb') do |f| @curl.on_body do |data| f << data data.size end @curl.perform end if @curl.status.to_i >= 400 File.unlink(dest_file_path) if File.exist?(dest_file_path) = "Download failure: #{@curl.body_str} (status=#{@curl.status})" raise RestError, end dest_file_path end |
#upload(url, src_file_path) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zm/client/connector/rest_account.rb', line 44 def upload(url, src_file_path) @curl.url = url @curl.http_post(Curl::PostField.file('file', src_file_path)) if @curl.status.to_i >= 400 = [ "Upload failure ! #{src_file_path}", extract_title(@curl.body_str) ].compact raise RestError, .join("\n") end @curl.body_str end |
#verbose! ⇒ Object
14 15 16 17 |
# File 'lib/zm/client/connector/rest_account.rb', line 14 def verbose! @verbose = true @curl.verbose = @verbose end |