filmtotaal 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README +1 -0
- data/Rakefile +1 -0
- data/filmtotaal.gemspec +25 -0
- data/lib/filmtotaal.rb +9 -0
- data/lib/filmtotaal/client.rb +35 -0
- data/lib/filmtotaal/movie.rb +27 -0
- data/lib/filmtotaal/version.rb +3 -0
- data/spec/config.yml.default +1 -0
- data/spec/filmtotaal_spec.rb +58 -0
- data/spec/spec_helper.rb +13 -0
- metadata +109 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Simple library to talk to the FilmTotaal API (Dutch)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/filmtotaal.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "filmtotaal/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "filmtotaal"
|
7
|
+
s.version = Filmtotaal::VERSION
|
8
|
+
s.authors = ["Erik van der Wal"]
|
9
|
+
s.email = ["erikvdwal@gmail.com"]
|
10
|
+
s.homepage = "http://www.erikvdwal.nl/"
|
11
|
+
s.summary = %q{Simple library to talk to the FilmTotaal API (Dutch)}
|
12
|
+
s.description = %q{Simple library to talk to the FilmTotaal API (Dutch)}
|
13
|
+
|
14
|
+
s.rubyforge_project = "filmtotaal"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "nokogiri"
|
24
|
+
s.add_runtime_dependency "htmlentities"
|
25
|
+
end
|
data/lib/filmtotaal.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require "filmtotaal/version"
|
2
|
+
require "date"
|
3
|
+
require "open-uri"
|
4
|
+
require "nokogiri"
|
5
|
+
require "htmlentities"
|
6
|
+
|
7
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
8
|
+
require File.join(directory, 'filmtotaal', 'client')
|
9
|
+
require File.join(directory, 'filmtotaal', 'movie')
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Filmtotaal
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def initialize(api_key)
|
5
|
+
@api_key = api_key
|
6
|
+
end
|
7
|
+
|
8
|
+
def movies(date)
|
9
|
+
self.get({'dag' => date.strftime('%d-%m-%Y'), 'sorteer' => 0})
|
10
|
+
end
|
11
|
+
|
12
|
+
def movie_tips(date)
|
13
|
+
self.get({'dag' => date.strftime('%d-%m-%Y'), 'sorteer' => 1})
|
14
|
+
end
|
15
|
+
|
16
|
+
def film_of_the_day(date)
|
17
|
+
results = self.get({'dag' => date.strftime('%d-%m-%Y'), 'sorteer' => 2})
|
18
|
+
results.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_url
|
22
|
+
"http://www.filmtotaal.nl/api/filmsoptv.xml"
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(args = "")
|
26
|
+
url = base_url + "?apikey=#{@api_key}&" + args.map { |k,v| "#{k}=#{v}" }.join('&')
|
27
|
+
doc = Nokogiri::XML(open(url))
|
28
|
+
doc.xpath('//filmsoptv/film').map { |m| Movie.new(m, decoder) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def decoder
|
32
|
+
@decoder ||= HTMLEntities.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Filmtotaal
|
2
|
+
class Movie
|
3
|
+
attr_reader :title, :year, :url, :director, :actors, :genres, :countries, :plot, :tagline, :imdb_id, :imdb_rating, :rating, :votes, :start_time, :end_time, :channel, :runtime, :movie_tip, :cover_url
|
4
|
+
def initialize(data, decoder)
|
5
|
+
@title = decoder.decode(data.xpath('titel').text)
|
6
|
+
@year = data.xpath('jaar').text.to_i
|
7
|
+
@url = data.xpath('ft_link').text
|
8
|
+
@director = decoder.decode(data.xpath('regisseur').text)
|
9
|
+
@actors = decoder.decode(data.xpath('cast').text).split(':')
|
10
|
+
@genres = decoder.decode(data.xpath('genres').text).split(':')
|
11
|
+
@countries = decoder.decode(data.xpath('land').text).split(':')
|
12
|
+
@plot = decoder.decode(data.xpath('synopsis').text)
|
13
|
+
@tagline = decoder.decode(data.xpath('tagline').text)
|
14
|
+
@rating = data.xpath('ft_rating').text.to_f
|
15
|
+
@votes = data.xpath('ft_votes').text.to_i
|
16
|
+
@imdb_id = "tt#{data.xpath('imdb_id').text}"
|
17
|
+
@imdb_rating = data.xpath('imdb_rating').text.to_f
|
18
|
+
@imdb_votes = data.xpath('imdb_votes').text.to_i
|
19
|
+
@start_time = data.xpath('starttijd').text.to_i
|
20
|
+
@end_time = data.xpath('eindtijd').text.to_i
|
21
|
+
@runtime = data.xpath('duur').text.to_i
|
22
|
+
@channel = decoder.decode(data.xpath('zender').text)
|
23
|
+
@movie_tip = data.xpath('filmtip').text.to_i == 1 ? true : false
|
24
|
+
@cover_url = data.xpath('cover').text
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
api_key: ""
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "filmtotaal" do
|
4
|
+
before(:all) do
|
5
|
+
config = YAML.load_file(File.join(File.dirname(__FILE__), "config.yml"))
|
6
|
+
@client = Filmtotaal::Client.new(config['api_key'])
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "movie" do
|
10
|
+
it "should return todays movies" do
|
11
|
+
movies = @client.movies(Date.today)
|
12
|
+
movies.count.should > 0
|
13
|
+
movies.first.should be_a(Filmtotaal::Movie)
|
14
|
+
movies.first.genres.should be_a(Array)
|
15
|
+
movies.first.actors.should be_a(Array)
|
16
|
+
movies.first.start_time.should be_a(Integer)
|
17
|
+
movies.first.end_time.should be_a(Integer)
|
18
|
+
movies.first.runtime.should be_a(Integer)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return tomorrows movies" do
|
22
|
+
movies = @client.movies(Date.today+1)
|
23
|
+
movies.count.should > 0
|
24
|
+
movies.first.should be_a(Filmtotaal::Movie)
|
25
|
+
movies.first.genres.should be_a(Array)
|
26
|
+
movies.first.actors.should be_a(Array)
|
27
|
+
movies.first.start_time.should be_a(Integer)
|
28
|
+
movies.first.end_time.should be_a(Integer)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not return movies after tomorrow" do
|
32
|
+
movies = @client.movies(Date.today+2)
|
33
|
+
movies.count.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return movie tip for today" do
|
37
|
+
movies = @client.movie_tips(Date.today)
|
38
|
+
movies.count.should > 0
|
39
|
+
movies.first.should be_a(Filmtotaal::Movie)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return movie tip for tomorrow" do
|
43
|
+
movies = @client.movie_tips(Date.today+1)
|
44
|
+
movies.count.should > 0
|
45
|
+
movies.first.should be_a(Filmtotaal::Movie)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return a film of the day" do
|
49
|
+
movie = @client.film_of_the_day(Date.today)
|
50
|
+
movie.should be_a(Filmtotaal::Movie)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not return a film of the day after tomorrow" do
|
54
|
+
movie = @client.film_of_the_day(Date.today+2)
|
55
|
+
movie.should be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'filmtotaal'
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filmtotaal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Erik van der Wal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: htmlentities
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Simple library to talk to the FilmTotaal API (Dutch)
|
63
|
+
email:
|
64
|
+
- erikvdwal@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- README
|
73
|
+
- Rakefile
|
74
|
+
- filmtotaal.gemspec
|
75
|
+
- lib/filmtotaal.rb
|
76
|
+
- lib/filmtotaal/client.rb
|
77
|
+
- lib/filmtotaal/movie.rb
|
78
|
+
- lib/filmtotaal/version.rb
|
79
|
+
- spec/config.yml.default
|
80
|
+
- spec/filmtotaal_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: http://www.erikvdwal.nl/
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project: filmtotaal
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Simple library to talk to the FilmTotaal API (Dutch)
|
106
|
+
test_files:
|
107
|
+
- spec/config.yml.default
|
108
|
+
- spec/filmtotaal_spec.rb
|
109
|
+
- spec/spec_helper.rb
|