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.



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

def initialize
  @verbose = false
  @cookies = nil
  @follow_location = true
end

Instance Attribute Details

#follow_locationObject (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

#verboseObject (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



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

def cookies(cookies)
  @cookies = cookies
end

#download(url, dest_file_path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zm/client/connector/rest_account.rb', line 22

def download(url, dest_file_path)
  curl = init_curl_client(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)

    message = "Download failure: #{curl.body_str} (status=#{curl.status})"
    close_curl(curl)
    raise RestError, message
  end

  dest_file_path
end

#upload(url, src_file_path) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zm/client/connector/rest_account.rb', line 45

def upload(url, src_file_path)
  curl = init_curl_client(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
    close_curl(curl)
    raise RestError, messages.join("\n")
  end

  str = curl.body_str
  close_curl(curl)
  str
end

#verbose!Object



14
15
16
# File 'lib/zm/client/connector/rest_account.rb', line 14

def verbose!
  @verbose = true
end