class Soaring::Detailer

Public Class Methods

new(options) click to toggle source
# File lib/soaring/detailer.rb, line 7
def initialize(options)
  @options = options
end

Public Instance Methods

detail() click to toggle source
# File lib/soaring/detailer.rb, line 11
def detail
  uri = URI.parse(@options[:url])
  args = {}
  uri.query = URI.encode_www_form(args)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true if uri.is_a?(URI::HTTPS)
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)

  if '200' != response.code
    $stderr.puts "Failed to connect with http error code #{response.code}"
    exit 1
  end

  puts JSON.parse(response.body) if 'json' == @options[:format]
  print JSON.parse(response.body).to_yaml if 'yaml' == @options[:format]

rescue StandardError => exception
  message = "#{exception.class}: #{exception.message}"
  $stderr.puts "#{message}"
  exit 1
end