Module: Search
- Defined in:
- lib/robbie/search.rb
Class Method Summary collapse
Class Method Details
.actor(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/robbie/search.rb', line 34 def actor (name) if name.nil? puts "You need to specify an actor/actress to query" exit end name = URI.escape(name.first) myApiFilms = JSON.parse(HTTP.get("http://www.myapifilms.com/imdb/idIMDB?name=#{name}&token=8e26a029-8cf1-4dd7-89bd-889bf5e74cbd&format=json&language=en-us&limit=1&bornDied=1").body) dob = Time.parse(myApiFilms["data"]["names"][0]["dateOfBirth"]) now = Time.now.utc.to_date age = now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) puts "- #{myApiFilms["data"]["names"][0]["name"]} (Age: #{age}) /#{myApiFilms["data"]["names"][0]["idIMDB"]}" end |
.movie(title) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/robbie/search.rb', line 9 def movie(title) if title.empty? puts "You need to specify a movie to query" exit end title = URI.escape(title.first) url = "http://www.omdbapi.com/?type=movie&r=json&s="+title omdbData = JSON.parse(HTTP.get('http://www.omdbapi.com/?type=movie&r=json&s='+title).body) puts "- #{omdbData["Search"][0]["Title"]} (#{omdbData["Search"][0]["Year"]}) - imdb.com/title/#{omdbData["Search"][0]["imdbID"]}" puts "- #{omdbData["Search"][1]["Title"]} (#{omdbData["Search"][1]["Year"]}) - imdb.com/title/#{omdbData["Search"][1]["imdbID"]}" puts "- #{omdbData["Search"][2]["Title"]} (#{omdbData["Search"][2]["Year"]}) - imdb.com/title/#{omdbData["Search"][2]["imdbID"]}" end |
.tv(title) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/robbie/search.rb', line 22 def tv (title) if title.nil? puts "You need to specify a TV show to query" exit end title = URI.escape(title.first) omdbData = JSON.parse(HTTP.get('http://www.omdbapi.com/?type=series&r=json&s='+title).body) puts "- #{omdbData["Search"][0]["Title"]} (#{omdbData["Search"][0]["Year"]}) - imdb.com/title/#{omdbData["Search"][0]["imdbID"]}" puts "- #{omdbData["Search"][1]["Title"]} (#{omdbData["Search"][1]["Year"]}) - imdb.com/title/#{omdbData["Search"][1]["imdbID"]}" puts "- #{omdbData["Search"][2]["Title"]} (#{omdbData["Search"][2]["Year"]}) - imdb.com/title/#{omdbData["Search"][2]["imdbID"]}" end |