curzon_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: eba02f165b52b7421edeb7252cfb501f3046fad4f5a9c1a320b1551925cf364f
4
- data.tar.gz: 362233c6da401d4d232f118a36b464ffa65819cbc50f00189cc545847e9d900b
3
+ metadata.gz: a776f80248448e96486dccbe8854e1ef83bff8a0ecfcc94d4d73a589d211e431
4
+ data.tar.gz: 5e221f593af12e296ffb302a0792cfa328fd7cdb90f7503b521e6c4eb0116657
5
5
  SHA512:
6
- metadata.gz: c6bb9f6dd880f71a60eb9ab955fe1570606893573d7bfa8156a536e23c45f0625bffae6eabbea8571384bcbe3f94a4714f51100e43a6a9c27e7b754d5de9b81e
7
- data.tar.gz: 8ad0eb707f0748d259d6256e526686376fb49a8717d1a94987486f769153917bb60b46e2b477101d957cd820769dfd004ab0a0007bfd071051ca3825e5a2eff1
6
+ metadata.gz: 941bcbadcab44c8f6ec29908c1339adb8f19b7e33974b0c6638919de8291977da36c001d0184ac618ba604f0e16f933b1de65a90e84931e439a36dbb8a41a633
7
+ data.tar.gz: 9334fce8ae9360df12ab5653aae3e7badc21e425c61cb9737c5321b33d8c277709f5154bb8ee07e8f8715f7c154fa4807ccd8502ee093d781be1a3e4212ea2b6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
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, from the Vista sites response. They are `nil` when a site has no location or sits at 0, 0.
9
+ - `CurzonUk.ensure_token!` fetches a guest token only when there is none or it expires within an hour, and `CurzonUk.token_expires_at` reads its expiry. Both come from cinebase's `Vista::TokenHolder`.
10
+
11
+ ### Changed
12
+ - A token the API rejects is cleared from `CurzonUk.token`, so the next `ensure_token!` fetches a fresh one.
13
+ - Requires cinebase 5.6.
14
+
5
15
  ## [1.0.0] - 2026-10-22
6
16
 
7
17
  ### Added
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
data/README.md CHANGED
@@ -53,9 +53,21 @@ CurzonUk.token = ENV.fetch('CURZON_TOKEN')
53
53
  ```
54
54
 
55
55
  Tokens currently last 12 hours. The gem checks the declared expiry but does not
56
- verify the signature. Missing, expired or rejected tokens raise
57
- `CurzonUk::AuthenticationError`; call `CurzonUk.acquire_token!` again. Normal
58
- API calls never acquire or renew a token automatically.
56
+ verify the signature. Normal API calls never acquire or renew a token
57
+ automatically. `CurzonUk.ensure_token!` fetches one only when there is no token,
58
+ or the token expires within an hour, and otherwise keeps the current one. Call
59
+ it before each batch of requests:
60
+
61
+ ``` ruby
62
+ CurzonUk.ensure_token!
63
+ CurzonUk.token_expires_at
64
+ #=> 2026-10-31 03:00:00 UTC
65
+ CurzonUk::Cinema.all
66
+ ```
67
+
68
+ Missing, expired or rejected tokens raise `CurzonUk::AuthenticationError`. A
69
+ token the API rejects is cleared from `CurzonUk.token`, so the next
70
+ `ensure_token!` fetches a fresh one.
59
71
 
60
72
  ### Cinema
61
73
 
@@ -84,6 +96,12 @@ cinema.brand
84
96
  cinema.full_name
85
97
  #=> 'Curzon Soho'
86
98
 
99
+ cinema.latitude
100
+ #=> 51.5127983093262
101
+
102
+ cinema.longitude
103
+ #=> -0.130500003695488
104
+
87
105
  cinema.url
88
106
  #=> 'https://www.curzon.com/venues/soho/'
89
107
  ```
data/curzon_uk.gemspec CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'simplecov', '< 1'
28
28
  spec.add_development_dependency 'webmock'
29
29
 
30
- spec.add_runtime_dependency 'cinebase', '~> 5.4'
30
+ spec.add_runtime_dependency 'cinebase', '~> 5.6'
31
31
  end
@@ -68,6 +68,24 @@ module CurzonUk
68
68
  'Curzon'.freeze
69
69
  end
70
70
 
71
+ # Latitude of the cinema
72
+ # @return [Float, nil] decimal degrees, or nil when unknown
73
+ # @example
74
+ # CurzonUk::Cinema.new('SOH1').latitude
75
+ # #=> 51.5127983093262
76
+ def latitude
77
+ coordinates&.first
78
+ end
79
+
80
+ # Longitude of the cinema
81
+ # @return [Float, nil] decimal degrees, or nil when unknown
82
+ # @example
83
+ # CurzonUk::Cinema.new('SOH1').longitude
84
+ # #=> -0.130500003695488
85
+ def longitude
86
+ coordinates&.last
87
+ end
88
+
71
89
  # The name of the cinema
72
90
  # @return [String]
73
91
  # @example
@@ -102,6 +120,13 @@ module CurzonUk
102
120
  end
103
121
  end
104
122
 
123
+ # 0, 0 marks a site whose position was never set
124
+ def coordinates
125
+ location = site_hash['location'] || {}
126
+ pair = [location['latitude'], location['longitude']]
127
+ pair.map(&:to_f) if pair.all?(Numeric) && pair.any?(&:nonzero?)
128
+ end
129
+
105
130
  def site_hash
106
131
  @site_hash ||= self.class.send(:sites_hash).fetch(id, {})
107
132
  end
@@ -12,23 +12,31 @@ module CurzonUk
12
12
 
13
13
  # @return [Array<Hash>] cinemas
14
14
  def sites
15
- client.get("sites").fetch("sites")
15
+ get("sites").fetch("sites")
16
16
  end
17
17
 
18
18
  # @param [String] cinema_id site id, e.g. 'ALD1'
19
19
  # @param [Date] date business date
20
20
  # @return [Hash] showtimes plus their related films and attributes
21
21
  def showtimes(cinema_id, date)
22
- client.get("showtimes/by-business-date/#{date.iso8601}",
22
+ get("showtimes/by-business-date/#{date.iso8601}",
23
23
  "siteIds" => cinema_id)
24
24
  end
25
25
 
26
26
  private
27
27
 
28
+ def get(path, query = {})
29
+ token = CurzonUk.token
30
+ client(token).get(path, query)
31
+ rescue Cinebase::Vista::AuthenticationError
32
+ CurzonUk.reject_token!(token)
33
+ raise
34
+ end
35
+
28
36
  # Curzon's API needs no Connect-Region-Code.
29
- def client
37
+ def client(token)
30
38
  Cinebase::Vista::Client.new(base_url: BASE_URL, region_code: nil,
31
- token: CurzonUk.token)
39
+ token: token)
32
40
  end
33
41
  end
34
42
  end
@@ -1,6 +1,6 @@
1
1
  # Ruby interface for https://www.curzon.com
2
- # @version 1.0.0
2
+ # @version 1.1.0
3
3
  module CurzonUk
4
4
  # Gem version
5
- VERSION = '1.0.0'.freeze
5
+ VERSION = '1.1.0'.freeze
6
6
  end
data/lib/curzon_uk.rb CHANGED
@@ -18,13 +18,10 @@ require_relative './curzon_uk/performance'
18
18
  module CurzonUk
19
19
  AuthenticationError = Cinebase::Vista::AuthenticationError
20
20
 
21
- # A raw guest JWT, without the "Bearer " prefix. Never persisted by the gem.
22
- class << self
23
- attr_accessor :token
24
-
25
- # Explicit acquisition/renewal; ordinary API calls never launch a subprocess.
26
- def acquire_token!(curl: nil)
27
- self.token = Internal::GuestToken.new(curl: curl).fetch
28
- end
21
+ extend Cinebase::Vista::TokenHolder
22
+
23
+ # @api private
24
+ def self.guest_token_class
25
+ Internal::GuestToken
29
26
  end
30
27
  end
@@ -3,6 +3,7 @@
3
3
  {
4
4
  "id": "CAN2",
5
5
  "name": { "text": "Canterbury" },
6
+ "location": { "latitude": 0, "longitude": 0 },
6
7
  "contactDetails": {
7
8
  "addressV2": {
8
9
  "line1": { "text": "Unit 9," },
@@ -15,6 +16,7 @@
15
16
  {
16
17
  "id": "SOH1",
17
18
  "name": { "text": "Soho" },
19
+ "location": { "latitude": 51.5127983093262, "longitude": -0.130500003695488 },
18
20
  "contactDetails": {
19
21
  "addressV2": {
20
22
  "line1": { "text": "99 Example Avenue," },
@@ -58,6 +58,29 @@ class CurzonUk::CinemaTest < Minitest::Test
58
58
  end
59
59
  end
60
60
 
61
+ def test_latitude_and_longitude
62
+ with_fake_api do
63
+ cinema = CurzonUk::Cinema.new('SOH1')
64
+
65
+ assert_in_delta 51.5128, cinema.latitude, 0.0001
66
+ assert_in_delta(-0.1305, cinema.longitude, 0.0001)
67
+ end
68
+ end
69
+
70
+ def test_latitude_and_longitude_are_nil_without_a_location
71
+ with_fake_api do
72
+ assert_nil CurzonUk::Cinema.new('VIC1').latitude
73
+ assert_nil CurzonUk::Cinema.new('VIC1').longitude
74
+ end
75
+ end
76
+
77
+ def test_latitude_and_longitude_are_nil_at_zero_zero
78
+ with_fake_api do
79
+ assert_nil CurzonUk::Cinema.new('CAN2').latitude
80
+ assert_nil CurzonUk::Cinema.new('CAN2').longitude
81
+ end
82
+ end
83
+
61
84
  def test_name
62
85
  with_fake_api do
63
86
  assert_equal 'Soho', CurzonUk::Cinema.new('SOH1').name
@@ -44,6 +44,14 @@ class CurzonUk::Internal::ApiResponseTest < Minitest::Test
44
44
  assert_raises(CurzonUk::AuthenticationError) { api.sites }
45
45
  end
46
46
 
47
+ def test_rejected_token_is_cleared
48
+ stub_request(:get, "#{BASE_URL}/sites").to_return(status: 401)
49
+
50
+ assert_raises(CurzonUk::AuthenticationError) { api.sites }
51
+
52
+ assert_nil CurzonUk.token
53
+ end
54
+
47
55
  private
48
56
 
49
57
  def api
@@ -58,6 +58,13 @@ class CurzonUk::Internal::GuestTokenTest < Minitest::Test
58
58
  assert_match(/curl-impersonate/, error.message)
59
59
  end
60
60
 
61
+ def test_ensure_token_fetches_only_without_a_current_token
62
+ token = token_expiring_at(Time.now + 7200)
63
+
64
+ assert_equal token, CurzonUk.ensure_token!(curl: fake_curl("#{page_with(token)}\n200"))
65
+ assert_equal token, CurzonUk.ensure_token!(curl: File.join(@directory, 'missing'))
66
+ end
67
+
61
68
  def test_acquire_token_sets_token
62
69
  token = token_expiring_at(Time.now + 3600)
63
70
 
@@ -14,6 +14,16 @@ class LiveCinemaTest < Minitest::Test
14
14
  refute_empty cinema.postal_code, "#{cinema.id} #{cinema.name}"
15
15
  end
16
16
  end
17
+
18
+ def test_cinemas_have_uk_coordinates
19
+ located = CurzonUk::Cinema.all.select(&:latitude)
20
+
21
+ refute_empty located
22
+ located.each do |cinema|
23
+ assert_includes 49.0..61.0, cinema.latitude, "#{cinema.id} #{cinema.name}"
24
+ assert_includes(-9.0..2.0, cinema.longitude, "#{cinema.id} #{cinema.name}")
25
+ end
26
+ end
17
27
  end
18
28
 
19
29
  class LivePerformanceTest < Minitest::Test
@@ -16,6 +16,11 @@ module ApiShapes
16
16
  line = address.fetch(key)
17
17
  assert_kind_of String, line.fetch('text'), "site #{site['id']} #{key}" unless line.nil?
18
18
  end
19
+ location = site['location'] || {}
20
+ %w(latitude longitude).each do |key|
21
+ value = location[key]
22
+ assert_kind_of Numeric, value, "site #{site['id']} #{key}" unless value.nil?
23
+ end
19
24
  end
20
25
  end
21
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curzon_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
@@ -113,14 +113,14 @@ dependencies:
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '5.4'
116
+ version: '5.6'
117
117
  type: :runtime
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '5.4'
123
+ version: '5.6'
124
124
  description: Pull movie & cinema information from the Curzon Vista API
125
125
  email:
126
126
  - andy@goodscary.com