Module: Request

Defined in:
lib/robbie/request.rb

Class Method Summary collapse

Class Method Details

.actor(args) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# 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) ⇒ Object

works, sort of



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object

to do



26
27
28
29
30
31
32
# 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) ⇒ Object

GR Ruby gem auto formats the query to be readable



148
149
150
151
152
153
154
155
156
157
158
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# 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) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Object

to do



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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