odeon_uk 4.0.1 → 5.1.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 (73) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/release.yml +73 -0
  3. data/.github/workflows/test.yml +43 -0
  4. data/.gitignore +1 -1
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +36 -0
  7. data/README.md +100 -21
  8. data/Rakefile +14 -15
  9. data/lib/odeon_uk/cinema.rb +40 -22
  10. data/lib/odeon_uk/internal/api_response.rb +19 -39
  11. data/lib/odeon_uk/internal/guest_token.rb +23 -0
  12. data/lib/odeon_uk/internal/parser/api/showtime.rb +81 -0
  13. data/lib/odeon_uk/internal/title_sanitizer.rb +3 -8
  14. data/lib/odeon_uk/performance.rb +34 -41
  15. data/lib/odeon_uk/version.rb +3 -3
  16. data/lib/odeon_uk.rb +16 -2
  17. data/odeon_uk.gemspec +10 -6
  18. data/test/fixtures/api/showtimes-824.json +66 -0
  19. data/test/fixtures/api/sites.json +32 -0
  20. data/test/lib/odeon_uk/cinema_test.rb +66 -215
  21. data/test/lib/odeon_uk/internal/api_response_test.rb +48 -29
  22. data/test/lib/odeon_uk/internal/fixture_shape_test.rb +14 -0
  23. data/test/lib/odeon_uk/internal/guest_token_test.rb +84 -0
  24. data/test/lib/odeon_uk/internal/parser/api/showtime_test.rb +77 -0
  25. data/test/lib/odeon_uk/internal/title_sanitizer_test.rb +109 -89
  26. data/test/lib/odeon_uk/performance_test.rb +129 -146
  27. data/test/lib/odeon_uk/version_test.rb +3 -3
  28. data/test/live/api_shape_test.rb +19 -0
  29. data/test/live/integration_test.rb +21 -0
  30. data/test/live/live_helper.rb +11 -0
  31. data/test/package_test.rb +56 -0
  32. data/test/support/api_fixtures_helper.rb +5 -30
  33. data/test/support/api_shapes.rb +46 -0
  34. data/test/support/fake_api_response.rb +9 -6
  35. data/test/test_helper.rb +6 -3
  36. metadata +67 -89
  37. data/.travis.yml +0 -7
  38. data/lib/odeon_uk/internal/parser/api/film_lookup.rb +0 -34
  39. data/lib/odeon_uk/internal/parser/api/performance_day.rb +0 -92
  40. data/rake/fixture_creator.rb +0 -46
  41. data/test/fixtures/api/all_cinemas.plist +0 -0
  42. data/test/fixtures/api/app_init.plist +0 -0
  43. data/test/fixtures/api/film_times/71-14876.plist +0 -0
  44. data/test/fixtures/api/film_times/71-15408.plist +0 -0
  45. data/test/fixtures/api/film_times/71-15684.plist +0 -0
  46. data/test/fixtures/api/film_times/71-15866.plist +0 -0
  47. data/test/fixtures/api/film_times/71-15868.plist +0 -0
  48. data/test/fixtures/api/film_times/71-15961.plist +0 -0
  49. data/test/fixtures/api/film_times/71-15963.plist +0 -0
  50. data/test/fixtures/api/film_times/71-15965.plist +0 -0
  51. data/test/fixtures/api/film_times/71-15967.plist +0 -0
  52. data/test/fixtures/api/film_times/71-15969.plist +0 -0
  53. data/test/fixtures/api/film_times/71-15977.plist +0 -0
  54. data/test/fixtures/api/film_times/71-15980.plist +0 -0
  55. data/test/fixtures/api/film_times/71-16037.plist +0 -0
  56. data/test/fixtures/api/film_times/71-16136.plist +0 -0
  57. data/test/fixtures/api/film_times/71-16142.plist +0 -0
  58. data/test/fixtures/api/film_times/71-16143.plist +0 -0
  59. data/test/fixtures/api/film_times/71-16187.plist +0 -0
  60. data/test/fixtures/api/film_times/71-16369.plist +0 -0
  61. data/test/fixtures/api/film_times/71-16370.plist +0 -0
  62. data/test/fixtures/api/film_times/71-16374.plist +0 -0
  63. data/test/fixtures/api/film_times/71-16386.plist +0 -0
  64. data/test/fixtures/api/film_times/71-16387.plist +0 -0
  65. data/test/fixtures/api/film_times/71-16388.plist +0 -0
  66. data/test/fixtures/api/film_times/71-16438.plist +0 -0
  67. data/test/fixtures/api/film_times/71-16454.plist +0 -0
  68. data/test/fixtures/api/film_times/71-16457.plist +0 -0
  69. data/test/fixtures/api/film_times/71-16477.plist +0 -0
  70. data/test/fixtures/api/film_times/71-16478.plist +0 -0
  71. data/test/fixtures/api/film_times/71-16480.plist +0 -0
  72. data/test/fixtures/api/film_times/71-16482.plist +0 -0
  73. data/test/fixtures/api/film_times/71-16489.plist +0 -0
@@ -2,40 +2,15 @@
2
2
  module ApiFixturesHelper
3
3
  private
4
4
 
5
- def all_cinemas_plist
6
- read_fixture('api/all_cinemas')
5
+ def sites_json
6
+ read_fixture('api/sites')
7
7
  end
8
8
 
9
- def app_init_plist
10
- read_fixture('api/app_init')
11
- end
12
-
13
- def film_times_plist(cinema_id, film_id)
14
- read_fixture("api/film_times/#{cinema_id}-#{film_id}")
15
- end
16
-
17
- def film_times_plist_random
18
- read_fixture("api/film_times/#{film_times_plist_names(71).sample}")
19
- end
20
-
21
- def film_times_plist_names(cinema_id)
22
- Dir.entries(File.expand_path('../../fixtures/api/film_times', __FILE__))
23
- .reject { |filename| !filename.match(/\A#{cinema_id}-/) }
24
- .map { |filename| filename.gsub('.plist', '') }
25
- end
26
-
27
- def parse(content)
28
- plist = CFPropertyList::List.new(data: content).value
29
- CFPropertyList.native_types(plist).fetch('data', {})
9
+ def showtimes_json(cinema_id)
10
+ read_fixture("api/showtimes-#{cinema_id}")
30
11
  end
31
12
 
32
13
  def read_fixture(filepath)
33
- File.read(File.expand_path("../../fixtures/#{filepath}.plist", __FILE__))
34
- end
35
-
36
- def stub_post(site_path, request_body, response_body)
37
- url = "https://api.odeon.co.uk/2.1/api/#{site_path}"
38
- response = { status: 200, body: response_body, headers: {} }
39
- stub_request(:post, url).with(body: request_body).to_return(response)
14
+ File.read(File.expand_path("../../fixtures/#{filepath}.json", __FILE__))
40
15
  end
41
16
  end
@@ -0,0 +1,46 @@
1
+ require 'time'
2
+
3
+ # The parts of Vista responses the gem reads. Checked against the hand-written
4
+ # fixtures and, in the live suite, against real responses held only in memory.
5
+ module ApiShapes
6
+ private
7
+
8
+ def assert_sites_shape(data)
9
+ sites = data.fetch('sites')
10
+ refute_empty sites
11
+ sites.each do |site|
12
+ assert_match(/\A\d{3}\z/, site.fetch('id'))
13
+ assert_kind_of String, site.dig('name', 'text')
14
+ address = site.fetch('contactDetails').fetch('address')
15
+ %w(line1 line2 city).each do |key|
16
+ assert_kind_of String, address.fetch(key), "site #{site['id']} #{key}"
17
+ end
18
+ end
19
+ end
20
+
21
+ def assert_showtimes_shape(data)
22
+ related = data.fetch('relatedData')
23
+ films = related.fetch('films').to_h { |film| [film.fetch('id'), film] }
24
+ attributes = related.fetch('attributes').to_h do |attribute|
25
+ [attribute.fetch('id'), attribute]
26
+ end
27
+
28
+ films.each_value { |film| assert_kind_of String, film.dig('title', 'text') }
29
+ attributes.each_value do |attribute|
30
+ assert_kind_of String, attribute.dig('shortName', 'text')
31
+ assert_kind_of String, attribute.dig('name', 'text')
32
+ end
33
+
34
+ showtimes = data.fetch('showtimes')
35
+ refute_empty showtimes
36
+ showtimes.each do |showtime|
37
+ assert_kind_of String, showtime.fetch('id')
38
+ assert_includes films.keys, showtime.fetch('filmId')
39
+ assert_kind_of Time, Time.iso8601(showtime.fetch('schedule').fetch('startsAt'))
40
+ assert_includes [true, false], showtime.fetch('requires3dGlasses')
41
+ showtime.fetch('attributeIds').each do |id|
42
+ assert_includes attributes.keys, id
43
+ end
44
+ end
45
+ end
46
+ end
@@ -3,15 +3,18 @@ require_relative 'api_fixtures_helper'
3
3
  class FakeApiResponse
4
4
  include ApiFixturesHelper
5
5
 
6
- def app_init
7
- parse(app_init_plist)
6
+ attr_reader :requested_dates
7
+
8
+ def initialize
9
+ @requested_dates = []
8
10
  end
9
11
 
10
- def all_cinemas
11
- parse(all_cinemas_plist)
12
+ def sites
13
+ JSON.parse(sites_json).fetch('sites')
12
14
  end
13
15
 
14
- def film_times(cinema_id, film_id)
15
- parse(film_times_plist(cinema_id, film_id))
16
+ def showtimes(cinema_id, date)
17
+ @requested_dates << date
18
+ JSON.parse(showtimes_json(cinema_id))
16
19
  end
17
20
  end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
- require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/test/'
4
+ end
3
5
 
4
6
  require 'minitest/autorun'
7
+ require 'minitest/mock'
5
8
  require 'minitest/reporters'
6
9
 
7
10
  Minitest::Reporters.use! [
@@ -9,9 +12,9 @@ Minitest::Reporters.use! [
9
12
  ]
10
13
 
11
14
  require 'webmock/minitest'
12
- WebMock.allow_net_connect!
13
15
 
14
16
  require File.expand_path('../../lib/odeon_uk.rb', __FILE__)
15
17
 
16
18
  require_relative 'support/api_fixtures_helper'
19
+ require_relative 'support/api_shapes'
17
20
  require_relative 'support/fake_api_response'
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odeon_uk
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Croll
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2016-02-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: codeclimate-test-reporter
13
+ name: base64
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
@@ -25,7 +24,21 @@ dependencies:
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
27
26
  - !ruby/object:Gem::Dependency
28
- name: minitest-reporters
27
+ name: bundler
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest-mock
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
44
  - - ">="
@@ -39,7 +52,7 @@ dependencies:
39
52
  - !ruby/object:Gem::Version
40
53
  version: '0'
41
54
  - !ruby/object:Gem::Dependency
42
- name: rake
55
+ name: minitest-reporters
43
56
  requirement: !ruby/object:Gem::Requirement
44
57
  requirements:
45
58
  - - ">="
@@ -53,7 +66,7 @@ dependencies:
53
66
  - !ruby/object:Gem::Version
54
67
  version: '0'
55
68
  - !ruby/object:Gem::Dependency
56
- name: webmock
69
+ name: rake
57
70
  requirement: !ruby/object:Gem::Requirement
58
71
  requirements:
59
72
  - - ">="
@@ -67,13 +80,27 @@ dependencies:
67
80
  - !ruby/object:Gem::Version
68
81
  version: '0'
69
82
  - !ruby/object:Gem::Dependency
70
- name: CFPropertyList
83
+ name: simplecov
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '1'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "<"
94
+ - !ruby/object:Gem::Version
95
+ version: '1'
96
+ - !ruby/object:Gem::Dependency
97
+ name: webmock
71
98
  requirement: !ruby/object:Gem::Requirement
72
99
  requirements:
73
100
  - - ">="
74
101
  - !ruby/object:Gem::Version
75
102
  version: '0'
76
- type: :runtime
103
+ type: :development
77
104
  prerelease: false
78
105
  version_requirements: !ruby/object:Gem::Requirement
79
106
  requirements:
@@ -86,23 +113,25 @@ dependencies:
86
113
  requirements:
87
114
  - - "~>"
88
115
  - !ruby/object:Gem::Version
89
- version: '3.0'
116
+ version: '5.4'
90
117
  type: :runtime
91
118
  prerelease: false
92
119
  version_requirements: !ruby/object:Gem::Requirement
93
120
  requirements:
94
121
  - - "~>"
95
122
  - !ruby/object:Gem::Version
96
- version: '3.0'
97
- description: Pull movie & cinema information from the Odeon iOS API
123
+ version: '5.4'
124
+ description: Pull movie & cinema information from the ODEON Vista API
98
125
  email:
99
126
  - andy@goodscary.com
100
127
  executables: []
101
128
  extensions: []
102
129
  extra_rdoc_files: []
103
130
  files:
131
+ - ".github/workflows/release.yml"
132
+ - ".github/workflows/test.yml"
104
133
  - ".gitignore"
105
- - ".travis.yml"
134
+ - ".ruby-version"
106
135
  - CHANGELOG.md
107
136
  - COMM-LICENSE
108
137
  - Gemfile
@@ -112,60 +141,35 @@ files:
112
141
  - lib/odeon_uk.rb
113
142
  - lib/odeon_uk/cinema.rb
114
143
  - lib/odeon_uk/internal/api_response.rb
115
- - lib/odeon_uk/internal/parser/api/film_lookup.rb
116
- - lib/odeon_uk/internal/parser/api/performance_day.rb
144
+ - lib/odeon_uk/internal/guest_token.rb
145
+ - lib/odeon_uk/internal/parser/api/showtime.rb
117
146
  - lib/odeon_uk/internal/title_sanitizer.rb
118
147
  - lib/odeon_uk/performance.rb
119
148
  - lib/odeon_uk/version.rb
120
149
  - odeon_uk.gemspec
121
- - rake/fixture_creator.rb
122
- - test/fixtures/api/all_cinemas.plist
123
- - test/fixtures/api/app_init.plist
124
- - test/fixtures/api/film_times/71-14876.plist
125
- - test/fixtures/api/film_times/71-15408.plist
126
- - test/fixtures/api/film_times/71-15684.plist
127
- - test/fixtures/api/film_times/71-15866.plist
128
- - test/fixtures/api/film_times/71-15868.plist
129
- - test/fixtures/api/film_times/71-15961.plist
130
- - test/fixtures/api/film_times/71-15963.plist
131
- - test/fixtures/api/film_times/71-15965.plist
132
- - test/fixtures/api/film_times/71-15967.plist
133
- - test/fixtures/api/film_times/71-15969.plist
134
- - test/fixtures/api/film_times/71-15977.plist
135
- - test/fixtures/api/film_times/71-15980.plist
136
- - test/fixtures/api/film_times/71-16037.plist
137
- - test/fixtures/api/film_times/71-16136.plist
138
- - test/fixtures/api/film_times/71-16142.plist
139
- - test/fixtures/api/film_times/71-16143.plist
140
- - test/fixtures/api/film_times/71-16187.plist
141
- - test/fixtures/api/film_times/71-16369.plist
142
- - test/fixtures/api/film_times/71-16370.plist
143
- - test/fixtures/api/film_times/71-16374.plist
144
- - test/fixtures/api/film_times/71-16386.plist
145
- - test/fixtures/api/film_times/71-16387.plist
146
- - test/fixtures/api/film_times/71-16388.plist
147
- - test/fixtures/api/film_times/71-16438.plist
148
- - test/fixtures/api/film_times/71-16454.plist
149
- - test/fixtures/api/film_times/71-16457.plist
150
- - test/fixtures/api/film_times/71-16477.plist
151
- - test/fixtures/api/film_times/71-16478.plist
152
- - test/fixtures/api/film_times/71-16480.plist
153
- - test/fixtures/api/film_times/71-16482.plist
154
- - test/fixtures/api/film_times/71-16489.plist
150
+ - test/fixtures/api/showtimes-824.json
151
+ - test/fixtures/api/sites.json
155
152
  - test/lib/odeon_uk/cinema_test.rb
156
153
  - test/lib/odeon_uk/internal/api_response_test.rb
154
+ - test/lib/odeon_uk/internal/fixture_shape_test.rb
155
+ - test/lib/odeon_uk/internal/guest_token_test.rb
156
+ - test/lib/odeon_uk/internal/parser/api/showtime_test.rb
157
157
  - test/lib/odeon_uk/internal/title_sanitizer_test.rb
158
158
  - test/lib/odeon_uk/performance_test.rb
159
159
  - test/lib/odeon_uk/version_test.rb
160
+ - test/live/api_shape_test.rb
161
+ - test/live/integration_test.rb
162
+ - test/live/live_helper.rb
163
+ - test/package_test.rb
160
164
  - test/support/api_fixtures_helper.rb
165
+ - test/support/api_shapes.rb
161
166
  - test/support/fake_api_response.rb
162
167
  - test/test_helper.rb
163
- homepage: http://github.com/andycroll/odeon_uk
168
+ homepage: https://github.com/andycroll/odeon_uk
164
169
  licenses:
165
170
  - AGPL
166
171
  - MIT
167
172
  metadata: {}
168
- post_install_message:
169
173
  rdoc_options: []
170
174
  require_paths:
171
175
  - lib
@@ -173,58 +177,32 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
177
  requirements:
174
178
  - - ">="
175
179
  - !ruby/object:Gem::Version
176
- version: '0'
180
+ version: '3.4'
177
181
  required_rubygems_version: !ruby/object:Gem::Requirement
178
182
  requirements:
179
183
  - - ">="
180
184
  - !ruby/object:Gem::Version
181
185
  version: '0'
182
186
  requirements: []
183
- rubyforge_project:
184
- rubygems_version: 2.4.5
185
- signing_key:
187
+ rubygems_version: 4.0.20
186
188
  specification_version: 4
187
189
  summary: It's a scraper, but a nice one
188
190
  test_files:
189
- - test/fixtures/api/all_cinemas.plist
190
- - test/fixtures/api/app_init.plist
191
- - test/fixtures/api/film_times/71-14876.plist
192
- - test/fixtures/api/film_times/71-15408.plist
193
- - test/fixtures/api/film_times/71-15684.plist
194
- - test/fixtures/api/film_times/71-15866.plist
195
- - test/fixtures/api/film_times/71-15868.plist
196
- - test/fixtures/api/film_times/71-15961.plist
197
- - test/fixtures/api/film_times/71-15963.plist
198
- - test/fixtures/api/film_times/71-15965.plist
199
- - test/fixtures/api/film_times/71-15967.plist
200
- - test/fixtures/api/film_times/71-15969.plist
201
- - test/fixtures/api/film_times/71-15977.plist
202
- - test/fixtures/api/film_times/71-15980.plist
203
- - test/fixtures/api/film_times/71-16037.plist
204
- - test/fixtures/api/film_times/71-16136.plist
205
- - test/fixtures/api/film_times/71-16142.plist
206
- - test/fixtures/api/film_times/71-16143.plist
207
- - test/fixtures/api/film_times/71-16187.plist
208
- - test/fixtures/api/film_times/71-16369.plist
209
- - test/fixtures/api/film_times/71-16370.plist
210
- - test/fixtures/api/film_times/71-16374.plist
211
- - test/fixtures/api/film_times/71-16386.plist
212
- - test/fixtures/api/film_times/71-16387.plist
213
- - test/fixtures/api/film_times/71-16388.plist
214
- - test/fixtures/api/film_times/71-16438.plist
215
- - test/fixtures/api/film_times/71-16454.plist
216
- - test/fixtures/api/film_times/71-16457.plist
217
- - test/fixtures/api/film_times/71-16477.plist
218
- - test/fixtures/api/film_times/71-16478.plist
219
- - test/fixtures/api/film_times/71-16480.plist
220
- - test/fixtures/api/film_times/71-16482.plist
221
- - test/fixtures/api/film_times/71-16489.plist
191
+ - test/fixtures/api/showtimes-824.json
192
+ - test/fixtures/api/sites.json
222
193
  - test/lib/odeon_uk/cinema_test.rb
223
194
  - test/lib/odeon_uk/internal/api_response_test.rb
195
+ - test/lib/odeon_uk/internal/fixture_shape_test.rb
196
+ - test/lib/odeon_uk/internal/guest_token_test.rb
197
+ - test/lib/odeon_uk/internal/parser/api/showtime_test.rb
224
198
  - test/lib/odeon_uk/internal/title_sanitizer_test.rb
225
199
  - test/lib/odeon_uk/performance_test.rb
226
200
  - test/lib/odeon_uk/version_test.rb
201
+ - test/live/api_shape_test.rb
202
+ - test/live/integration_test.rb
203
+ - test/live/live_helper.rb
204
+ - test/package_test.rb
227
205
  - test/support/api_fixtures_helper.rb
206
+ - test/support/api_shapes.rb
228
207
  - test/support/fake_api_response.rb
229
208
  - test/test_helper.rb
230
- has_rdoc:
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.4
4
- - 2.3.0
5
- addons:
6
- code_climate:
7
- repo_token: 2999a45e7504799e1153d82fcb36fcc8f603388ca3d7df3caae1dd20f753a8c1
@@ -1,34 +0,0 @@
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
@@ -1,92 +0,0 @@
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
@@ -1,46 +0,0 @@
1
- module FixtureCreator
2
- class Api
3
- def all_cinemas!
4
- write_fixture(:all_cinemas)
5
- end
6
-
7
- def app_init!
8
- write_fixture(:app_init)
9
- end
10
-
11
- def film_times!(cinema_id)
12
- OdeonUk::Performance.send(:film_ids_at, cinema_id).each do |i|
13
- write_film_times_fixture(cinema_id, i)
14
- end
15
- end
16
-
17
- private
18
-
19
- def fixture(name)
20
- File.expand_path("../../test/fixtures/api/#{name}.plist", __FILE__)
21
- end
22
-
23
- def log(message)
24
- puts "Create API fixture: #{message}"
25
- end
26
-
27
- def write_film_times_fixture(cinema_id, film_id)
28
- FileUtils.mkdir_p 'film_times'
29
- text = "film_times/#{cinema_id}-#{film_id}"
30
- File.open(fixture(text), 'w+') do |file|
31
- log(text)
32
- file.write OdeonUk::Internal::ApiResponse.new.send(:film_times_raw,
33
- cinema_id,
34
- film_id)
35
- end
36
- end
37
-
38
- def write_fixture(kind)
39
- FileUtils.mkdir_p kind.to_s
40
- File.open(fixture(kind), 'w+') do |file|
41
- log(kind)
42
- file.write OdeonUk::Internal::ApiResponse.new.send("#{kind}_raw".to_sym)
43
- end
44
- end
45
- end
46
- end
Binary file
Binary file