Class: TMDBParty::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HTTParty::Icebox
Defined in:
lib/tmdb_party.rb

Instance Method Summary collapse

Methods included from HTTParty::Icebox

included

Constructor Details

#initialize(key = nil) ⇒ Base

Returns a new instance of Base.



39
40
41
# File 'lib/tmdb_party.rb', line 39

def initialize(key=nil)
  !key.nil? ? (@api_key = key) : (@api_key= readFile('apikey.txt').first.strip)
end

Instance Method Details

#default_path_itemsObject



43
44
45
46
47
# File 'lib/tmdb_party.rb', line 43

def default_path_items
  path_items = ['en']
  path_items << 'json'
  path_items << @api_key
end

#get_info(id) ⇒ Object



67
68
69
70
# File 'lib/tmdb_party.rb', line 67

def get_info(id)
  data = self.class.get("/Movie.getInfo/" + default_path_items.join('/') + '/' + id.to_s)
  Movie.new(data.first, self)
end

#imdb_lookup(imdb_id) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/tmdb_party.rb', line 58

def imdb_lookup(imdb_id)
  data = self.class.get("/Movie.imdbLookup/" + default_path_items.join('/') + '/' + imdb_id)
  if data.class != Array || data.first == "Nothing found."
    nil
  else
    Movie.new(data.first, self)
  end
end

#readFile(filename, maxlines = 0) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/tmdb_party.rb', line 28

def readFile filename, maxlines=0
  i=0
  read_so_far=[]
  f=File.open(File.expand_path(filename), 'r')
  while (line=f.gets)
    break if maxlines!=0 and i >= maxlines
    read_so_far << line and i+=1
  end
  read_so_far
end

#search(query) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/tmdb_party.rb', line 49

def search(query)
  data = self.class.get("/Movie.search/" + default_path_items.join('/') + '/' + URI.escape(query))
  if data.class != Array || data.first == "Nothing found."
    []
  else
    data.collect { |movie| Movie.new(movie, self) }
  end
end