Class: Zm::Client::RestAccountConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/connector/rest_account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRestAccountConnector

Returns a new instance of RestAccountConnector.



11
12
13
14
15
# File 'lib/zm/client/connector/rest_account.rb', line 11

def initialize
  @verbose = false
  @follow_location = true
  @curl = easy_curl
end

Instance Attribute Details

#follow_locationObject (readonly)

Returns the value of attribute follow_location.



9
10
11
# File 'lib/zm/client/connector/rest_account.rb', line 9

def follow_location
  @follow_location
end

#verboseObject (readonly)

Returns the value of attribute verbose.



9
10
11
# File 'lib/zm/client/connector/rest_account.rb', line 9

def verbose
  @verbose
end

Instance Method Details



22
23
24
# File 'lib/zm/client/connector/rest_account.rb', line 22

def cookie(cookie)
  @curl.headers['Cookie'] = cookie
end

#download(url, dest_file_path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/zm/client/connector/rest_account.rb', line 26

def download(url, dest_file_path)
  @curl.url = URI.escape(url)
  File.open(dest_file_path, 'wb') do |f|
    @curl.on_body do |data|
      f << data
      data.size
    end
    @curl.perform
  end
end

#upload(url, src_file_path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/zm/client/connector/rest_account.rb', line 37

def upload(url, src_file_path)
  @curl.url = URI.escape(url)
  @curl.http_post(Curl::PostField.file('file', src_file_path))

  if @curl.status.to_i >= 400
    messages = [
      "Upload failure ! #{src_file_path}",
      extract_title(@curl.body_str)
    ].compact
    raise RestError, messages.join("\n")
  end

  @curl.body_str
end

#verbose!Object



17
18
19
20
# File 'lib/zm/client/connector/rest_account.rb', line 17

def verbose!
  @verbose = true
  @curl.verbose = @verbose
end