vue_uk 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d51133b8fa61b0a4ee6aab8ec4adf944a4b321518be709174fae2f98c58352e1
4
- data.tar.gz: 22ea402e37db1a0908e8d90d2c5d2ad5935c00371c516ab9b1755c564436e660
3
+ metadata.gz: 360458297b98535971b0dbef7be0dafeb437ee4da40426c7d8ef259515edc023
4
+ data.tar.gz: 825f222789213c3be3d0c0e8abcb5f8ece8f0f26a9c7259146faa80ec01a8799
5
5
  SHA512:
6
- metadata.gz: 6ffa45b43577d3c54b790f2becfabc82aed9942c266e28539e8b4629a05e3944ea060b62bcfe6ca5204ef7f8532b91bb92aba9c37d4b8f13153f6d21f4c8c3ec
7
- data.tar.gz: f8f0fcd8720367a37b98b54bf91154ce91aefae0d20a86a134e46b800cac2c9178c09ab94ac5975adec29d6bfcf670ff32679a6106caef2b69dff9189a2433b1
6
+ metadata.gz: faa8d4ee96a22fe8ff39b39a612254a0fdb6b88db1615016ac110beaba4ea6b487bc82d202e344162a874e76a61d77d9db313ad1df3556f6aa0d8479d43d7124
7
+ data.tar.gz: 8fd92fbd799e6be26c30f6be0f3d89c588041cb4fe5b7cc539e024be88df3920939e4c1f5e74a853effbe2f56f8ae7b554beed44468e3996ed5504892bcb0f00
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [1.1.0] - 2026-10-31
6
+
7
+ ### Added
8
+ - `Cinema#latitude` and `Cinema#longitude` as Floats in decimal degrees, read from `cinemaLocationCoordinates` on the cinema's page like its address. They are `nil` when the page has no readable coordinates or they are 0, 0.
9
+
10
+ ### Changed
11
+ - The cinema list is fetched again after an hour (`Cinema::CACHE_TTL`), so a long-running process sees cinemas Vue opens or closes.
12
+
5
13
  ## [1.0.0] - 2026-10-22
6
14
 
7
15
  ### Added
data/README.md CHANGED
@@ -30,8 +30,8 @@ once if the API rejects it.
30
30
  ### Cinema
31
31
 
32
32
  Only UK cinemas are returned; Vue's euro-priced cinemas are left out. The API
33
- has no addresses, so the first call to an address method reads the cinema's page
34
- on myvue.com.
33
+ has no addresses or coordinates, so the first call to an address method,
34
+ `latitude` or `longitude` reads the cinema's page on myvue.com.
35
35
 
36
36
  ``` ruby
37
37
  VueUk::Cinema.all
@@ -59,6 +59,12 @@ cinema.full_name
59
59
  cinema.id
60
60
  #=> '10051'
61
61
 
62
+ cinema.latitude
63
+ #=> 53.754874975913864
64
+
65
+ cinema.longitude
66
+ #=> -2.369161692538972
67
+
62
68
  cinema.url
63
69
  #=> 'https://www.myvue.com/cinema/accrington'
64
70
  ```
data/lib/vue_uk/cinema.rb CHANGED
@@ -10,9 +10,14 @@ module VueUk
10
10
  # A county and postcode on one line, e.g. 'Essex CO4 5UP'
11
11
  REGION_AND_POSTCODE = /\A(.+?)\s+([A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2})\z/i.freeze
12
12
 
13
- # Map coordinates some cinemas list in place of a postcode
13
+ # Map coordinates, as on each cinema page and in place of a postcode in
14
+ # some addresses
14
15
  COORDINATES = /\A-?\d+(\.\d+)?,\s*-?\d+(\.\d+)?\z/.freeze
15
16
 
17
+ # Seconds the cinema list is kept, so a long-running process sees
18
+ # cinemas Vue opens or closes
19
+ CACHE_TTL = 3600
20
+
16
21
  # Constructor
17
22
  # @param [Integer, String] id the cinema id of the format 10051/'10051'
18
23
  # @return [VueUk::Cinema]
@@ -75,6 +80,24 @@ module VueUk
75
80
  'Vue'.freeze
76
81
  end
77
82
 
83
+ # Latitude of the cinema, read from its page on the Vue website
84
+ # @return [Float, nil] decimal degrees, or nil when unknown
85
+ # @example
86
+ # VueUk::Cinema.new(10051).latitude
87
+ # #=> 53.754874975913864
88
+ def latitude
89
+ coordinates&.first
90
+ end
91
+
92
+ # Longitude of the cinema, read from its page on the Vue website
93
+ # @return [Float, nil] decimal degrees, or nil when unknown
94
+ # @example
95
+ # VueUk::Cinema.new(10051).longitude
96
+ # #=> -2.369161692538972
97
+ def longitude
98
+ coordinates&.last
99
+ end
100
+
78
101
  # The name of the cinema
79
102
  # @return [String]
80
103
  # @example
@@ -93,17 +116,20 @@ module VueUk
93
116
  # @api private
94
117
  # Leaves out Vue's euro-priced cinemas outside the UK.
95
118
  def self.cinemas_hash
96
- @cinemas_hash ||= VueUk::Internal::ApiResponse.new.cinemas
119
+ if @cinemas_hash.nil? || Time.now - @cinemas_fetched_at > CACHE_TTL
120
+ @cinemas_hash = VueUk::Internal::ApiResponse.new.cinemas
97
121
  .select { |cinema| cinema['venueCurrency'] == 'GBP' }
98
122
  .to_h { |cinema| [cinema.fetch('cinemaId'), cinema] }
123
+ @cinemas_fetched_at = Time.now
124
+ end
125
+ @cinemas_hash
99
126
  end
100
127
  private_class_method :cinemas_hash
101
128
 
102
129
  private
103
130
 
104
131
  def address_lines
105
- @page ||= VueUk::Internal::Website.new.cinema(cinema_hash.fetch('whatsOnUrl'))
106
- @page.dig('cinemaAddress', 'value').to_s.split(/\r?\n/)
132
+ page.dig('cinemaAddress', 'value').to_s.split(/\r?\n/)
107
133
  .map { |line| line.strip.sub(/,\s*(UK|United Kingdom)\z/i, '') }
108
134
  .reject { |line| line.empty? || line.match?(COORDINATES) }
109
135
  end
@@ -111,5 +137,18 @@ module VueUk
111
137
  def cinema_hash
112
138
  @cinema_hash ||= self.class.send(:cinemas_hash).fetch(id, {})
113
139
  end
140
+
141
+ # 0, 0 marks a cinema whose position was never set
142
+ def coordinates
143
+ value = page.dig('cinemaLocationCoordinates', 'value').to_s.strip
144
+ if value.match?(COORDINATES)
145
+ pair = value.split(',').map(&:to_f)
146
+ pair if pair.any?(&:nonzero?)
147
+ end
148
+ end
149
+
150
+ def page
151
+ @page ||= VueUk::Internal::Website.new.cinema(cinema_hash.fetch('whatsOnUrl'))
152
+ end
114
153
  end
115
154
  end
@@ -1,6 +1,6 @@
1
1
  # Ruby interface for https://www.myvue.com
2
- # @version 1.0.0
2
+ # @version 1.1.0
3
3
  module VueUk
4
4
  # Gem version
5
- VERSION = '1.0.0'.freeze
5
+ VERSION = '1.1.0'.freeze
6
6
  end
@@ -3,6 +3,6 @@
3
3
  <head><title>Vue Accrington</title></head>
4
4
  <body>
5
5
  <div id="__next"></div>
6
- <script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"layoutData":{"sitecore":{"context":{"cinema":{"cinemaId":{"value":"10051"},"cinemaName":{"value":"Accrington"},"cinemaAddress":{"value":"1 Example Viaduct\r\nExample Road\r\nAccrington\r\nBB5 0ZZ "}}}}}}}}</script>
6
+ <script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"layoutData":{"sitecore":{"context":{"cinema":{"cinemaId":{"value":"10051"},"cinemaName":{"value":"Accrington"},"cinemaLocationCoordinates":{"value":"53.7548, -2.3691"},"cinemaAddress":{"value":"1 Example Viaduct\r\nExample Road\r\nAccrington\r\nBB5 0ZZ "}}}}}}}}</script>
7
7
  </body>
8
8
  </html>
@@ -19,6 +19,22 @@ class VueUk::CinemaTest < Minitest::Test
19
19
  end
20
20
  end
21
21
 
22
+ def test_cinema_list_expires_after_cache_ttl
23
+ requests = 0
24
+ new_api = lambda do
25
+ requests += 1
26
+ @api_response
27
+ end
28
+ now = Time.now
29
+
30
+ VueUk::Internal::ApiResponse.stub(:new, new_api) do
31
+ Time.stub(:now, now) { 2.times { VueUk::Cinema.all } }
32
+ Time.stub(:now, now + VueUk::Cinema::CACHE_TTL + 1) { VueUk::Cinema.all }
33
+ end
34
+
35
+ assert_equal 2, requests
36
+ end
37
+
22
38
  def test_name_and_full_name
23
39
  with_fakes do
24
40
  assert_equal 'Accrington', VueUk::Cinema.new(10051).name
@@ -91,8 +107,49 @@ class VueUk::CinemaTest < Minitest::Test
91
107
  assert_equal '255 Example Road', adr[:extended_address]
92
108
  end
93
109
 
110
+ def test_latitude_and_longitude_from_cinema_page
111
+ with_fakes do
112
+ cinema = VueUk::Cinema.new(10051)
113
+
114
+ assert_in_delta 53.7548, cinema.latitude, 0.0001
115
+ assert_in_delta(-2.3691, cinema.longitude, 0.0001)
116
+ end
117
+ end
118
+
119
+ def test_latitude_and_longitude_are_nil_without_coordinates
120
+ cinema = cinema_with_page('cinemaAddress' => { 'value' => '1 Example Viaduct' })
121
+
122
+ assert_nil cinema.latitude
123
+ assert_nil cinema.longitude
124
+ end
125
+
126
+ def test_latitude_and_longitude_are_nil_at_zero_zero
127
+ cinema = cinema_with_page('cinemaLocationCoordinates' => { 'value' => '0, 0' })
128
+
129
+ assert_nil cinema.latitude
130
+ assert_nil cinema.longitude
131
+ end
132
+
133
+ def test_latitude_and_longitude_are_nil_for_unreadable_coordinates
134
+ cinema = cinema_with_page('cinemaLocationCoordinates' => { 'value' => 'Accrington' })
135
+
136
+ assert_nil cinema.latitude
137
+ assert_nil cinema.longitude
138
+ end
139
+
94
140
  private
95
141
 
142
+ def cinema_with_page(page)
143
+ website = Object.new
144
+ website.define_singleton_method(:cinema) { |_url| page }
145
+ cinema = VueUk::Cinema.new(10051)
146
+
147
+ VueUk::Internal::ApiResponse.stub(:new, @api_response) do
148
+ VueUk::Internal::Website.stub(:new, website) { cinema.latitude }
149
+ end
150
+ cinema
151
+ end
152
+
96
153
  def adr_for(address)
97
154
  website = Object.new
98
155
  website.define_singleton_method(:cinema) { |_url| { 'cinemaAddress' => { 'value' => address } } }
@@ -12,6 +12,13 @@ class LiveCinemaTest < Minitest::Test
12
12
  def test_address_has_a_postcode
13
13
  refute_empty VueUk::Cinema.new(10051).postal_code
14
14
  end
15
+
16
+ def test_cinema_has_uk_coordinates
17
+ cinema = VueUk::Cinema.new(10051)
18
+
19
+ assert_includes 49.0..61.0, cinema.latitude
20
+ assert_includes(-9.0..2.0, cinema.longitude)
21
+ end
15
22
  end
16
23
 
17
24
  class LivePerformanceTest < Minitest::Test
@@ -34,5 +34,7 @@ module ApiShapes
34
34
 
35
35
  def assert_cinema_page_shape(cinema)
36
36
  assert_kind_of String, cinema.fetch('cinemaAddress').fetch('value')
37
+ coordinates = cinema.dig('cinemaLocationCoordinates', 'value')
38
+ assert_match(/\A-?\d+(\.\d+)?,\s*-?\d+(\.\d+)?\z/, coordinates.strip) unless coordinates.nil?
37
39
  end
38
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue_uk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Croll