picturehouse_uk 6.0.0-x86_64-linux-gnu → 6.1.0-x86_64-linux-gnu

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: a83a8906383b34dd528cbc7e0e9e8ba544451e598f4bdff3daac5c88859e6387
4
- data.tar.gz: 7f25eaf8d6ded251a4747fb31b865cfb9cd1a0c2bdc7f9556df86b3dc91b8f82
3
+ metadata.gz: e0d425e15ce784b1ce0019797bbe0a07c060e79e7aef213c5a04a5f2e69a210d
4
+ data.tar.gz: 5bda63f437fde46a3f82a553be128154b5d89daec5217acbaedf9d1962ea1c0f
5
5
  SHA512:
6
- metadata.gz: a3ece7b8c341a0bdffa8d0c198e31b8bb0d5a347e1683c27f4dabb4c51681355bce5edd148cb0b6f1da4866399c9883a0ef4824150363017e83e3d1dc6814387
7
- data.tar.gz: 25d4b2880e9a6630fb0234a182160fc3ea5a32eef182962b63e809273af7f6dfd8dc0d0a90d0e226a1330a3861118e7844432fdd6aa3edf5e16bc7173e4c68d2
6
+ metadata.gz: 457cc0b62bf8d2edbb1023917bfd1c9ed0b95cc7b839d9a2c106b8ba9d096d77608a531988f7c3654dd825d06686eee3a23fab262c890d6fd5775a0ac673286d
7
+ data.tar.gz: c7a452170940d26a04441335a076a08b519878fff35c08ba2f27dd20e4442d058bc85f81bf574e3e92afb4245a4a3ffeb7bba4f990334428f01a6eea9dd15b36
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
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
+ ## [6.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
+ - `PicturehouseUk.ensure_token!` fetches a guest token only when there is none or it expires within an hour, and `PicturehouseUk.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 `PicturehouseUk.token`, so the next `ensure_token!` fetches a fresh one.
13
+ - Requires cinebase 5.6.
14
+
15
+ ## [6.0.1] - 2026-10-22
16
+
17
+ ### Changed
18
+ - Reuse one Vista client, and so one kept-alive connection, for all requests until the token changes, instead of opening a TLS connection for every request. Requires cinebase 5.5.
19
+
5
20
  ## [6.0.0] - 2026-10-22
6
21
 
7
22
  ### Changed
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in picturehouse_uk.gemspec
4
4
  gemspec
5
+
data/README.md CHANGED
@@ -55,9 +55,21 @@ PicturehouseUk.token = ENV.fetch('PICTUREHOUSE_TOKEN')
55
55
  ```
56
56
 
57
57
  Tokens currently last 12 hours. The gem checks the declared expiry but does not
58
- verify the signature. Missing, expired or rejected tokens raise
59
- `PicturehouseUk::AuthenticationError`; call `PicturehouseUk.acquire_token!`
60
- again. Normal API calls never acquire or renew a token automatically.
58
+ verify the signature. Normal API calls never acquire or renew a token
59
+ automatically. `PicturehouseUk.ensure_token!` fetches one only when there is no
60
+ token, or the token expires within an hour, and otherwise keeps the current one.
61
+ Call it before each batch of requests:
62
+
63
+ ``` ruby
64
+ PicturehouseUk.ensure_token!
65
+ PicturehouseUk.token_expires_at
66
+ #=> 2026-10-31 03:00:00 UTC
67
+ PicturehouseUk::Cinema.all
68
+ ```
69
+
70
+ Missing, expired or rejected tokens raise `PicturehouseUk::AuthenticationError`. A
71
+ token the API rejects is cleared from `PicturehouseUk.token`, so the next
72
+ `ensure_token!` fetches a fresh one.
61
73
 
62
74
  ### Cinema
63
75
 
@@ -86,6 +98,12 @@ cinema.brand
86
98
  cinema.name
87
99
  #=> "Duke's at Komedia"
88
100
 
101
+ cinema.latitude
102
+ #=> 50.8247985839844
103
+
104
+ cinema.longitude
105
+ #=> -0.139400005340576
106
+
89
107
  cinema.id
90
108
  #=> '019'
91
109
 
@@ -80,6 +80,26 @@ module PicturehouseUk
80
80
  name
81
81
  end
82
82
 
83
+ # Latitude of the cinema
84
+ # @return [Float, nil] decimal degrees, or nil when unknown
85
+ # @example
86
+ # cinema = PicturehouseUk::Cinema.new(19)
87
+ # cinema.latitude
88
+ # #=> 50.8247985839844
89
+ def latitude
90
+ coordinates&.first
91
+ end
92
+
93
+ # Longitude of the cinema
94
+ # @return [Float, nil] decimal degrees, or nil when unknown
95
+ # @example
96
+ # cinema = PicturehouseUk::Cinema.new(19)
97
+ # cinema.longitude
98
+ # #=> -0.139400005340576
99
+ def longitude
100
+ coordinates&.last
101
+ end
102
+
83
103
  # The name of the cinema
84
104
  # @return [String]
85
105
  # @example
@@ -114,6 +134,13 @@ module PicturehouseUk
114
134
  end
115
135
  end
116
136
 
137
+ # 0, 0 marks a site whose position was never set
138
+ def coordinates
139
+ location = site_hash['location'] || {}
140
+ pair = [location['latitude'], location['longitude']]
141
+ pair.map(&:to_f) if pair.all?(Numeric) && pair.any?(&:nonzero?)
142
+ end
143
+
117
144
  def site_hash
118
145
  @site_hash ||= self.class.send(:sites_hash).fetch(id, {})
119
146
  end
@@ -12,23 +12,37 @@ module PicturehouseUk
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 zero-padded site id, e.g. '019'
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
- # Picturehouse's API rejects every Connect-Region-Code, so send none.
28
+ def get(path, query = {})
29
+ client.get(path, query)
30
+ rescue Cinebase::Vista::AuthenticationError
31
+ PicturehouseUk.reject_token!(@client_token)
32
+ raise
33
+ end
34
+
35
+ # One client keeps one connection open, so reuse it until the token
36
+ # changes. Picturehouse's API rejects every Connect-Region-Code, so
37
+ # send none.
29
38
  def client
30
- Cinebase::Vista::Client.new(base_url: BASE_URL, region_code: nil,
31
- token: PicturehouseUk.token)
39
+ token = PicturehouseUk.token
40
+ if @client.nil? || @client_token != token
41
+ @client_token = token
42
+ @client = Cinebase::Vista::Client.new(base_url: BASE_URL, region_code: nil,
43
+ token: token)
44
+ end
45
+ @client
32
46
  end
33
47
  end
34
48
  end
@@ -1,6 +1,6 @@
1
1
  # Ruby interface for https://www.picturehouses.com
2
- # @version 6.0.0
2
+ # @version 6.1.0
3
3
  module PicturehouseUk
4
4
  # Gem version
5
- VERSION = '6.0.0'.freeze
5
+ VERSION = '6.1.0'.freeze
6
6
  end
@@ -18,13 +18,10 @@ require_relative './picturehouse_uk/performance'
18
18
  module PicturehouseUk
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
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'simplecov', '< 1'
26
26
  spec.add_development_dependency 'webmock'
27
27
 
28
- spec.add_runtime_dependency 'cinebase', '~> 5.4'
28
+ spec.add_runtime_dependency 'cinebase', '~> 5.6'
29
29
  end
@@ -3,6 +3,7 @@
3
3
  {
4
4
  "id": "002",
5
5
  "name": { "text": "Arts Picturehouse Cambridge" },
6
+ "location": { "latitude": 0, "longitude": 0 },
6
7
  "contactDetails": {
7
8
  "addressV2": {
8
9
  "line1": { "text": "1 Example Street" },
@@ -15,6 +16,7 @@
15
16
  {
16
17
  "id": "013",
17
18
  "name": { "text": "Picturehouse at FACT Liverpool" },
19
+ "location": null,
18
20
  "contactDetails": {
19
21
  "addressV2": {
20
22
  "line1": { "text": "2 Example Street" },
@@ -27,6 +29,7 @@
27
29
  {
28
30
  "id": "019",
29
31
  "name": { "text": "Duke's at Komedia" },
32
+ "location": { "latitude": 50.8247985839844, "longitude": -0.139400005340576 },
30
33
  "contactDetails": {
31
34
  "addressV2": {
32
35
  "line1": { "text": "3 Example Street" },
@@ -50,6 +50,29 @@ class PicturehouseUk::CinemaTest < Minitest::Test
50
50
  assert_equal 'Picturehouse', PicturehouseUk::Cinema.new(19).brand
51
51
  end
52
52
 
53
+ def test_latitude_and_longitude
54
+ with_fake_api do
55
+ cinema = PicturehouseUk::Cinema.new(19)
56
+
57
+ assert_in_delta 50.8248, cinema.latitude, 0.0001
58
+ assert_in_delta(-0.1394, cinema.longitude, 0.0001)
59
+ end
60
+ end
61
+
62
+ def test_latitude_and_longitude_are_nil_without_a_location
63
+ with_fake_api do
64
+ assert_nil PicturehouseUk::Cinema.new(13).latitude
65
+ assert_nil PicturehouseUk::Cinema.new(13).longitude
66
+ end
67
+ end
68
+
69
+ def test_latitude_and_longitude_are_nil_at_zero_zero
70
+ with_fake_api do
71
+ assert_nil PicturehouseUk::Cinema.new(2).latitude
72
+ assert_nil PicturehouseUk::Cinema.new(2).longitude
73
+ end
74
+ end
75
+
53
76
  def test_name_and_full_name
54
77
  with_fake_api do
55
78
  assert_equal "Duke's at Komedia", PicturehouseUk::Cinema.new(19).name
@@ -44,8 +44,44 @@ class PicturehouseUk::Internal::ApiResponseTest < Minitest::Test
44
44
  assert_raises(PicturehouseUk::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(PicturehouseUk::AuthenticationError) { api.sites }
51
+
52
+ assert_nil PicturehouseUk.token
53
+ end
54
+
55
+ def test_reuses_one_client_while_the_token_holds
56
+ stub_request(:get, "#{BASE_URL}/sites").to_return(status: 200, body: sites_json)
57
+ shared = api
58
+
59
+ assert_equal 1, count_clients { 3.times { shared.sites } }
60
+ end
61
+
62
+ def test_builds_a_new_client_for_a_new_token
63
+ stub_request(:get, "#{BASE_URL}/sites").to_return(status: 200, body: sites_json)
64
+ shared = api
65
+
66
+ clients = count_clients do
67
+ shared.sites
68
+ PicturehouseUk.token = 'renewed-jwt'
69
+ shared.sites
70
+ end
71
+
72
+ assert_equal 2, clients
73
+ end
74
+
47
75
  private
48
76
 
77
+ def count_clients
78
+ clients = 0
79
+ original = Cinebase::Vista::Client.method(:new)
80
+ counting = ->(**options) { clients += 1; original.call(**options) }
81
+ Cinebase::Vista::Client.stub(:new, counting) { yield }
82
+ clients
83
+ end
84
+
49
85
  def api
50
86
  PicturehouseUk::Internal::ApiResponse.new
51
87
  end
@@ -38,6 +38,13 @@ class PicturehouseUk::Internal::GuestTokenTest < Minitest::Test
38
38
  assert_raises(PicturehouseUk::AuthenticationError) { guest_token(curl).fetch }
39
39
  end
40
40
 
41
+ def test_ensure_token_fetches_only_without_a_current_token
42
+ token = token_expiring_at(Time.now + 7200)
43
+
44
+ assert_equal token, PicturehouseUk.ensure_token!(curl: fake_curl("#{page_with(token)}\n200"))
45
+ assert_equal token, PicturehouseUk.ensure_token!(curl: File.join(@directory, 'missing'))
46
+ end
47
+
41
48
  def test_acquire_token_sets_token
42
49
  token = token_expiring_at(Time.now + 3600)
43
50
 
@@ -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 = PicturehouseUk::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: picturehouse_uk
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: x86_64-linux-gnu
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 Picturehouse Vista API
125
125
  email:
126
126
  - andy@goodscary.com