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.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zm/client/connector/rest_account.rb', line 10

def initialize
  @verbose = false
  @timeout = 300

  @ssl_options = {
    verify: false,
    verify_hostname: false,
    verify_mode: OpenSSL::SSL::VERIFY_NONE
  }

  @cookies = nil
end

Instance Attribute Details

#follow_locationObject (readonly)

Returns the value of attribute follow_location.



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

def follow_location
  @follow_location
end

#verboseObject (readonly)

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

Instance Method Details

#cookies(cookies) ⇒ Object



27
28
29
# File 'lib/zm/client/connector/rest_account.rb', line 27

def cookies(cookies)
  @cookies = cookies
end

#download(download_url, dest_file_path) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/zm/client/connector/rest_account.rb', line 51

def download(download_url, dest_file_path)
  url, path = split_url(download_url)

  conn = conn_get(url)

  write_downloaded_file(dest_file_path, conn, path)
end

#read(download_url) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zm/client/connector/rest_account.rb', line 31

def read(download_url)
  url, path = split_url(download_url)

  conn = conn_get(url)

  data = +''

  response = conn.get(path) do |request|
    request.options.on_data = Proc.new do |chunk, _, _|
      data.concat(chunk)
    end
  end

  if response.status >= 400
    raise RestError, "Download failure: #{response.body} (status=#{response.status})"
  end

  data
end

#upload(upload_url, src_file_path) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/zm/client/connector/rest_account.rb', line 59

def upload(upload_url, src_file_path)
  url, path = split_url(upload_url)

  conn = conn_multipart(url)

  payload = { file: Faraday::Multipart::FilePart.new(src_file_path, nil) }
  response = conn.post(path, payload)

  if response.status >= 400
    messages = [
      "Upload failure ! #{src_file_path}",
      extract_title(response.body)
    ].compact

    raise RestError, messages.join("\n")
  end

  response.body
end

#verbose!Object



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

def verbose!
  @verbose = true
end