module Request

Public Instance Methods

actor(args) click to toggle source
# File lib/robbie/request.rb, line 116
def actor (args)
  name = URI.escape(args.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&filmography=1&exactFilter=0&limit=1&bornDied=1&starSign=0&uniqueName=0&actorActress=0&actorTrivia=0&actorPhotos=0&actorVideos=0&salary=0&spouses=0&tradeMark=0&personalQuotes=0&starMeter=0").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)

  apiFilmsShort = myApiFilms["data"]["names"][0]
  films = apiFilmsShort["filmographies"][0]["filmography"]
  puts "Name:\t\t#{apiFilmsShort["name"]}"
  puts "Age:\t\t#{age} years"
  print "Filmography:\t"
  10.times do |i|
    str = films[i]["year"]
    if str =~ /\d/
      if(i == 9)
        print "#{films[i]["title"]} (#{films[i]["year"][1..-1]})."
      else
        print "#{films[i]["title"]} (#{films[i]["year"][1..-1]}), "
      end
    else
      if(i == 9)
        print "#{films[i]["title"]} (TBD)."
      else
        print "#{films[i]["title"]} (TBD), "
      end
    end
  end
  puts "\nBirthday:\t#{apiFilmsShort["dateOfBirth"]}"
end
album(args) click to toggle source
# File lib/robbie/request.rb, line 53
def album(args) # works, sort of
  # Requires artist and album
  @album = URI.escape(args.shift)
  @artist = URI.escape(args.shift)
  @res = HTTP.get("http://ws.audioscrobbler.com/2.0/?method=album.getInfo&artist=#{@artist}&album=#{@album}&api_key=0a7d3b25ed857f679eba1a353e98a658&format=json").body
  @json = JSON.parse(@res)

  puts "Title: \t\t#{@json['album']['name']}"
  puts "Artist: \t#{@json['album']['artist']}"
  puts "Year: \t\t#{@json['album']['wiki']['published']}"
  puts "Tracks: \t"

  @json['album']['tracks']['track'].length.times do |i|
    puts "\t##{i+1}:\t#{@json['album']['tracks']['track'][i]['name']}"
  end
end
artist(args) click to toggle source
# File lib/robbie/request.rb, line 26
def artist(args) # to do
  @artist = URI.escape(args.shift)
  @res = HTTP.get("http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist=#{@artist}&api_key=0a7d3b25ed857f679eba1a353e98a658&format=json").body
  @json = JSON.parse(@res)

  puts @json['artist']['bio']['summary']
end
book(title) click to toggle source
# File lib/robbie/request.rb, line 148
def book (title) # GR Ruby gem auto formats the query to be readable
  # file = File.read('key.json')
  # keys = JSON.parse(file)
  title = title.first
  client = Goodreads.new(:api_key => 'oSMwxqaPNr0o1PYs2Jddg') # keys["goodreads"]["public"] # i fucking hate code dude i s2g
  book = client.book_by_title(title)

  puts "Title: #{book.title}"
  puts "Publisher: #{book.publisher}"
  puts "Author: #{book.authors.author[0]['name']}"
end
id(id) click to toggle source
# File lib/robbie/request.rb, line 14
def id(id)
  @id = URI.escape(id.shift)
  @res = HTTP.get("http://www.omdbapi.com/?i=#{@id}")
  @json = JSON.parse(@res)

  puts "Title: \t\t #{@json["Title"]}"
  puts "Plot:  \t\t #{@json["Plot"]}"
  puts "Poster: \t #{@json["Poster"]}"
  puts "Actors: \t #{@json["Actors"]}"
  puts "Rating: \t\t #{@json["imdbRating"]}"
end
movie(title) click to toggle source
# File lib/robbie/request.rb, line 70
def movie(title)
  Bitly.use_api_version_3

  bitly = Bitly.new('benp51', 'R_886e9ca24b25c1e91d66f5c6379568a9')
  client = Canistreamit::Client.new

  titleClean = title.first
  overwrittenTitle = URI.escape(title.first)
  canistreamit = client.search_and_query(titleClean, ["streaming"])
  omdbData = JSON.parse(HTTP.get('http://www.omdbapi.com/?t='+overwrittenTitle+'&y=&plot=short&r=json').body)

  puts "Title:\t\t#{omdbData["Title"]}"
  puts "Plot:\t\t#{omdbData["Plot"]}"
  puts "Director:\t#{omdbData["Director"]}"
  puts "Poster:\t\t#{bitly.shorten(omdbData["Poster"]).short_url}"
  puts "Actors:\t\t#{omdbData["Actors"]}"
  puts "Rating:\t\t#{omdbData["imdbRating"]}"

  if(canistreamit[0]["availability"]["streaming"].empty?)
    puts "Stream: \tNot Available"
  else
    puts "Stream: "
    canistreamit[0]["availability"]["streaming"].each do |service|
      puts "\t#{service[1]['friendlyName']}\t#{bitly.shorten(service[1]["direct_url"]).short_url}"
    end
  end
end
song(args) click to toggle source
# File lib/robbie/request.rb, line 34
def song(args) # to do
  # Requires track title and artist name
  @song = URI.escape(args.shift)
  @artist = URI.escape(args.shift)
  @res = HTTP.get("http://ws.audioscrobbler.com/2.0/?method=track.getInfo&track=#{@song}&artist=#{@artist}&api_key=0a7d3b25ed857f679eba1a353e98a658&format=json").body
  @json = JSON.parse(@res)

  if @year = @json['track']['wiki'].nil?
    @year = "Not Available"
  else
    @year = @json['track']['wiki']['published']
  end

  puts "Title: \t\t#{@json['track']['name']}"
  puts "Artist: \t#{@json['track']['artist']['name']}"
  puts "Year: \t\t#{@year}"
  puts "Duration: \t#{@json['track']['duration'].to_i/1000} seconds"
end
tv(title) click to toggle source
# File lib/robbie/request.rb, line 98
def tv (title)
  Bitly.use_api_version_3

  bitly = Bitly.new('benp51', 'R_886e9ca24b25c1e91d66f5c6379568a9')

  titleClean = title.first
  overwrittenTitle = URI.escape(title.first)
  client = Canistreamit::Client.new
  canistreamit = client.search_and_query(titleClean, ["streaming"])

  omdbData = JSON.parse(HTTP.get('http://www.omdbapi.com/?t='+overwrittenTitle+'&type=series&plot=short&r=json').body)
  puts "Title:\t\t#{omdbData["Title"]}"
  puts "Plot:\t\t#{omdbData["Plot"]}"
  puts "Poster:\t\t#{bitly.shorten(omdbData["Poster"]).short_url}"
  puts "Actors:\t\t#{omdbData["Actors"]}"
  puts "Rating:\t\t#{omdbData["imdbRating"]}"
end