Class: Soaring::Detailer

Inherits:
Object
  • Object
show all
Defined in:
lib/soaring/detailer.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Detailer

Returns a new instance of Detailer.



7
8
9
# File 'lib/soaring/detailer.rb', line 7

def initialize(options)
  @options = options
end

Instance Method Details

#detailObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/soaring/detailer.rb', line 11

def detail
  url = URI.parse(@options[:url])
  req = Net::HTTP::Get.new(url.to_s)
  res = Net::HTTP.start(url.host, url.port) {|http|
    http.request(req)
  }

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

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

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