odeon_uk 1.1.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +8 -1
- data/README.md +1 -0
- data/Rakefile +13 -9
- data/lib/odeon_uk/cinema.rb +14 -42
- data/lib/odeon_uk/film.rb +23 -5
- data/lib/odeon_uk/internal/film_with_screenings_parser.rb +133 -46
- data/lib/odeon_uk/internal/showtimes_page.rb +36 -0
- data/lib/odeon_uk/internal/title_sanitizer.rb +49 -0
- data/lib/odeon_uk/internal/website.rb +36 -0
- data/lib/odeon_uk/screening.rb +56 -22
- data/lib/odeon_uk/version.rb +2 -2
- data/lib/odeon_uk.rb +4 -2
- data/odeon_uk.gemspec +0 -1
- data/test/fixture_updater.rb +72 -0
- data/test/fixtures/{odeon-bfi-imax.html → cinema/bfi_imax.html} +988 -1130
- data/test/fixtures/{odeon-brighton.html → cinema/brighton.html} +1035 -761
- data/test/fixtures/{odeon-london-leicester-square.html → cinema/leicester_square.html} +470 -766
- data/test/fixtures/showtimes/brighton/film_first.html +92 -0
- data/test/fixtures/showtimes/brighton/film_last.html +100 -0
- data/test/fixtures/showtimes/brighton.html +2071 -0
- data/test/fixtures/showtimes/liverpool_one/film_first_dbox.html +188 -0
- data/test/fixtures/showtimes/manchester/film_first_imax.html +182 -0
- data/test/fixtures/{odeon-sitemap.html → sitemap.html} +572 -444
- data/test/lib/odeon_uk/cinema_test.rb +129 -231
- data/test/lib/odeon_uk/film_test.rb +50 -3
- data/test/lib/odeon_uk/internal/film_with_screenings_parser_test.rb +79 -123
- data/test/lib/odeon_uk/internal/showtimes_page_test.rb +51 -0
- data/test/lib/odeon_uk/internal/title_sanitizer_test.rb +105 -0
- data/test/lib/odeon_uk/internal/website_test.rb +59 -0
- data/test/lib/odeon_uk/screening_test.rb +66 -32
- metadata +32 -53
- data/test/fixtures/brighton-showtimes/about-time.html +0 -175
- data/test/fixtures/brighton-showtimes/autism-friendly-planes.html +0 -75
- data/test/fixtures/brighton-showtimes/bolshoi-spartacus-live.html +0 -67
- data/test/fixtures/brighton-showtimes/cinemagic-echo-planet.html +0 -67
- data/test/fixtures/brighton-showtimes/globe-on-screen-twelfth-night.html +0 -67
- data/test/fixtures/brighton-showtimes/met-opera-eugene-onegin.html +0 -67
- data/test/fixtures/brighton-showtimes/national-theatre-live-frankenstein.html +0 -78
- data/test/fixtures/brighton-showtimes/nt-live-war-horse.html +0 -67
- data/test/fixtures/brighton-showtimes/royal-opera-house-turandot.html +0 -66
- data/test/fixtures/brighton-showtimes/rsc-richard-ii.html +0 -67
- data/test/fixtures/brighton-showtimes/star-trek-into-darkness-2d.html +0 -83
- data/test/fixtures/brighton-showtimes/ukjff-from-cable-street-to-brick-lane.html +0 -67
- data/test/fixtures/manchester-showtimes/thor-the-dark-world.html +0 -300
- data/test/fixtures/odeon-brighton-showtimes.html +0 -1238
data/lib/odeon_uk/screening.rb
CHANGED
@@ -1,40 +1,74 @@
|
|
1
1
|
module OdeonUk
|
2
|
-
|
3
2
|
# The object representing a single screening of a film on the Odeon UK website
|
4
3
|
class Screening
|
5
|
-
|
6
4
|
# @return [String] the booking URL on the cinema website
|
7
5
|
attr_reader :booking_url
|
6
|
+
# @return [String] 2d or 3d
|
7
|
+
attr_reader :dimension
|
8
8
|
# @return [String] the cinema name
|
9
9
|
attr_reader :cinema_name
|
10
10
|
# @return [String] the film name
|
11
11
|
attr_reader :film_name
|
12
|
-
|
13
|
-
|
14
|
-
# @
|
15
|
-
|
16
|
-
|
17
|
-
# @
|
18
|
-
# @
|
19
|
-
# @
|
20
|
-
# @
|
21
|
-
|
22
|
-
|
23
|
-
@cinema_name
|
24
|
-
@
|
25
|
-
@
|
12
|
+
|
13
|
+
# @param [Hash] options options hash
|
14
|
+
# @option options [String] :booking_url (nil) booking url for the screening
|
15
|
+
# @option options [String] :cinema_name name of the cinema
|
16
|
+
# @option options [String] :cinema_id website id of the cinema
|
17
|
+
# @option options [String] :dimension ('2d') dimension of the screening
|
18
|
+
# @option options [String] :film_name name of the film
|
19
|
+
# @option options [Time] :time utc time of the screening
|
20
|
+
# @option options [Array<String>] :variant ([]) type of screening
|
21
|
+
def initialize(options)
|
22
|
+
@booking_url = options.fetch(:booking_url, nil)
|
23
|
+
@cinema_name = options.fetch(:cinema_name)
|
24
|
+
@cinema_id = options.fetch(:cinema_id)
|
25
|
+
@dimension = options.fetch(:dimension, '2d')
|
26
|
+
@film_name = options.fetch(:film_name)
|
27
|
+
@time = options.fetch(:time)
|
28
|
+
@variant = options.fetch(:variant, [])
|
29
|
+
end
|
30
|
+
|
31
|
+
# All currently listed films showing at a cinema
|
32
|
+
# @param [Integer] cinema_id id of the cinema on the website
|
33
|
+
# @return [Array<OdeonUk::Screening>]
|
34
|
+
def self.at(cinema_id)
|
35
|
+
showtimes_page(cinema_id).to_a.map do |html|
|
36
|
+
screenings_parser(html).to_a.map do |attributes|
|
37
|
+
new(attributes.merge(cinema_hash(cinema_id)))
|
38
|
+
end
|
39
|
+
end.flatten
|
26
40
|
end
|
27
41
|
|
28
42
|
# The date of the screening
|
29
43
|
# @return [Date]
|
30
|
-
def
|
31
|
-
|
44
|
+
def showing_on
|
45
|
+
showing_at.to_date
|
46
|
+
end
|
47
|
+
|
48
|
+
# The UTC time of the screening
|
49
|
+
# @return [Time]
|
50
|
+
def showing_at
|
51
|
+
@time
|
52
|
+
end
|
53
|
+
|
54
|
+
# The kinds of screening
|
55
|
+
# @return <Array[String]>
|
56
|
+
def variant
|
57
|
+
@variant.map(&:downcase).sort
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def self.screenings_parser(html)
|
63
|
+
OdeonUk::Internal::FilmWithScreeningsParser.new(html)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.showtimes_page(cinema_id)
|
67
|
+
OdeonUk::Internal::ShowtimesPage.new(cinema_id)
|
32
68
|
end
|
33
69
|
|
34
|
-
|
35
|
-
|
36
|
-
warn "Please use #variant instead, I can't spell"
|
37
|
-
variant
|
70
|
+
def self.cinema_hash(id)
|
71
|
+
{ cinema_id: id, cinema_name: Cinema.find(id).name }
|
38
72
|
end
|
39
73
|
end
|
40
74
|
end
|
data/lib/odeon_uk/version.rb
CHANGED
data/lib/odeon_uk.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
require 'httparty'
|
2
1
|
require 'nokogiri'
|
3
2
|
require 'tzinfo'
|
4
3
|
require 'tzinfo/data'
|
5
|
-
require 'pp'
|
6
4
|
|
7
5
|
require_relative './odeon_uk/version'
|
8
6
|
|
9
7
|
require_relative './odeon_uk/internal/film_with_screenings_parser'
|
8
|
+
require_relative './odeon_uk/internal/showtimes_page'
|
9
|
+
require_relative './odeon_uk/internal/title_sanitizer'
|
10
|
+
require_relative './odeon_uk/internal/website'
|
10
11
|
|
11
12
|
require_relative './odeon_uk/cinema'
|
12
13
|
require_relative './odeon_uk/film'
|
13
14
|
require_relative './odeon_uk/screening'
|
14
15
|
|
16
|
+
# odeon_uk gem
|
15
17
|
module OdeonUk
|
16
18
|
end
|
data/odeon_uk.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_development_dependency 'rake'
|
24
24
|
gem.add_development_dependency 'webmock'
|
25
25
|
|
26
|
-
gem.add_runtime_dependency 'httparty'
|
27
26
|
gem.add_runtime_dependency 'nokogiri'
|
28
27
|
gem.add_runtime_dependency 'tzinfo'
|
29
28
|
gem.add_runtime_dependency 'tzinfo-data'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path('../../lib/odeon_uk.rb', __FILE__)
|
2
|
+
|
3
|
+
def fixture(name)
|
4
|
+
File.expand_path("../fixtures/#{name}.html", __FILE__)
|
5
|
+
end
|
6
|
+
|
7
|
+
File.open(fixture('sitemap'), 'w+') do |file|
|
8
|
+
puts '* Sitemap'
|
9
|
+
file.write OdeonUk::Internal::Website.new.sitemap
|
10
|
+
end
|
11
|
+
|
12
|
+
# BRIGHTON
|
13
|
+
|
14
|
+
File.open(fixture('cinema/brighton'), 'w+') do |file|
|
15
|
+
puts '* Brighton Cinema'
|
16
|
+
file.write OdeonUk::Internal::Website.new.cinema(71)
|
17
|
+
end
|
18
|
+
|
19
|
+
File.open(fixture('showtimes/brighton'), 'w+') do |file|
|
20
|
+
puts '* Brighton Showtimes'
|
21
|
+
file.write OdeonUk::Internal::Website.new.showtimes(71)
|
22
|
+
end
|
23
|
+
|
24
|
+
parser = OdeonUk::Internal::ShowtimesParser.new(71)
|
25
|
+
|
26
|
+
File.open(fixture('showtimes/brighton/film_first'), 'w+') do |file|
|
27
|
+
puts '* Brighton Film First'
|
28
|
+
file.write parser.films_with_screenings_html[0]
|
29
|
+
end
|
30
|
+
|
31
|
+
File.open(fixture('showtimes/brighton/film_last'), 'w+') do |file|
|
32
|
+
puts '* Brighton Film Last'
|
33
|
+
file.write parser.films_with_screenings_html[-1]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Manchester IMAX
|
37
|
+
|
38
|
+
parser = OdeonUk::Internal::ShowtimesParser.new(11)
|
39
|
+
imax_screenings = parser.films_with_screenings_html.select do |text|
|
40
|
+
text.match 'imax'
|
41
|
+
end
|
42
|
+
|
43
|
+
File.open(fixture('showtimes/manchester/film_first_imax'), 'w+') do |file|
|
44
|
+
puts '* Manchester Film First IMAX'
|
45
|
+
file.write imax_screenings[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Liverpool ONE
|
49
|
+
|
50
|
+
parser = OdeonUk::Internal::ShowtimesParser.new(171)
|
51
|
+
dbox_screenings = parser.films_with_screenings_html.select do |text|
|
52
|
+
text.match 'D-Box'
|
53
|
+
end
|
54
|
+
|
55
|
+
File.open(fixture('showtimes/liverpool_one/film_first_dbox'), 'w+') do |file|
|
56
|
+
puts '* Liverpool ONE Film First D-BOX'
|
57
|
+
file.write dbox_screenings[0]
|
58
|
+
end
|
59
|
+
|
60
|
+
# London BFI IMAX
|
61
|
+
|
62
|
+
File.open(fixture('cinema/bfi_imax'), 'w+') do |file|
|
63
|
+
puts '* BFI IMAX Cinema'
|
64
|
+
file.write OdeonUk::Internal::Website.new.cinema(211)
|
65
|
+
end
|
66
|
+
|
67
|
+
# London Leicester Square
|
68
|
+
|
69
|
+
File.open(fixture('cinema/leicester_square'), 'w+') do |file|
|
70
|
+
puts '* Leceister Square Cinema'
|
71
|
+
file.write OdeonUk::Internal::Website.new.cinema(105)
|
72
|
+
end
|