odeon_uk 3.0.6 → 4.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 +5 -3
- data/CHANGELOG.md +14 -0
- data/{LICENSE.txt → COMM-LICENSE} +0 -0
- data/LICENSE +617 -0
- data/README.md +58 -29
- data/Rakefile +7 -21
- data/lib/odeon_uk.rb +5 -14
- data/lib/odeon_uk/cinema.rb +123 -75
- data/lib/odeon_uk/{api/response.rb → internal/api_response.rb} +3 -3
- data/lib/odeon_uk/internal/parser/api/film_lookup.rb +34 -0
- data/lib/odeon_uk/internal/parser/api/performance_day.rb +92 -0
- data/lib/odeon_uk/internal/title_sanitizer.rb +34 -39
- data/lib/odeon_uk/performance.rb +87 -0
- data/lib/odeon_uk/version.rb +2 -2
- data/odeon_uk.gemspec +19 -21
- data/rake/fixture_creator.rb +5 -57
- data/test/fixtures/api/all_cinemas.plist +0 -0
- data/test/fixtures/api/app_init.plist +0 -0
- data/test/fixtures/api/film_times/71-14876.plist +0 -0
- data/test/fixtures/api/film_times/71-15408.plist +0 -0
- data/test/fixtures/api/film_times/71-15684.plist +0 -0
- data/test/fixtures/api/film_times/71-15866.plist +0 -0
- data/test/fixtures/api/film_times/71-15868.plist +0 -0
- data/test/fixtures/api/film_times/71-15961.plist +0 -0
- data/test/fixtures/api/film_times/71-15963.plist +0 -0
- data/test/fixtures/api/film_times/71-15965.plist +0 -0
- data/test/fixtures/api/film_times/71-15967.plist +0 -0
- data/test/fixtures/api/film_times/71-15969.plist +0 -0
- data/test/fixtures/api/film_times/71-15977.plist +0 -0
- data/test/fixtures/api/film_times/71-15980.plist +0 -0
- data/test/fixtures/api/film_times/71-16037.plist +0 -0
- data/test/fixtures/api/film_times/71-16136.plist +0 -0
- data/test/fixtures/api/film_times/71-16142.plist +0 -0
- data/test/fixtures/api/film_times/71-16143.plist +0 -0
- data/test/fixtures/api/film_times/71-16187.plist +0 -0
- data/test/fixtures/api/film_times/71-16369.plist +0 -0
- data/test/fixtures/api/film_times/71-16370.plist +0 -0
- data/test/fixtures/api/film_times/71-16374.plist +0 -0
- data/test/fixtures/api/film_times/71-16386.plist +0 -0
- data/test/fixtures/api/film_times/71-16387.plist +0 -0
- data/test/fixtures/api/film_times/71-16388.plist +0 -0
- data/test/fixtures/api/film_times/71-16438.plist +0 -0
- data/test/fixtures/api/film_times/71-16454.plist +0 -0
- data/test/fixtures/api/film_times/71-16457.plist +0 -0
- data/test/fixtures/api/film_times/71-16477.plist +0 -0
- data/test/fixtures/api/film_times/71-16478.plist +0 -0
- data/test/fixtures/api/film_times/71-16480.plist +0 -0
- data/test/fixtures/api/film_times/71-16482.plist +0 -0
- data/test/fixtures/api/film_times/71-16489.plist +0 -0
- data/test/lib/odeon_uk/cinema_test.rb +154 -373
- data/test/lib/odeon_uk/{api/response_test.rb → internal/api_response_test.rb} +7 -4
- data/test/lib/odeon_uk/performance_test.rb +149 -0
- data/test/lib/odeon_uk/version_test.rb +3 -5
- data/test/support/api_fixtures_helper.rb +9 -3
- data/test/support/fake_api_response.rb +17 -0
- data/test/test_helper.rb +9 -3
- metadata +89 -145
- data/.rdoc_options +0 -16
- data/lib/odeon_uk/api/cinema.rb +0 -67
- data/lib/odeon_uk/api/screenings.rb +0 -103
- data/lib/odeon_uk/configuration.rb +0 -21
- data/lib/odeon_uk/html/cinema.rb +0 -101
- data/lib/odeon_uk/html/parser/film_with_screenings.rb +0 -160
- data/lib/odeon_uk/html/screenings.rb +0 -38
- data/lib/odeon_uk/html/website.rb +0 -38
- data/lib/odeon_uk/screening.rb +0 -71
- data/test/fixtures/api/film_times/71-100747.plist +0 -0
- data/test/fixtures/api/film_times/71-100750.plist +0 -0
- data/test/fixtures/api/film_times/71-100790.plist +0 -0
- data/test/fixtures/api/film_times/71-14646.plist +0 -0
- data/test/fixtures/api/film_times/71-14725.plist +0 -0
- data/test/fixtures/api/film_times/71-15086.plist +0 -0
- data/test/fixtures/api/film_times/71-15096.plist +0 -0
- data/test/fixtures/api/film_times/71-15122.plist +0 -0
- data/test/fixtures/api/film_times/71-15130.plist +0 -0
- data/test/fixtures/api/film_times/71-15141.plist +0 -0
- data/test/fixtures/api/film_times/71-15142.plist +0 -0
- data/test/fixtures/api/film_times/71-15143.plist +0 -0
- data/test/fixtures/api/film_times/71-15144.plist +0 -0
- data/test/fixtures/api/film_times/71-15145.plist +0 -0
- data/test/fixtures/api/film_times/71-15170.plist +0 -0
- data/test/fixtures/api/film_times/71-15172.plist +0 -0
- data/test/fixtures/api/film_times/71-15177.plist +0 -0
- data/test/fixtures/api/film_times/71-15179.plist +0 -0
- data/test/fixtures/api/film_times/71-15182.plist +0 -0
- data/test/fixtures/api/film_times/71-15286.plist +0 -0
- data/test/fixtures/api/film_times/71-15360.plist +0 -0
- data/test/fixtures/api/film_times/71-15586.plist +0 -0
- data/test/fixtures/api/film_times/71-15700.plist +0 -0
- data/test/fixtures/api/film_times/71-15718.plist +0 -0
- data/test/fixtures/api/film_times/71-15768.plist +0 -0
- data/test/fixtures/api/film_times/71-15788.plist +0 -0
- data/test/fixtures/api/film_times/71-15793.plist +0 -0
- data/test/fixtures/api/film_times/71-15794.plist +0 -0
- data/test/fixtures/api/film_times/71-15795.plist +0 -0
- data/test/fixtures/api/film_times/71-15796.plist +0 -0
- data/test/fixtures/api/film_times/71-15799.plist +0 -0
- data/test/fixtures/api/film_times/71-15802.plist +0 -0
- data/test/fixtures/api/film_times/71-15814.plist +0 -0
- data/test/fixtures/api/film_times/71-15817.plist +0 -0
- data/test/fixtures/api/film_times/71-15840.plist +0 -0
- data/test/fixtures/html/cinema/105.html +0 -2622
- data/test/fixtures/html/cinema/211.html +0 -3241
- data/test/fixtures/html/cinema/71.html +0 -3448
- data/test/fixtures/html/showtimes/11-imax.html +0 -170
- data/test/fixtures/html/showtimes/171-d-box.html +0 -203
- data/test/fixtures/html/showtimes/71-0.html +0 -59
- data/test/fixtures/html/showtimes/71.html +0 -2395
- data/test/fixtures/html/sitemap.html +0 -1303
- data/test/lib/odeon_uk/api/cinema_test.rb +0 -165
- data/test/lib/odeon_uk/api/screenings_test.rb +0 -58
- data/test/lib/odeon_uk/configuration_test.rb +0 -29
- data/test/lib/odeon_uk/html/cinema_test.rb +0 -149
- data/test/lib/odeon_uk/html/parser/film_with_screenings_test.rb +0 -97
- data/test/lib/odeon_uk/html/screenings_test.rb +0 -44
- data/test/lib/odeon_uk/html/website_test.rb +0 -67
- data/test/lib/odeon_uk/screening_test.rb +0 -92
- data/test/support/website_fixtures_helper.rb +0 -30
@@ -0,0 +1,34 @@
|
|
1
|
+
module OdeonUk
|
2
|
+
# @api private
|
3
|
+
module Internal
|
4
|
+
module Parser
|
5
|
+
module Api
|
6
|
+
# Parses a string to derive address
|
7
|
+
class FilmLookup
|
8
|
+
# @param [Integer] cinema_id id of the cinema
|
9
|
+
# @return [Hash{Integer => OdeonUk::Internal::Parser::Api::Film}]
|
10
|
+
# contains all films keyed by id for a cinema
|
11
|
+
def at(cinema_id)
|
12
|
+
to_hash.select do |_, film_hash|
|
13
|
+
film_hash['sites'].include?(cinema_id)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Hash{Integer => OdeonUk::Internal::Parser::Api::Film}]
|
18
|
+
# contains all films & upcoming films keyed by id
|
19
|
+
def to_hash
|
20
|
+
@to_hash ||= api.each_with_object({}) do |film_hash, result|
|
21
|
+
result[film_hash['filmMasterId'].to_i] = film_hash
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def api
|
28
|
+
@api ||= OdeonUk::Internal::ApiResponse.new.app_init['films']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module OdeonUk
|
2
|
+
# @api private
|
3
|
+
module Internal
|
4
|
+
module Parser
|
5
|
+
module Api
|
6
|
+
# A single day of performances for a particular film
|
7
|
+
class PerformanceDay
|
8
|
+
def initialize(data)
|
9
|
+
@data = data
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_a
|
13
|
+
performance_kinds.each_with_index.flat_map do |_, index|
|
14
|
+
starting_times(index).map do |time|
|
15
|
+
{
|
16
|
+
dimension: dimension(index),
|
17
|
+
starting_at: TimeParser.new(date, time).to_utc,
|
18
|
+
variant: variant(index)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def date
|
27
|
+
@data['date']
|
28
|
+
end
|
29
|
+
|
30
|
+
def dimension(index)
|
31
|
+
performance_kind(index).include?('3D') ? '3d' : '2d'
|
32
|
+
end
|
33
|
+
|
34
|
+
def performance_kinds
|
35
|
+
@data['attributes']
|
36
|
+
end
|
37
|
+
|
38
|
+
def performance_kind(index)
|
39
|
+
performance_kinds[index]['attribute']
|
40
|
+
end
|
41
|
+
|
42
|
+
def starting_times(index)
|
43
|
+
performance_kinds[index]['showtimes'][0].map do |h|
|
44
|
+
h['performanceTime']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def variant(index)
|
49
|
+
{
|
50
|
+
'Culture' => 'arts',
|
51
|
+
'Kids' => 'kids',
|
52
|
+
'IMAX' => 'imax',
|
53
|
+
'Newbies' => 'baby',
|
54
|
+
'Silver Cinema' => 'senior'
|
55
|
+
}.select { |k, _| performance_kind(index).include?(k) }.values.uniq
|
56
|
+
end
|
57
|
+
|
58
|
+
# parse a time to utc time
|
59
|
+
TimeParser = Struct.new(:date, :time) do
|
60
|
+
def to_utc
|
61
|
+
tz.local_to_utc(parsed_time)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def early_morning_screening?
|
67
|
+
time.match(/\A00/)
|
68
|
+
end
|
69
|
+
|
70
|
+
def parsed_date
|
71
|
+
case date
|
72
|
+
when 'Today' then Time.now.strftime '%Y-%m-%d'
|
73
|
+
when 'Tomorrow' then (Time.now + 60 * 60 * 24).strftime '%Y-%m-%d'
|
74
|
+
else date.gsub('.', '').match(/\d+\s\w+\z/)[0]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def parsed_time
|
79
|
+
parsed_time = Time.parse("#{parsed_date} #{time} UTC")
|
80
|
+
# Odeon deliberately mislabel their 00:01 screenings as the day before
|
81
|
+
early_morning_screening? ? parsed_time + 60 * 60 * 24 : parsed_time
|
82
|
+
end
|
83
|
+
|
84
|
+
def tz
|
85
|
+
@tz ||= TZInfo::Timezone.get('Europe/London')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -3,49 +3,44 @@ module OdeonUk
|
|
3
3
|
# @api private
|
4
4
|
module Internal
|
5
5
|
# Sanitize and standardize film titles
|
6
|
-
class TitleSanitizer
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
/\ACinemagic \d{1,4} \-/, # cinemagic
|
12
|
-
/\(encore.+\)/i, # encore for NT Live
|
13
|
-
/\(live\)/i, # live in brackets
|
14
|
-
'UKJFF -', # UK Jewish festival prefix
|
15
|
-
/\bsing\-?a\-?long\b/i, # singalong
|
16
|
-
'Autism Friendly - ', # autism friendly
|
17
|
-
'amp;', # html ampersands
|
18
|
-
]
|
6
|
+
class TitleSanitizer < Cinebase::TitleSanitizer
|
7
|
+
# @!method initialize(title)
|
8
|
+
# Constructor
|
9
|
+
# @param [String] title a film title
|
10
|
+
# @return [CineworldUk::Internal::TitleSanitizer]
|
19
11
|
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
/National Theatre Live - (.*)/ => 'National Theatre: ',
|
26
|
-
/NT Live - (.*)/ => 'National Theatre: ',
|
27
|
-
/ROH - (.*)/ => 'Royal Opera House: ',
|
28
|
-
/(.*)\- RSC Live \d{1,4}/ => 'Royal Shakespeare Company: '
|
29
|
-
}
|
12
|
+
# @!method sanitized
|
13
|
+
# sanitized and standardized title
|
14
|
+
# @return [String] sanitised title
|
15
|
+
|
16
|
+
private
|
30
17
|
|
31
|
-
#
|
32
|
-
def
|
33
|
-
|
18
|
+
# strings and regex to be removed
|
19
|
+
def remove
|
20
|
+
[
|
21
|
+
/\s+[23][dD]/, # dimension
|
22
|
+
'Autism Friendly Screening -', # autism screening
|
23
|
+
/\ACinemagic \d{1,4} \-/, # cinemagic
|
24
|
+
/\(encore.+\)/i, # encore for NT Live
|
25
|
+
/\(live\)/i, # live in brackets
|
26
|
+
'UKJFF -', # UK Jewish festival prefix
|
27
|
+
/\bsing\-?a\-?long\b/i, # singalong
|
28
|
+
'Autism Friendly - ', # autism friendly
|
29
|
+
'amp;', # html ampersands
|
30
|
+
]
|
34
31
|
end
|
35
32
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
sanitized.squeeze(' ').strip
|
48
|
-
end
|
33
|
+
# regexes and their replacements
|
34
|
+
def replace
|
35
|
+
{
|
36
|
+
/Bolshoi - (.*)/ => 'Bolshoi: ',
|
37
|
+
/Globe On Screen: (.*)/ => 'Globe: ',
|
38
|
+
/Met Opera - (.*)/ => 'Met Opera: ',
|
39
|
+
/National Theatre Live - (.*)/ => 'National Theatre: ',
|
40
|
+
/NT Live - (.*)/ => 'National Theatre: ',
|
41
|
+
/ROH - (.*)/ => 'Royal Opera House: ',
|
42
|
+
/(.*)\- RSC Live \d{1,4}/ => 'Royal Shakespeare Company: '
|
43
|
+
}
|
49
44
|
end
|
50
45
|
end
|
51
46
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module OdeonUk
|
2
|
+
# The object representing a single screening of a film on the Odeon UK website
|
3
|
+
class Performance < Cinebase::Performance
|
4
|
+
# @!attribute [r] booking_url
|
5
|
+
# @return [String] the booking URL on the cinema website
|
6
|
+
# @!attribute [r] cinema_name
|
7
|
+
# @return [String] the cinema name
|
8
|
+
# @!attribute [r] cinema_id
|
9
|
+
# @return [String] the cinema id
|
10
|
+
# @!attribute [r] dimension
|
11
|
+
# @return [String] 2d or 3d
|
12
|
+
# @!attribute [r] film_name
|
13
|
+
# @return [String] the film name
|
14
|
+
|
15
|
+
# @!method initialize(options)
|
16
|
+
# @param [Hash] options options hash
|
17
|
+
# @option options [String] :booking_url (nil) buying url for the screening
|
18
|
+
# @option options [String] :cinema_name name of the cinema
|
19
|
+
# @option options [String] :cinema_id website id of the cinema
|
20
|
+
# @option options [String] :dimension ('2d') dimension of the screening
|
21
|
+
# @option options [String] :film_name name of the film
|
22
|
+
# @option options [Time] :starting_at listed start time of the performance
|
23
|
+
|
24
|
+
# All currently listed films showing at a cinema
|
25
|
+
# @param [Integer] cinema_id id of the cinema on the website
|
26
|
+
# @return [Array<OdeonUk::Performance>]
|
27
|
+
def self.at(cinema_id)
|
28
|
+
film_ids_at(cinema_id).flat_map do |film_id|
|
29
|
+
api_response.film_times(cinema_id, film_id).flat_map do |day|
|
30
|
+
performance_days(day).map do |hash|
|
31
|
+
new(hash.merge(cinema_hash(cinema_id))
|
32
|
+
.merge(film_name: film_name(film_id)))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @!method showing_on
|
39
|
+
# The date of the screening
|
40
|
+
# @return [Date]
|
41
|
+
|
42
|
+
# @!method starting_at
|
43
|
+
# UTC time of the screening
|
44
|
+
# @return [Time]
|
45
|
+
|
46
|
+
# @!method variant
|
47
|
+
# The kinds of screening (IMAX, kids, baby, senior)
|
48
|
+
# @return <Array[String]>
|
49
|
+
|
50
|
+
# private
|
51
|
+
|
52
|
+
def self.api_response
|
53
|
+
@api_response ||= OdeonUk::Internal::ApiResponse.new
|
54
|
+
end
|
55
|
+
private_class_method :api_response
|
56
|
+
|
57
|
+
def self.cinema_hash(cinema_id)
|
58
|
+
{ cinema_id: cinema_id, cinema_name: Cinema.new(cinema_id).name }
|
59
|
+
end
|
60
|
+
private_class_method :cinema_hash
|
61
|
+
|
62
|
+
def self.films_at(cinema_id)
|
63
|
+
film_lookup.at(cinema_id)
|
64
|
+
end
|
65
|
+
private_class_method :films_at
|
66
|
+
|
67
|
+
def self.film_lookup
|
68
|
+
@film_lookup ||= OdeonUk::Internal::Parser::Api::FilmLookup.new
|
69
|
+
end
|
70
|
+
private_class_method :film_lookup
|
71
|
+
|
72
|
+
def self.film_ids_at(cinema_id)
|
73
|
+
films_at(cinema_id).keys
|
74
|
+
end
|
75
|
+
private_class_method :film_ids_at
|
76
|
+
|
77
|
+
def self.film_name(film_id)
|
78
|
+
film_lookup.to_hash[film_id]['title']
|
79
|
+
end
|
80
|
+
private_class_method :film_name
|
81
|
+
|
82
|
+
def self.performance_days(data)
|
83
|
+
OdeonUk::Internal::Parser::Api::PerformanceDay.new(data).to_a
|
84
|
+
end
|
85
|
+
private_class_method :performance_days
|
86
|
+
end
|
87
|
+
end
|
data/lib/odeon_uk/version.rb
CHANGED
data/odeon_uk.gemspec
CHANGED
@@ -1,29 +1,27 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'odeon_uk/version'
|
5
4
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'odeon_uk'
|
7
|
+
spec.version = OdeonUk::VERSION
|
8
|
+
spec.authors = ['Andy Croll']
|
9
|
+
spec.email = ['andy@goodscary.com']
|
10
|
+
spec.description = 'Pull movie & cinema information from the Odeon iOS API'
|
11
|
+
spec.summary = "It's a scraper, but a nice one"
|
12
|
+
spec.homepage = 'http://github.com/andycroll/odeon_uk'
|
13
|
+
spec.licenses = %w(AGPL MIT)
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
spec.files = `git ls-files`.split($RS)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
21
|
+
spec.add_development_dependency 'minitest-reporters'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'webmock'
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
gem.add_runtime_dependency 'tzinfo'
|
28
|
-
gem.add_runtime_dependency 'tzinfo-data'
|
25
|
+
spec.add_runtime_dependency 'CFPropertyList'
|
26
|
+
spec.add_runtime_dependency 'cinebase', '~> 3.0'
|
29
27
|
end
|
data/rake/fixture_creator.rb
CHANGED
@@ -9,7 +9,7 @@ module FixtureCreator
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def film_times!(cinema_id)
|
12
|
-
OdeonUk::
|
12
|
+
OdeonUk::Performance.send(:film_ids_at, cinema_id).each do |i|
|
13
13
|
write_film_times_fixture(cinema_id, i)
|
14
14
|
end
|
15
15
|
end
|
@@ -29,9 +29,9 @@ module FixtureCreator
|
|
29
29
|
text = "film_times/#{cinema_id}-#{film_id}"
|
30
30
|
File.open(fixture(text), 'w+') do |file|
|
31
31
|
log(text)
|
32
|
-
file.write OdeonUk::
|
33
|
-
|
34
|
-
|
32
|
+
file.write OdeonUk::Internal::ApiResponse.new.send(:film_times_raw,
|
33
|
+
cinema_id,
|
34
|
+
film_id)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,59 +39,7 @@ module FixtureCreator
|
|
39
39
|
FileUtils.mkdir_p kind.to_s
|
40
40
|
File.open(fixture(kind), 'w+') do |file|
|
41
41
|
log(kind)
|
42
|
-
file.write OdeonUk::
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Html < Struct.new(:cinema_id)
|
48
|
-
def cinema!
|
49
|
-
write_page_fixture(:cinema)
|
50
|
-
end
|
51
|
-
|
52
|
-
def film_node!(index)
|
53
|
-
write_node_fixture(index)
|
54
|
-
end
|
55
|
-
|
56
|
-
def showtimes!
|
57
|
-
write_page_fixture(:showtimes)
|
58
|
-
end
|
59
|
-
|
60
|
-
def sitemap!
|
61
|
-
write_page_fixture(:sitemap)
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def fixture(name)
|
67
|
-
File.expand_path("../../test/fixtures/html/#{name}.html", __FILE__)
|
68
|
-
end
|
69
|
-
|
70
|
-
def log(message)
|
71
|
-
puts "Create HTML fixture: #{message}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def write_node_fixture(index)
|
75
|
-
FileUtils.mkdir_p 'showtimes'
|
76
|
-
text = "showtimes/#{cinema_id}-#{index}"
|
77
|
-
File.open(fixture(text), 'w+') do |file|
|
78
|
-
log(text)
|
79
|
-
nodes = OdeonUk::Html::Screenings.send(:film_nodes, cinema_id)
|
80
|
-
node = if index.is_a?(Fixnum)
|
81
|
-
nodes[index]
|
82
|
-
else
|
83
|
-
nodes.select { |n| !!n.to_s.match(/#{index}/i) }[0]
|
84
|
-
end
|
85
|
-
file.write(node.to_s)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def write_page_fixture(kind)
|
90
|
-
FileUtils.mkdir_p kind.to_s
|
91
|
-
text = kind.to_s + (cinema_id ? "/#{cinema_id}" : '')
|
92
|
-
File.open(fixture(text), 'w+') do |file|
|
93
|
-
log(text)
|
94
|
-
file.write OdeonUk::Html::Website.new.send(*[kind, cinema_id].compact)
|
42
|
+
file.write OdeonUk::Internal::ApiResponse.new.send("#{kind}_raw".to_sym)
|
95
43
|
end
|
96
44
|
end
|
97
45
|
end
|
Binary file
|
Binary file
|