Module: ODDB::HttpFile

Included in:
Plugin
Defined in:
src/util/http.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) http_body(server, source, session = nil, hdrs = nil)



23
24
25
26
27
28
29
# File 'src/util/http.rb', line 23

def http_body(server, source, session=nil, hdrs=nil)
  session ||= HttpSession.new server
  resp = session.get(source, hdrs)
  if resp.is_a? Net::HTTPOK
    resp.body
  end
end

- (Object) http_file(server, source, target, session = nil, hdrs = nil)



13
14
15
16
17
18
19
20
21
22
# File 'src/util/http.rb', line 13

def http_file(server, source, target, session=nil, hdrs = nil)
  if(body = http_body(server, source, session, hdrs))
    dir = File.dirname(target)
    FileUtils.mkdir_p(dir)
    File.open(target, 'w') { |file|
      file << body
    }
    true
  end
end