odeon_uk 1.1.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +8 -1
  4. data/README.md +1 -0
  5. data/Rakefile +13 -9
  6. data/lib/odeon_uk/cinema.rb +14 -42
  7. data/lib/odeon_uk/film.rb +23 -5
  8. data/lib/odeon_uk/internal/film_with_screenings_parser.rb +133 -46
  9. data/lib/odeon_uk/internal/showtimes_page.rb +36 -0
  10. data/lib/odeon_uk/internal/title_sanitizer.rb +49 -0
  11. data/lib/odeon_uk/internal/website.rb +36 -0
  12. data/lib/odeon_uk/screening.rb +56 -22
  13. data/lib/odeon_uk/version.rb +2 -2
  14. data/lib/odeon_uk.rb +4 -2
  15. data/odeon_uk.gemspec +0 -1
  16. data/test/fixture_updater.rb +72 -0
  17. data/test/fixtures/{odeon-bfi-imax.html → cinema/bfi_imax.html} +988 -1130
  18. data/test/fixtures/{odeon-brighton.html → cinema/brighton.html} +1035 -761
  19. data/test/fixtures/{odeon-london-leicester-square.html → cinema/leicester_square.html} +470 -766
  20. data/test/fixtures/showtimes/brighton/film_first.html +92 -0
  21. data/test/fixtures/showtimes/brighton/film_last.html +100 -0
  22. data/test/fixtures/showtimes/brighton.html +2071 -0
  23. data/test/fixtures/showtimes/liverpool_one/film_first_dbox.html +188 -0
  24. data/test/fixtures/showtimes/manchester/film_first_imax.html +182 -0
  25. data/test/fixtures/{odeon-sitemap.html → sitemap.html} +572 -444
  26. data/test/lib/odeon_uk/cinema_test.rb +129 -231
  27. data/test/lib/odeon_uk/film_test.rb +50 -3
  28. data/test/lib/odeon_uk/internal/film_with_screenings_parser_test.rb +79 -123
  29. data/test/lib/odeon_uk/internal/showtimes_page_test.rb +51 -0
  30. data/test/lib/odeon_uk/internal/title_sanitizer_test.rb +105 -0
  31. data/test/lib/odeon_uk/internal/website_test.rb +59 -0
  32. data/test/lib/odeon_uk/screening_test.rb +66 -32
  33. metadata +32 -53
  34. data/test/fixtures/brighton-showtimes/about-time.html +0 -175
  35. data/test/fixtures/brighton-showtimes/autism-friendly-planes.html +0 -75
  36. data/test/fixtures/brighton-showtimes/bolshoi-spartacus-live.html +0 -67
  37. data/test/fixtures/brighton-showtimes/cinemagic-echo-planet.html +0 -67
  38. data/test/fixtures/brighton-showtimes/globe-on-screen-twelfth-night.html +0 -67
  39. data/test/fixtures/brighton-showtimes/met-opera-eugene-onegin.html +0 -67
  40. data/test/fixtures/brighton-showtimes/national-theatre-live-frankenstein.html +0 -78
  41. data/test/fixtures/brighton-showtimes/nt-live-war-horse.html +0 -67
  42. data/test/fixtures/brighton-showtimes/royal-opera-house-turandot.html +0 -66
  43. data/test/fixtures/brighton-showtimes/rsc-richard-ii.html +0 -67
  44. data/test/fixtures/brighton-showtimes/star-trek-into-darkness-2d.html +0 -83
  45. data/test/fixtures/brighton-showtimes/ukjff-from-cable-street-to-brick-lane.html +0 -67
  46. data/test/fixtures/manchester-showtimes/thor-the-dark-world.html +0 -300
  47. data/test/fixtures/odeon-brighton-showtimes.html +0 -1238
@@ -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
- # @return [Time] the UTC time of the screening
13
- attr_reader :when
14
- # @return [String] the type of screening (2D, 3D, IMAX...)
15
- attr_reader :variant
16
-
17
- # @param [String] film_name the film name
18
- # @param [String] the cinema name
19
- # @param [Time] time datetime of the screening (UTC preferred)
20
- # @param [String] booking_url direct link to the booking page for this screening
21
- # @param [String] variant the type of showing (e.g. 3d/baby/live)
22
- def initialize(film_name, cinema_name, time, booking_url=nil, variant=nil)
23
- @cinema_name, @film_name, @variant = cinema_name, film_name, variant
24
- @booking_url = booking_url
25
- @when = time.utc? ? time : TZInfo::Timezone.get('Europe/London').local_to_utc(time)
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 date
31
- @when.to_date
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
- # @deprecated Please use {#variant} instead, I can't spell
35
- def varient
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
@@ -1,6 +1,6 @@
1
1
  # Ruby interface for http://www.odeon.co.uk
2
- # @version 1.1.5
2
+ # @version 2.0.0
3
3
  module OdeonUk
4
4
  # Gem version
5
- VERSION = "1.1.5"
5
+ VERSION = '2.0.0'
6
6
  end
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