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



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_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



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

def cookies(cookies)
  @curl.cookies = cookies
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)

    message = "Download failure: #{@curl.body_str} (status=#{@curl.status})"
    raise RestError, message
  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
    messages = [
      "Upload failure ! #{src_file_path}",
      extract_title(@curl.body_str)
    ].compact
    raise RestError, messages.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