class Gollum::RemoteCode

Public Class Methods

new(path) click to toggle source
# File lib/gollum-lib/remote_code.rb, line 8
def initialize path
  raise(ArgumentError, 'path is nil or empty') if path.nil? or path.empty?
  @uri = URI(path)
end

Public Instance Methods

contents() click to toggle source
# File lib/gollum-lib/remote_code.rb, line 13
def contents
  @contents ||= req @uri
end

Private Instance Methods

req(uri, cut = 1) click to toggle source
# File lib/gollum-lib/remote_code.rb, line 19
def req uri, cut = 1
  return "Too many redirects or retries" if cut >= 10
  http = Net::HTTP.new uri.host, uri.port
  http.use_ssl = true
  resp = http.get uri.path, {
    'Accept'        => 'text/plain',
    'Cache-Control' => 'no-cache',
    'Connection'    => 'keep-alive',
    'User-Agent'    => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0'
  }
  code = resp.code.to_i
  return resp.body if code == 200
  return "Not Found" if code == 404
  return "Unhandled Response Code #{code}" unless code == 304 or not resp.header['location'].nil?
  loc = URI.parse resp.header['location']
  uri2 = loc.relative? ? (uri + loc) : loc # overloads (+)
  req uri2, (cut + 1)
end