odeon_uk 2.0.4 → 3.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 (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::Api::Cinema do
4
+ include ApiFixturesHelper
5
+
6
+ let(:described_class) { OdeonUk::Api::Cinema }
7
+
8
+ let(:response) { 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
+ response.expect(:all_cinemas, parse(all_cinemas_plist))
19
+ end
20
+
21
+ it 'returns an Array of integers' do
22
+ OdeonUk::Api::Response.stub :new, response 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::Api::Response.stub :new, response 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 { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
54
+
55
+ describe 'Brighton' do
56
+ let(:id) { 71 }
57
+
58
+ it 'returns cinema name' do
59
+ OdeonUk::Api::Response.stub :new, response 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::Api::Response.stub :new, response 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 { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
80
+
81
+ describe 'Short Address (Brighton)' do
82
+ let(:id) { 71 }
83
+
84
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
85
+
86
+ it 'returns town name' do
87
+ OdeonUk::Api::Response.stub :new, response 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 { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
101
+
102
+ it 'returns the postcode' do
103
+ OdeonUk::Api::Response.stub :new, response 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 { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
113
+
114
+ it 'returns the postcode' do
115
+ OdeonUk::Api::Response.stub :new, response 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 { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
125
+
126
+ it 'returns the postcode' do
127
+ OdeonUk::Api::Response.stub :new, response 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 { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
141
+
142
+ it 'returns first line of address' do
143
+ OdeonUk::Api::Response.stub :new, response do
144
+ subject.must_equal 'Kingswest'
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe OdeonUk::Api::Response do
4
+ include ApiFixturesHelper
5
+
6
+ let(:described_class) { OdeonUk::Api::Response }
7
+
8
+ describe '#app_init' do
9
+ subject { described_class.new.app_init }
10
+
11
+ before { stub_post('app-init', nil, app_init_plist) }
12
+
13
+ it 'returns a hash' do
14
+ subject.class.must_equal Hash
15
+ subject.keys.must_equal(%w(films offers))
16
+ end
17
+ end
18
+
19
+ describe '#all_cinemas' do
20
+ subject { described_class.new.all_cinemas }
21
+
22
+ before { stub_post('all-cinemas', nil, all_cinemas_plist) }
23
+
24
+ it 'returns a hash' do
25
+ subject.class.must_equal Hash
26
+ subject.keys.must_equal(%w(sites))
27
+ end
28
+ end
29
+
30
+ describe '#showtimes(id)' do
31
+ subject { described_class.new.film_times(71, 15130) }
32
+
33
+ before do
34
+ stub_post('film-times',
35
+ { s: '71', m: '15130' },
36
+ film_times_plist(71, 15130))
37
+ end
38
+
39
+ it 'returns an array' do
40
+ subject.class.must_equal Array
41
+ subject.each { |group| group.keys.must_equal(%w(date attributes)) }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe OdeonUk::Api::Screenings do
4
+ include ApiFixturesHelper
5
+
6
+ let(:described_class) { OdeonUk::Api::Screenings }
7
+
8
+ before { WebMock.disable_net_connect! }
9
+
10
+ describe '.at(cinema_id)' do
11
+ subject { described_class.at(71) }
12
+
13
+ before do
14
+ stub_post('app-init', nil, app_init_plist)
15
+ film_times_plists(71).each do |name|
16
+ film_id = name.match(/(\d+)\.plist/)[1]
17
+ stub_post('film-times',
18
+ { s: '71', m: film_id },
19
+ film_times_plist(71, film_id))
20
+ end
21
+ end
22
+
23
+ it 'returns an array of screening attributes as hashes' do
24
+ subject.must_be_instance_of(Array)
25
+ subject.each do |screening|
26
+ screening.must_be_instance_of(Hash)
27
+ screening.keys.must_include(:film_name)
28
+
29
+ screening.keys.must_include(:time)
30
+ screening[:time].must_be_instance_of(Time)
31
+
32
+ screening.keys.must_include(:variant)
33
+
34
+ screening.keys.must_include(:dimension)
35
+ screening[:dimension].must_match(/[23]d/)
36
+ end
37
+ end
38
+
39
+ it 'returns correct number of screenings' do
40
+ subject.count.must_equal 159
41
+ end
42
+ end
43
+ end