picturehouse_uk 6.0.0 → 6.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 +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -0
- data/README.md +21 -3
- data/lib/picturehouse_uk/cinema.rb +27 -0
- data/lib/picturehouse_uk/internal/api_response.rb +19 -5
- data/lib/picturehouse_uk/version.rb +2 -2
- data/lib/picturehouse_uk.rb +5 -8
- data/picturehouse_uk.gemspec +1 -1
- data/test/fixtures/api/sites.json +3 -0
- data/test/lib/picturehouse_uk/cinema_test.rb +23 -0
- data/test/lib/picturehouse_uk/internal/api_response_test.rb +36 -0
- data/test/lib/picturehouse_uk/internal/guest_token_test.rb +7 -0
- data/test/live/integration_test.rb +10 -0
- data/test/support/api_shapes.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cef25f6e072bfc5815d9d5735f65e8cb04a02b08d12878cc18e9b24b7c1fd37
|
|
4
|
+
data.tar.gz: 355a2ed6038015dc13bf343877eee1e7ce4000b79d777ffb32d854469bb7ba45
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 51d87437c51cb449edc1a230fdbebe96581897f5cbf79c5ba328660bf4ff157fc664cae347727bdf753a064d886dc3513e1f46b344515adb63c721e08e4e40b2
|
|
7
|
+
data.tar.gz: 6130b97bb1ef8b58c19c05ddcf80226ec0c7644065632553a9a345c882c1a6844c688fd9082c46c3ccabdbd3f5787d4d893e81a4c0f6ee982af2e216b88d9333
|
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
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.
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
+
get("showtimes/by-business-date/#{date.iso8601}",
|
|
23
23
|
"siteIds" => cinema_id)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
private
|
|
27
27
|
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
data/lib/picturehouse_uk.rb
CHANGED
|
@@ -18,13 +18,10 @@ require_relative './picturehouse_uk/performance'
|
|
|
18
18
|
module PicturehouseUk
|
|
19
19
|
AuthenticationError = Cinebase::Vista::AuthenticationError
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
data/picturehouse_uk.gemspec
CHANGED
|
@@ -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
|
data/test/support/api_shapes.rb
CHANGED
|
@@ -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.
|
|
4
|
+
version: 6.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.
|
|
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.
|
|
123
|
+
version: '5.6'
|
|
124
124
|
description: Pull movie & cinema information from the Picturehouse Vista API
|
|
125
125
|
email:
|
|
126
126
|
- andy@goodscary.com
|