odeon_uk 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +6 -0
  4. data/Rakefile +29 -0
  5. data/lib/odeon_uk/api/cinema.rb +62 -0
  6. data/lib/odeon_uk/api/response.rb +55 -0
  7. data/lib/odeon_uk/api/screenings.rb +89 -0
  8. data/lib/odeon_uk/cinema.rb +53 -114
  9. data/lib/odeon_uk/configuration.rb +21 -0
  10. data/lib/odeon_uk/html/cinema.rb +101 -0
  11. data/lib/odeon_uk/html/parser/film_with_screenings.rb +160 -0
  12. data/lib/odeon_uk/html/screenings.rb +38 -0
  13. data/lib/odeon_uk/{internal → html}/website.rb +1 -1
  14. data/lib/odeon_uk/internal/title_sanitizer.rb +1 -0
  15. data/lib/odeon_uk/screening.rb +7 -15
  16. data/lib/odeon_uk/version.rb +2 -2
  17. data/lib/odeon_uk.rb +11 -4
  18. data/odeon_uk.gemspec +2 -0
  19. data/rake/fixture_creator.rb +98 -0
  20. data/test/fixtures/api/all_cinemas.plist +0 -0
  21. data/test/fixtures/api/app_init.plist +0 -0
  22. data/test/fixtures/api/film_times/71-100747.plist +0 -0
  23. data/test/fixtures/api/film_times/71-100750.plist +0 -0
  24. data/test/fixtures/api/film_times/71-100790.plist +0 -0
  25. data/test/fixtures/api/film_times/71-14646.plist +0 -0
  26. data/test/fixtures/api/film_times/71-14725.plist +0 -0
  27. data/test/fixtures/api/film_times/71-15086.plist +0 -0
  28. data/test/fixtures/api/film_times/71-15096.plist +0 -0
  29. data/test/fixtures/api/film_times/71-15122.plist +0 -0
  30. data/test/fixtures/api/film_times/71-15130.plist +0 -0
  31. data/test/fixtures/api/film_times/71-15141.plist +0 -0
  32. data/test/fixtures/api/film_times/71-15142.plist +0 -0
  33. data/test/fixtures/api/film_times/71-15143.plist +0 -0
  34. data/test/fixtures/api/film_times/71-15144.plist +0 -0
  35. data/test/fixtures/api/film_times/71-15145.plist +0 -0
  36. data/test/fixtures/api/film_times/71-15170.plist +0 -0
  37. data/test/fixtures/api/film_times/71-15172.plist +0 -0
  38. data/test/fixtures/api/film_times/71-15177.plist +0 -0
  39. data/test/fixtures/api/film_times/71-15179.plist +0 -0
  40. data/test/fixtures/api/film_times/71-15182.plist +0 -0
  41. data/test/fixtures/api/film_times/71-15286.plist +0 -0
  42. data/test/fixtures/api/film_times/71-15360.plist +0 -0
  43. data/test/fixtures/api/film_times/71-15586.plist +0 -0
  44. data/test/fixtures/api/film_times/71-15700.plist +0 -0
  45. data/test/fixtures/api/film_times/71-15718.plist +0 -0
  46. data/test/fixtures/api/film_times/71-15768.plist +0 -0
  47. data/test/fixtures/api/film_times/71-15788.plist +0 -0
  48. data/test/fixtures/api/film_times/71-15793.plist +0 -0
  49. data/test/fixtures/api/film_times/71-15794.plist +0 -0
  50. data/test/fixtures/api/film_times/71-15795.plist +0 -0
  51. data/test/fixtures/api/film_times/71-15796.plist +0 -0
  52. data/test/fixtures/api/film_times/71-15799.plist +0 -0
  53. data/test/fixtures/api/film_times/71-15802.plist +0 -0
  54. data/test/fixtures/api/film_times/71-15814.plist +0 -0
  55. data/test/fixtures/api/film_times/71-15817.plist +0 -0
  56. data/test/fixtures/api/film_times/71-15840.plist +0 -0
  57. data/test/fixtures/{cinema/leicester_square.html → html/cinema/105.html} +384 -313
  58. data/test/fixtures/{cinema/bfi_imax.html → html/cinema/211.html} +677 -355
  59. data/test/fixtures/{cinema/brighton.html → html/cinema/71.html} +899 -431
  60. data/test/fixtures/html/showtimes/11-imax.html +170 -0
  61. data/test/fixtures/html/showtimes/171-d-box.html +203 -0
  62. data/test/fixtures/html/showtimes/71-0.html +59 -0
  63. data/test/fixtures/html/showtimes/71.html +2395 -0
  64. data/test/fixtures/{sitemap.html → html/sitemap.html} +264 -352
  65. data/test/lib/odeon_uk/api/cinema_test.rb +149 -0
  66. data/test/lib/odeon_uk/api/response_test.rb +44 -0
  67. data/test/lib/odeon_uk/api/screenings_test.rb +43 -0
  68. data/test/lib/odeon_uk/cinema_test.rb +373 -148
  69. data/test/lib/odeon_uk/configuration_test.rb +29 -0
  70. data/test/lib/odeon_uk/html/cinema_test.rb +149 -0
  71. data/test/lib/odeon_uk/{internal/film_with_screenings_parser_test.rb → html/parser/film_with_screenings_test.rb} +12 -42
  72. data/test/lib/odeon_uk/html/screenings_test.rb +43 -0
  73. data/test/lib/odeon_uk/html/website_test.rb +37 -0
  74. data/test/lib/odeon_uk/screening_test.rb +17 -83
  75. data/test/support/api_fixtures_helper.rb +34 -0
  76. data/test/support/website_fixtures_helper.rb +25 -0
  77. data/test/test_helper.rb +7 -2
  78. metadata +149 -34
  79. data/lib/odeon_uk/film.rb +0 -65
  80. data/lib/odeon_uk/internal/film_with_screenings_parser.rb +0 -159
  81. data/lib/odeon_uk/internal/showtimes_page.rb +0 -36
  82. data/test/fixture_updater.rb +0 -72
  83. data/test/fixtures/showtimes/brighton/film_first.html +0 -92
  84. data/test/fixtures/showtimes/brighton/film_last.html +0 -100
  85. data/test/fixtures/showtimes/brighton.html +0 -2071
  86. data/test/fixtures/showtimes/liverpool_one/film_first_dbox.html +0 -188
  87. data/test/fixtures/showtimes/manchester/film_first_imax.html +0 -182
  88. data/test/lib/odeon_uk/film_test.rb +0 -142
  89. data/test/lib/odeon_uk/internal/showtimes_page_test.rb +0 -51
  90. data/test/lib/odeon_uk/internal/website_test.rb +0 -59
@@ -0,0 +1,149 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe OdeonUk::Html::Cinema do
4
+ include WebsiteFixturesHelper
5
+
6
+ let(:described_class) { OdeonUk::Html::Cinema }
7
+
8
+ let(:website) { Minitest::Mock.new }
9
+
10
+ before do
11
+ WebMock.disable_net_connect!
12
+ end
13
+
14
+ describe '.ids' do
15
+ subject { described_class.ids }
16
+
17
+ before do
18
+ website.expect(:sitemap, sitemap_html)
19
+ end
20
+
21
+ it 'returns an Array of OdeonUk::Html::Cinemas' do
22
+ OdeonUk::Html::Website.stub :new, website do
23
+ subject.must_be_instance_of(Array)
24
+ subject.each do |value|
25
+ value.must_be_instance_of(Fixnum)
26
+ end
27
+ end
28
+ end
29
+
30
+ it 'returns the correctly sized array' do
31
+ OdeonUk::Html::Website.stub :new, website do
32
+ subject.size.must_equal 115
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '.new(id)' do
38
+ subject { described_class.new(id) }
39
+
40
+ describe 'Brighton' do
41
+ let(:id) { 71 }
42
+
43
+ it 'returns a cinema' do
44
+ subject.must_be_instance_of(described_class)
45
+ subject.id.must_equal(id)
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#name' do
51
+ subject { described_class.new(id).name }
52
+
53
+ before { website.expect(:sitemap, sitemap_html) }
54
+
55
+ describe 'Brighton' do
56
+ let(:id) { 71 }
57
+
58
+ it 'returns cinema name' do
59
+ OdeonUk::Html::Website.stub :new, website do
60
+ subject.must_equal 'Brighton'
61
+ end
62
+ end
63
+ end
64
+
65
+ describe 'Leicester Square' do
66
+ let(:id) { 105 }
67
+
68
+ it 'returns cinema name' do
69
+ OdeonUk::Html::Website.stub :new, website do
70
+ subject.must_equal 'London - Leicester Square'
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '#locality' do
77
+ subject { described_class.new(id).locality }
78
+
79
+ before { website.expect(:sitemap, sitemap_html) }
80
+
81
+ describe 'Short Address (Brighton)' do
82
+ let(:id) { 71 }
83
+
84
+ before { website.expect(:cinema, cinema_html(71), [71]) }
85
+
86
+ it 'returns town name' do
87
+ OdeonUk::Html::Website.stub :new, website do
88
+ subject.must_equal 'Brighton'
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '#postal_code' do
95
+ subject { described_class.new(id).postal_code }
96
+
97
+ describe 'short address' do
98
+ let(:id) { 71 }
99
+
100
+ before { website.expect(:cinema, cinema_html(71), [71]) }
101
+
102
+ it 'returns the postcode' do
103
+ OdeonUk::Html::Website.stub :new, website do
104
+ subject.must_equal 'BN1 2RE'
105
+ end
106
+ end
107
+ end
108
+
109
+ describe 'short address (London)' do
110
+ let(:id) { 211 }
111
+
112
+ before { website.expect(:cinema, cinema_html(211), [211]) }
113
+
114
+ it 'returns the postcode' do
115
+ OdeonUk::Html::Website.stub :new, website do
116
+ subject.must_equal 'SE1 8XR'
117
+ end
118
+ end
119
+ end
120
+
121
+ describe 'short address (extra London Postcode)' do
122
+ let(:id) { 105 }
123
+
124
+ before { website.expect(:cinema, cinema_html(105), [105]) }
125
+
126
+ it 'returns the postcode' do
127
+ OdeonUk::Html::Website.stub :new, website do
128
+ subject.must_equal 'WC2H 7LQ'
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ describe '#street_address' do
135
+ subject { described_class.new(id).street_address }
136
+
137
+ describe 'short address' do
138
+ let(:id) { 71 }
139
+
140
+ before { website.expect(:cinema, cinema_html(71), [71]) }
141
+
142
+ it 'returns first line of address' do
143
+ OdeonUk::Html::Website.stub :new, website do
144
+ subject.must_equal 'Kingswest'
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -1,24 +1,18 @@
1
- require_relative '../../../test_helper'
1
+ require_relative '../../../../test_helper'
2
2
 
3
- describe OdeonUk::Internal::FilmWithScreeningsParser do
4
- let(:described_class) { OdeonUk::Internal::FilmWithScreeningsParser }
3
+ describe OdeonUk::Html::Parser::FilmWithScreenings do
4
+ include WebsiteFixturesHelper
5
+
6
+ let(:described_class) { OdeonUk::Html::Parser::FilmWithScreenings }
5
7
 
6
8
  describe '#film_name' do
7
9
  subject { described_class.new(film_html).film_name }
8
10
 
9
- describe 'passed first film html' do
10
- let(:film_html) { read_film_html('brighton/film_first') }
11
-
12
- it 'returns film name' do
13
- subject.must_equal 'A Most Wanted Man'
14
- end
15
- end
16
-
17
- describe 'passed last film html' do
18
- let(:film_html) { read_film_html('brighton/film_last') }
11
+ describe 'passed film html' do
12
+ let(:film_html) { showtimes_html('71-0') }
19
13
 
20
14
  it 'returns film name' do
21
- subject.must_equal 'The Riot Club'
15
+ subject.must_equal 'Home'
22
16
  end
23
17
  end
24
18
  end
@@ -26,8 +20,8 @@ describe OdeonUk::Internal::FilmWithScreeningsParser do
26
20
  describe '#to_a' do
27
21
  subject { described_class.new(film_html).to_a }
28
22
 
29
- describe 'passed first film html' do
30
- let(:film_html) { read_film_html('brighton/film_first') }
23
+ describe 'passed film html' do
24
+ let(:film_html) { showtimes_html('71-0') }
31
25
 
32
26
  it 'returns an array of hashes of screening attributes' do
33
27
  subject.must_be_instance_of Array
@@ -47,32 +41,13 @@ describe OdeonUk::Internal::FilmWithScreeningsParser do
47
41
  end
48
42
  end
49
43
 
50
- it 'returns the correct number of screenings' do
51
- subject.count.must_equal 10
52
- end
53
- end
54
-
55
- describe 'passed last film html' do
56
- let(:film_html) { read_film_html('brighton/film_last') }
57
-
58
- it 'returns an array of hashes of screening attributes' do
59
- subject.must_be_instance_of Array
60
- subject.each do |hash|
61
- hash[:booking_url].must_match 'https://www.odeon.co.uk/'
62
- hash[:dimension].must_match(/[23]d/)
63
- hash[:film_name].must_be_instance_of String
64
- hash[:time].must_be_instance_of Time
65
- hash[:time].zone.must_equal 'UTC'
66
- end
67
- end
68
-
69
44
  it 'returns at least 1' do
70
45
  subject.count.must_be :>=, 1
71
46
  end
72
47
  end
73
48
 
74
49
  describe 'passed imax film html' do
75
- let(:film_html) { read_film_html('manchester/film_first_imax') }
50
+ let(:film_html) { showtimes_html('11-imax') }
76
51
 
77
52
  it 'returns an array of hashes of screening attributes' do
78
53
  subject.must_be_instance_of Array
@@ -96,7 +71,7 @@ describe OdeonUk::Internal::FilmWithScreeningsParser do
96
71
  end
97
72
 
98
73
  describe 'passed d-box film html' do
99
- let(:film_html) { read_film_html('liverpool_one/film_first_dbox') }
74
+ let(:film_html) { showtimes_html('171-d-box') }
100
75
 
101
76
  it 'returns an array of hashes of screening attributes' do
102
77
  subject.must_be_instance_of Array
@@ -119,9 +94,4 @@ describe OdeonUk::Internal::FilmWithScreeningsParser do
119
94
  end
120
95
  end
121
96
  end
122
-
123
- def read_film_html(filename)
124
- path = '../../../../fixtures/showtimes'
125
- File.read(File.expand_path("#{path}/#{filename}.html", __FILE__))
126
- end
127
97
  end
@@ -0,0 +1,43 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe OdeonUk::Html::Screenings do
4
+ include WebsiteFixturesHelper
5
+
6
+ let(:described_class) { OdeonUk::Html::Screenings }
7
+
8
+ let(:website) { Minitest::Mock.new }
9
+
10
+ before { WebMock.disable_net_connect! }
11
+
12
+ describe '.at(cinema_id)' do
13
+ subject { described_class.at(71) }
14
+
15
+ before do
16
+ website.expect(:showtimes, showtimes_html(71), [71])
17
+ end
18
+
19
+ it 'returns an array of screening attributes as hashes' do
20
+ OdeonUk::Html::Website.stub :new, website do
21
+ subject.must_be_instance_of(Array)
22
+ subject.each do |screening|
23
+ screening.must_be_instance_of(Hash)
24
+ screening.keys.must_include(:film_name)
25
+
26
+ screening.keys.must_include(:time)
27
+ screening[:time].must_be_instance_of(Time)
28
+
29
+ screening.keys.must_include(:variant)
30
+
31
+ screening.keys.must_include(:dimension)
32
+ screening[:dimension].must_match(/[23]d/)
33
+ end
34
+ end
35
+ end
36
+
37
+ it 'returns correct number of screenings' do
38
+ OdeonUk::Html::Website.stub :new, website do
39
+ subject.count.must_equal 212
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe OdeonUk::Html::Website do
4
+ include WebsiteFixturesHelper
5
+
6
+ let(:described_class) { OdeonUk::Html::Website }
7
+
8
+ describe '#cinema(id)' do
9
+ subject { described_class.new.cinema(71) }
10
+
11
+ before { stub_get('cinemas/odeon/71/', cinema_html(71)) }
12
+
13
+ it 'returns a string' do
14
+ subject.class.must_equal String
15
+ end
16
+ end
17
+
18
+ describe '#sitemap' do
19
+ subject { described_class.new.sitemap }
20
+
21
+ before { stub_get('sitemap/', sitemap_html) }
22
+
23
+ it 'returns a string' do
24
+ subject.class.must_equal String
25
+ end
26
+ end
27
+
28
+ describe '#showtimes(id)' do
29
+ subject { described_class.new.showtimes(71) }
30
+
31
+ before { stub_get('showtimes/week/71/?siteId=71', showtimes_html(71)) }
32
+
33
+ it 'returns a string' do
34
+ subject.class.must_equal String
35
+ end
36
+ end
37
+ end
@@ -1,109 +1,43 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  describe OdeonUk::Screening do
4
+ include WebsiteFixturesHelper
5
+
4
6
  let(:described_class) { OdeonUk::Screening }
5
7
 
6
8
  let(:website) { Minitest::Mock.new }
7
9
 
8
- before { WebMock.disable_net_connect! }
10
+ before do
11
+ WebMock.disable_net_connect!
12
+ end
9
13
 
10
14
  describe '.at(cinema_id)' do
11
15
  subject { described_class.at(71) }
12
16
 
13
17
  before do
14
- website.expect(:showtimes, brighton_showtimes_html, [71])
15
- website.expect(:sitemap, sitemap_html)
18
+ website.expect(:cinema, cinema_html(71), [71])
19
+ website.expect(:showtimes, showtimes_html(71), [71])
16
20
  end
17
21
 
18
- it 'returns an array of screenings' do
19
- OdeonUk::Internal::Website.stub :new, website do
22
+ it 'returns an array of screening attributes as hashes' do
23
+ OdeonUk::Html::Website.stub :new, website do
20
24
  subject.must_be_instance_of(Array)
21
25
  subject.each do |screening|
22
26
  screening.must_be_instance_of(described_class)
27
+ screening.cinema_name.must_equal('Brighton')
28
+ screening.cinema_id.must_equal(71)
29
+ screening.film_name.wont_be_nil
30
+ screening.showing_at.must_be_instance_of(Time)
31
+ screening.showing_on.must_be_instance_of(Date)
32
+ screening.dimension.must_match(/[23]d/)
23
33
  end
24
34
  end
25
35
  end
26
36
 
27
37
  it 'returns correct number of screenings' do
28
- OdeonUk::Internal::Website.stub :new, website do
29
- subject.count.must_equal 214
38
+ OdeonUk::Html::Website.stub :new, website do
39
+ subject.count.must_equal 212
30
40
  end
31
41
  end
32
42
  end
33
-
34
- describe '#showing_on' do
35
- subject { described_class.new(options).showing_on }
36
-
37
- let(:options) do
38
- {
39
- film_name: 'Guardians of the Galaxy',
40
- cinema_id: 71,
41
- cinema_name: 'Odeon Brighton',
42
- time: Time.utc(2014, 9, 12, 11, 0),
43
- }
44
- end
45
-
46
- it 'should return date of screening' do
47
- subject.must_be_instance_of(Date)
48
- subject.must_equal Date.new(2014, 9, 12)
49
- end
50
- end
51
-
52
- describe '#variant' do
53
- subject { described_class.new(options).variant }
54
-
55
- describe 'passed array' do
56
- let(:options) do
57
- {
58
- film_name: 'Guardians of the Galaxy',
59
- cinema_id: 71,
60
- cinema_name: 'Odeon Brighton',
61
- time: Time.utc(2014, 9, 12, 11, 0),
62
- variant: %w(Kids BABY)
63
- }
64
- end
65
-
66
- it 'is an alphabetically ordered array of lower-cased strings' do
67
- subject.must_be_instance_of Array
68
- subject.each do |tag|
69
- tag.must_be_instance_of String
70
- end
71
- subject.must_equal %w(baby kids)
72
- end
73
- end
74
-
75
- describe 'passed string' do
76
- let(:options) do
77
- {
78
- film_name: 'Guardians of the Galaxy',
79
- cinema_id: 71,
80
- cinema_name: 'Odeon Brighton',
81
- time: Time.utc(2014, 9, 12, 11, 0),
82
- variant: 'Kids BABY'
83
- }
84
- end
85
-
86
- it 'is an alphabetically ordered array of lower-cased strings' do
87
- subject.must_be_instance_of Array
88
- subject.each do |tag|
89
- tag.must_be_instance_of String
90
- end
91
- subject.must_equal %w(baby kids)
92
- end
93
- end
94
- end
95
-
96
- private
97
-
98
- def brighton_showtimes_html
99
- read_file('../../../fixtures/showtimes/brighton.html')
100
- end
101
-
102
- def read_file(filepath)
103
- File.read(File.expand_path(filepath, __FILE__))
104
- end
105
-
106
- def sitemap_html
107
- read_file('../../../fixtures/sitemap.html')
108
- end
109
43
  end
@@ -0,0 +1,34 @@
1
+ module ApiFixturesHelper
2
+ private
3
+
4
+ def all_cinemas_plist
5
+ read_fixture('api/all_cinemas')
6
+ end
7
+
8
+ def app_init_plist
9
+ read_fixture('api/app_init')
10
+ end
11
+
12
+ def film_times_plist(cinema_id, film_id)
13
+ read_fixture("api/film_times/#{cinema_id}-#{film_id}")
14
+ end
15
+
16
+ def film_times_plists(cinema_id)
17
+ listing = Dir.entries(File.expand_path('../../fixtures/api/film_times', __FILE__))
18
+ listing.reject { |filename| !filename.match(/\A#{cinema_id}-/) }
19
+ end
20
+
21
+ def parse(content)
22
+ CFPropertyList.native_types(CFPropertyList::List.new(data: content).value)
23
+ end
24
+
25
+ def read_fixture(filepath)
26
+ File.read(File.expand_path("../../fixtures/#{filepath}.plist", __FILE__))
27
+ end
28
+
29
+ def stub_post(site_path, request_body, response_body)
30
+ url = "https://api.odeon.co.uk/2.1/api/#{site_path}"
31
+ response = { status: 200, body: response_body, headers: {} }
32
+ stub_request(:post, url).with(body: request_body).to_return(response)
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ module WebsiteFixturesHelper
2
+ private
3
+
4
+ def cinema_html(id)
5
+ read_fixture("html/cinema/#{id}")
6
+ end
7
+
8
+ def showtimes_html(id, i = nil)
9
+ read_fixture("html/showtimes/#{id}#{ "-#{i}" if i }")
10
+ end
11
+
12
+ def sitemap_html
13
+ read_fixture('html/sitemap')
14
+ end
15
+
16
+ def read_fixture(filepath)
17
+ File.read(File.expand_path("../../fixtures/#{filepath}.html", __FILE__))
18
+ end
19
+
20
+ def stub_get(site_path, response_body)
21
+ url = "http://www.odeon.co.uk/#{site_path}"
22
+ response = { status: 200, body: response_body, headers: {} }
23
+ stub_request(:get, url).to_return(response)
24
+ end
25
+ end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  require 'minitest/autorun'
2
- require 'minitest/pride'
2
+ require 'minitest/reporters'
3
+ reporter_options = { color: true, slow_count: 5 }
4
+ Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(reporter_options)]
3
5
 
4
6
  require 'webmock/minitest'
5
7
 
6
- require File.expand_path('../../lib/odeon_uk.rb', __FILE__)
8
+ require File.expand_path('../../lib/odeon_uk.rb', __FILE__)
9
+
10
+ require_relative 'support/api_fixtures_helper'
11
+ require_relative 'support/website_fixtures_helper'