nexus_mods 2.2.0 → 2.3.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 +6 -0
- data/lib/nexus_mods/api_client.rb +15 -0
- data/lib/nexus_mods/version.rb +1 -1
- data/lib/nexus_mods.rb +47 -1
- data/spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_caching_spec.rb +48 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d5efb3b98f3d8b66565eff56b7b6360fc99bae69a256423e6eae391eb3cd676
|
4
|
+
data.tar.gz: 7091d96c8a79ec591e805bcc09958199187b5f0afd73de85b5da314c2e24381a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1485e5270d8fcffb7a2ebfec15848f0f2af3a2575beef6b2d1c4746af682bd13142d15f140adae1c9e7c15d731d85d63d01ec135f28600e73d58249bc130990e
|
7
|
+
data.tar.gz: eccb9f4312f63a8c8fc459592c4c0c618378f59a69a261512981e890c0bfffa8c2044bafbcd16da9ec9c8d3b980a53a2e5322a89c5eece959240cafb7ac05e19
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# [v2.3.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v2.2.0...v2.3.0) (2023-04-12 15:08:22)
|
2
|
+
|
3
|
+
### Features
|
4
|
+
|
5
|
+
* [[Feature] Add a way to set cache timestamps manually](https://github.com/Muriel-Salvan/nexus_mods/commit/7e5ac1d16d1d31f4aa33ebb9a748310e4572a06f)
|
6
|
+
|
1
7
|
# [v2.2.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v2.1.0...v2.2.0) (2023-04-12 12:56:31)
|
2
8
|
|
3
9
|
### Features
|
@@ -76,6 +76,21 @@ class NexusMods
|
|
76
76
|
str_time.nil? ? nil : Time.parse(str_time)
|
77
77
|
end
|
78
78
|
|
79
|
+
# Set the timestamp of the cached data linked to a given API call.
|
80
|
+
# This should be used only to update the cache timestamp of a resource we know is still up-to-date without fetching the resource for real again.
|
81
|
+
#
|
82
|
+
# Parameters::
|
83
|
+
# * *path* (String): API path to contact (from v1/ and without .json)
|
84
|
+
# * *parameters* (Hash<Symbol,Object>): Optional parameters to add to the path [default: {}]
|
85
|
+
# * *verb* (Symbol): Verb to be used (:get, :post...) [default: :get]
|
86
|
+
# * *cache_timestamp* (Time): The cache timestamp to set for this resource
|
87
|
+
def set_api_cache_timestamp(path, cache_timestamp:, parameters: {}, verb: :get)
|
88
|
+
key = ApiClient.cache_key(path, parameters:, verb:)
|
89
|
+
Cacheable.cache_adapter.context[key] = {} unless Cacheable.cache_adapter.context.key?(key)
|
90
|
+
Cacheable.cache_adapter.context[key]['invalidate_time'] = cache_timestamp.utc.strftime('%FT%T.%9NUTC')
|
91
|
+
save_api_cache
|
92
|
+
end
|
93
|
+
|
79
94
|
# Send an HTTP request to the API and get back the HTTP response
|
80
95
|
#
|
81
96
|
# Parameters::
|
data/lib/nexus_mods/version.rb
CHANGED
data/lib/nexus_mods.rb
CHANGED
@@ -151,6 +151,15 @@ class NexusMods
|
|
151
151
|
@api_client.api_cache_timestamp('games')
|
152
152
|
end
|
153
153
|
|
154
|
+
# Set the cached timestamp of the list of games.
|
155
|
+
# This should be used only to update the cache timestamp of a resource we know is still up-to-date without fetching the resource for real again.
|
156
|
+
#
|
157
|
+
# Parameters::
|
158
|
+
# * *cache_timestamp* (Time): The cache timestamp to set for this resource
|
159
|
+
def set_games_cache_timestamp(cache_timestamp:)
|
160
|
+
@api_client.set_api_cache_timestamp('games', cache_timestamp:)
|
161
|
+
end
|
162
|
+
|
154
163
|
# Get information about a mod
|
155
164
|
#
|
156
165
|
# Parameters::
|
@@ -202,6 +211,17 @@ class NexusMods
|
|
202
211
|
@api_client.api_cache_timestamp("games/#{game_domain_name}/mods/#{mod_id}")
|
203
212
|
end
|
204
213
|
|
214
|
+
# Set the cached timestamp of a mod information.
|
215
|
+
# This should be used only to update the cache timestamp of a resource we know is still up-to-date without fetching the resource for real again.
|
216
|
+
#
|
217
|
+
# Parameters::
|
218
|
+
# * *game_domain_name* (String): Game domain name to query by default [default: @game_domain_name]
|
219
|
+
# * *mod_id* (Integer): The mod ID [default: @mod_id]
|
220
|
+
# * *cache_timestamp* (Time): The cache timestamp to set for this resource
|
221
|
+
def set_mod_cache_timestamp(cache_timestamp:, game_domain_name: @game_domain_name, mod_id: @mod_id)
|
222
|
+
@api_client.set_api_cache_timestamp("games/#{game_domain_name}/mods/#{mod_id}", cache_timestamp:)
|
223
|
+
end
|
224
|
+
|
205
225
|
# Get files belonging to a mod
|
206
226
|
#
|
207
227
|
# Parameters::
|
@@ -244,6 +264,17 @@ class NexusMods
|
|
244
264
|
@api_client.api_cache_timestamp("games/#{game_domain_name}/mods/#{mod_id}/files")
|
245
265
|
end
|
246
266
|
|
267
|
+
# Set the cached timestamp of a mod files information.
|
268
|
+
# This should be used only to update the cache timestamp of a resource we know is still up-to-date without fetching the resource for real again.
|
269
|
+
#
|
270
|
+
# Parameters::
|
271
|
+
# * *game_domain_name* (String): Game domain name to query by default [default: @game_domain_name]
|
272
|
+
# * *mod_id* (Integer): The mod ID [default: @mod_id]
|
273
|
+
# * *cache_timestamp* (Time): The cache timestamp to set for this resource
|
274
|
+
def set_mod_files_cache_timestamp(cache_timestamp:, game_domain_name: @game_domain_name, mod_id: @mod_id)
|
275
|
+
@api_client.set_api_cache_timestamp("games/#{game_domain_name}/mods/#{mod_id}/files", cache_timestamp:)
|
276
|
+
end
|
277
|
+
|
247
278
|
# Get a list of updated mod ids since a given time
|
248
279
|
#
|
249
280
|
# Parameters::
|
@@ -266,7 +297,7 @@ class NexusMods
|
|
266
297
|
end
|
267
298
|
end
|
268
299
|
|
269
|
-
# Get the cached timestamp of
|
300
|
+
# Get the cached timestamp of updated mod ids
|
270
301
|
#
|
271
302
|
# Parameters::
|
272
303
|
# * *game_domain_name* (String): Game domain name to query by default [default: @game_domain_name]
|
@@ -281,6 +312,21 @@ class NexusMods
|
|
281
312
|
@api_client.api_cache_timestamp("games/#{game_domain_name}/mods/updated", parameters: period_to_url_params(since))
|
282
313
|
end
|
283
314
|
|
315
|
+
# Set the cached timestamp of updated mod ids.
|
316
|
+
# This should be used only to update the cache timestamp of a resource we know is still up-to-date without fetching the resource for real again.
|
317
|
+
#
|
318
|
+
# Parameters::
|
319
|
+
# * *game_domain_name* (String): Game domain name to query by default [default: @game_domain_name]
|
320
|
+
# * *since* (Symbol): The time from which we look for updated mods [default: :one_day]
|
321
|
+
# Possible values are:
|
322
|
+
# * *one_day*: Since 1 day
|
323
|
+
# * *one_week*: Since 1 week
|
324
|
+
# * *one_month*: Since 1 month
|
325
|
+
# * *cache_timestamp* (Time): The cache timestamp to set for this resource
|
326
|
+
def set_updated_mods_cache_timestamp(cache_timestamp:, game_domain_name: @game_domain_name, since: :one_day)
|
327
|
+
@api_client.set_api_cache_timestamp("games/#{game_domain_name}/mods/updated", parameters: period_to_url_params(since), cache_timestamp:)
|
328
|
+
end
|
329
|
+
|
284
330
|
private
|
285
331
|
|
286
332
|
# Get the URL parameters from the required period
|
@@ -20,6 +20,7 @@ describe NexusMods do
|
|
20
20
|
query: proc { |nm| nm.games },
|
21
21
|
query_without_cache: proc { |nm| nm.games(clear_cache: true) },
|
22
22
|
get_cache_timestamp: proc { |nm| nm.games_cache_timestamp },
|
23
|
+
set_cache_timestamp: proc { |nm, ts| nm.set_games_cache_timestamp(cache_timestamp: ts) },
|
23
24
|
expiry_cache_param: :games
|
24
25
|
},
|
25
26
|
'mods' => {
|
@@ -28,6 +29,7 @@ describe NexusMods do
|
|
28
29
|
query: proc { |nm| nm.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014) },
|
29
30
|
query_without_cache: proc { |nm| nm.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014, clear_cache: true) },
|
30
31
|
get_cache_timestamp: proc { |nm| nm.mod_cache_timestamp(game_domain_name: 'skyrimspecialedition', mod_id: 2014) },
|
32
|
+
set_cache_timestamp: proc { |nm, ts| nm.set_mod_cache_timestamp(game_domain_name: 'skyrimspecialedition', mod_id: 2014, cache_timestamp: ts) },
|
31
33
|
expiry_cache_param: :mod
|
32
34
|
},
|
33
35
|
'mod files' => {
|
@@ -41,6 +43,7 @@ describe NexusMods do
|
|
41
43
|
query: proc { |nm| nm.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014) },
|
42
44
|
query_without_cache: proc { |nm| nm.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014, clear_cache: true) },
|
43
45
|
get_cache_timestamp: proc { |nm| nm.mod_files_cache_timestamp(game_domain_name: 'skyrimspecialedition', mod_id: 2014) },
|
46
|
+
set_cache_timestamp: proc { |nm, ts| nm.set_mod_files_cache_timestamp(game_domain_name: 'skyrimspecialedition', mod_id: 2014, cache_timestamp: ts) },
|
44
47
|
expiry_cache_param: :mod_files
|
45
48
|
}
|
46
49
|
}.merge(
|
@@ -68,7 +71,8 @@ describe NexusMods do
|
|
68
71
|
],
|
69
72
|
query: proc { |nm| nm.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since]) },
|
70
73
|
query_without_cache: proc { |nm| nm.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since], clear_cache: true) },
|
71
|
-
get_cache_timestamp: proc { |nm| nm.updated_mods_cache_timestamp(game_domain_name: 'skyrimspecialedition', since: since_config[:since]) }
|
74
|
+
get_cache_timestamp: proc { |nm| nm.updated_mods_cache_timestamp(game_domain_name: 'skyrimspecialedition', since: since_config[:since]) },
|
75
|
+
set_cache_timestamp: proc { |nm, ts| nm.set_updated_mods_cache_timestamp(game_domain_name: 'skyrimspecialedition', since: since_config[:since], cache_timestamp: ts) }
|
72
76
|
}
|
73
77
|
]
|
74
78
|
end
|
@@ -131,6 +135,18 @@ describe NexusMods do
|
|
131
135
|
expect(resource_config[:get_cache_timestamp].call(nexus_mods)).to be_between(before, after)
|
132
136
|
end
|
133
137
|
|
138
|
+
it 'changes manually the timestamp of the data stored in the API cache' do
|
139
|
+
expect_validate_user
|
140
|
+
expect_http_call_to(
|
141
|
+
path: resource_config[:expected_api_path],
|
142
|
+
json: resource_config[:mocked_api_json]
|
143
|
+
)
|
144
|
+
resource_config[:query].call(nexus_mods)
|
145
|
+
new_cache_timestamp = Time.parse('2023-01-12 11:22:33 UTC')
|
146
|
+
resource_config[:set_cache_timestamp].call(nexus_mods, new_cache_timestamp)
|
147
|
+
expect(resource_config[:get_cache_timestamp].call(nexus_mods)).to eq new_cache_timestamp
|
148
|
+
end
|
149
|
+
|
134
150
|
it 'retrieves the timestamp of the games data stored in the cache even after cache is used' do
|
135
151
|
expect_validate_user
|
136
152
|
expect_http_call_to(
|
@@ -159,7 +175,22 @@ describe NexusMods do
|
|
159
175
|
end
|
160
176
|
end
|
161
177
|
|
162
|
-
it '
|
178
|
+
it 'persists the cache timestamp that has been changed manually' do
|
179
|
+
with_api_cache_file do |api_cache_file|
|
180
|
+
expect_validate_user(times: 2)
|
181
|
+
expect_http_call_to(
|
182
|
+
path: resource_config[:expected_api_path],
|
183
|
+
json: resource_config[:mocked_api_json]
|
184
|
+
)
|
185
|
+
resource_config[:query].call(nexus_mods(api_cache_file:))
|
186
|
+
new_cache_timestamp = Time.parse('2023-01-12 11:22:33 UTC')
|
187
|
+
resource_config[:set_cache_timestamp].call(nexus_mods, new_cache_timestamp)
|
188
|
+
reset_nexus_mods
|
189
|
+
expect(resource_config[:get_cache_timestamp].call(nexus_mods(api_cache_file:))).to eq new_cache_timestamp
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'updates the timestamp of the data stored in the API cache by forcing an API query' do
|
163
194
|
expect_validate_user
|
164
195
|
expect_http_call_to(
|
165
196
|
path: resource_config[:expected_api_path],
|
@@ -174,6 +205,21 @@ describe NexusMods do
|
|
174
205
|
expect(resource_config[:get_cache_timestamp].call(nexus_mods)).to be_between(before, after)
|
175
206
|
end
|
176
207
|
|
208
|
+
it 'updates the timestamp of the data stored in the API cache by updating manually the cache timestamp' do
|
209
|
+
expect_validate_user
|
210
|
+
expect_http_call_to(
|
211
|
+
path: resource_config[:expected_api_path],
|
212
|
+
json: resource_config[:mocked_api_json],
|
213
|
+
times: 2
|
214
|
+
)
|
215
|
+
resource_config[:query].call(nexus_mods)
|
216
|
+
resource_config[:set_cache_timestamp].call(nexus_mods, Time.now.utc - (365 * 24 * 60 * 60))
|
217
|
+
before = Time.now
|
218
|
+
resource_config[:query].call(nexus_mods)
|
219
|
+
after = Time.now
|
220
|
+
expect(resource_config[:get_cache_timestamp].call(nexus_mods)).to be_between(before, after)
|
221
|
+
end
|
222
|
+
|
177
223
|
context 'when testing cache persistence in files' do
|
178
224
|
|
179
225
|
it 'persists API cache in a file' do
|