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
31
32
# 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