class GHI::Web

Constants

BASE_URI
HOST

Attributes

base[R]

Public Class Methods

new(base) click to toggle source
# File lib/ghi/web.rb, line 10
def initialize base
  @base = base
end

Public Instance Methods

curl(path = '', params = {}) click to toggle source
# File lib/ghi/web.rb, line 23
def curl path = '', params = {}
  uri_for(path, params).open.read
end
open(path = '', params = {}) click to toggle source
# File lib/ghi/web.rb, line 14
def open path = '', params = {}
  path = uri_for path, params
  $stdout.puts path
  return unless $stdout.tty?
  launcher = 'open'
  launcher = 'xdg-open' if /linux/ =~ RUBY_PLATFORM
  system "#{launcher} '#{path}'"
end

Private Instance Methods

uri_for(path, params) click to toggle source
# File lib/ghi/web.rb, line 29
def uri_for path, params
  unless params.empty?
    q = params.map { |k, v| "#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" }
    path += "?#{q.join '&'}"
  end
  URI(BASE_URI) + "#{base}/" + path
end