class Lono::Api::Proxy

Public Instance Methods

get(path) click to toggle source
# File lib/lono/api/proxy.rb, line 9
def get(path)
  request(Net::HTTP::Get, path)
end
http(url) click to toggle source
# File lib/lono/api/proxy.rb, line 17
def http(url)
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.open_timeout = http.read_timeout = 30
  http.use_ssl = true if uri.scheme == 'https'
  http
end
post(path, data={}) click to toggle source
# File lib/lono/api/proxy.rb, line 13
def post(path, data={})
  request(Net::HTTP::Post, path, data)
end
request(klass, path, data={}) click to toggle source
# File lib/lono/api/proxy.rb, line 26
def request(klass, path, data={})
  url = url(path)
  http = http(url)
  req = send_request(klass, url, data)
  http.request(req) # send request
end
send_request(klass, url, data={}) click to toggle source
# File lib/lono/api/proxy.rb, line 33
def send_request(klass, url, data={})
  data.merge!(
    lono_version: Lono::VERSION,
    lono_command: lono_command,
  )
  req = klass.new(url) # url includes query string and uri.path does not, must used url
  if [Net::HTTP::Post, Net::HTTP::Put].include?(klass)
    text = JSON.dump(data)
    req.body = text
    req.content_length = text.bytesize
  end
  req
end
url(path) click to toggle source

Lono::API does not include the /. IE: localhost:8888 path includes the /. IE: “/blueprints”

# File lib/lono/api/proxy.rb, line 49
def url(path)
  "#{Lono::API}/#{path}"
end

Private Instance Methods

lono_command() click to toggle source
# File lib/lono/api/proxy.rb, line 54
def lono_command
  "#{$0} #{ARGV.join(' ')}"
end