Module: Rmega::Net

Includes:
Loggable, Options
Included in:
Rmega::Nodes::Downloadable, Rmega::Nodes::Uploadable, Session
Defined in:
lib/rmega/net.rb

Instance Method Summary collapse

Methods included from Options

included, #options

Methods included from Loggable

included, #logger

Instance Method Details

#http_get_content(url) ⇒ Object



18
19
20
21
22
# File 'lib/rmega/net.rb', line 18

def http_get_content(url)
  uri = URI(url)
  req = ::Net::HTTP::Get.new(uri.request_uri)
  return send_http_request(uri, req).body
end

#http_post(url, data) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/rmega/net.rb', line 24

def http_post(url, data)
  uri = URI(url)
  req = ::Net::HTTP::Post.new(uri.request_uri)
  req.body = data
  logger.debug("REQ POST #{url} #{cut_string(data)}")
  response = send_http_request(uri, req)
  logger.debug("REP #{response.code} #{cut_string(response.body)}")
  return response
end

#survive(retries = options.max_retries, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rmega/net.rb', line 6

def survive(retries = options.max_retries, &block)
  yield
rescue ServerError
  raise
rescue Exception => error
  retries -= 1
  raise(error) if retries < 0
  logger.debug("[#{error.class}] #{error.message}. #{retries} attempt(s) left.")
  sleep(options.retry_interval)
  retry
end