module AdorableCat

Constants

VERSION

Public Class Methods

get_cat_data() click to toggle source
# File lib/adorable_cat.rb, line 8
def self.get_cat_data
  begin
    [generate_fact, generate_image]
  rescue Exception => e
    "error message .. miaooo"
    ["Cats not so adorable", "http://3.bp.blogspot.com/_p1qvL_zJG4E/RjQKSX1rTrI/AAAAAAAAAAg/hexhfYgvyJM/s1600-h/cat%2Bwith%2Bfalse%2Bteeth.gif"]
  end
end

Private Class Methods

generate_fact() click to toggle source
# File lib/adorable_cat.rb, line 20
def self.generate_fact
  parse_fact_response(RestClient.get "http://catfacts-api.appspot.com/api/facts", {:params => {:number => 1}})["facts"].first
end
generate_image() click to toggle source
# File lib/adorable_cat.rb, line 24
def self.generate_image
  noko_ele = Nokogiri::HTML(RestClient.get "http://thecatapi.com/api/images/get", {:params => {:format => "html"}})
  parse_image_response noko_ele
end
parse_fact_response(fact) click to toggle source
# File lib/adorable_cat.rb, line 29
def self.parse_fact_response(fact)
  JSON.parse(fact)
end
parse_image_response(nokogiri_object) click to toggle source
# File lib/adorable_cat.rb, line 33
def self.parse_image_response(nokogiri_object)
  nokogiri_object.root.children.children.children.first.attributes["src"].value
end