Class: Filmtotaal::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/filmtotaal/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



4
5
6
# File 'lib/filmtotaal/client.rb', line 4

def initialize(api_key)
	@api_key = api_key
end

Instance Method Details

#base_urlObject



21
22
23
# File 'lib/filmtotaal/client.rb', line 21

def base_url
	"http://www.filmtotaal.nl/api/filmsoptv.xml"
end

#decoderObject



31
32
33
# File 'lib/filmtotaal/client.rb', line 31

def decoder
  @decoder ||= HTMLEntities.new
end

#film_of_the_day(date) ⇒ Object



16
17
18
19
# File 'lib/filmtotaal/client.rb', line 16

def film_of_the_day(date)
	results = self.get({'dag' => date.strftime('%d-%m-%Y'), 'sorteer' => 2})
   results.first
end

#get(args = "") ⇒ Object



25
26
27
28
29
# File 'lib/filmtotaal/client.rb', line 25

def get(args = "")
  url = base_url + "?apikey=#{@api_key}&" + args.map { |k,v| "#{k}=#{v}" }.join('&')
  doc = Nokogiri::XML(open(url))
  doc.xpath('//filmsoptv/film').map { |m| Movie.new(m, decoder) }
end

#movie_tips(date) ⇒ Object



12
13
14
# File 'lib/filmtotaal/client.rb', line 12

def movie_tips(date)
	self.get({'dag' => date.strftime('%d-%m-%Y'), 'sorteer' => 1})      
end

#movies(date) ⇒ Object



8
9
10
# File 'lib/filmtotaal/client.rb', line 8

def movies(date)
	self.get({'dag' => date.strftime('%d-%m-%Y'), 'sorteer' => 0})
end