Class: Sloop
- Inherits:
-
Object
- Object
- Sloop
- Defined in:
- lib/sloop.rb
Class Method Summary collapse
Class Method Details
.name_vessel(shipname) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/sloop.rb', line 6 def self.name_vessel(shipname) connection = Faraday.new(:url => 'http://domai.nr') response = connection.get("/api/json/search?q=#{shipname}") if response.status.to_i == 200 pretty_print(Yajl::Parser.new(:symbolize_keys => true).parse(response.body)) else puts "Your query resulted in an error".red.bold end end |
.pretty_print(body) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sloop.rb', line 16 def self.pretty_print(body) puts "You searched for '#{body[:query]}'\n".green.bold puts ("Domain".ljust(20) + "Availability".ljust(20) + "Register").blue body[:results].each do |domain| if domain[:availability] == 'taken' || domain[:availability] == 'unavailable' puts ("#{domain[:domain]}".ljust(20) + "#{domain[:availability]}").yellow else puts ("#{domain[:domain]}".ljust(20) + "#{domain[:availability]}".ljust(20) + domain[:register_url]).green end end puts "\n" end |