nexus_mods 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/nexus_mods/api/mod_updates.rb +49 -0
- data/lib/nexus_mods/api_client.rb +29 -16
- data/lib/nexus_mods/version.rb +1 -1
- data/lib/nexus_mods.rb +31 -1
- data/spec/nexus_mods_test/factories/mod_files.rb +2 -2
- data/spec/nexus_mods_test/factories/mod_updates.rb +49 -0
- data/spec/nexus_mods_test/helpers.rb +2 -0
- data/spec/nexus_mods_test/scenarios/nexus_mods/api/mod_updates_spec.rb +91 -0
- data/spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_caching_spec.rb +63 -15
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac9b76be57a989b2cd00cb120912dc8360fc926e76589769b725879f582e7d82
|
4
|
+
data.tar.gz: 61342738bb1678bdbbbf350bf645b90210c55c8b53a63bdbb9cc755ca6f146bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ad0436dd7917b94ebbedaa26e7f943a92520b0336413730e273108849b7f2659e026954ad1a68570e99c27ad6654a6c970be208ec500078a4490e65930ce896
|
7
|
+
data.tar.gz: 67a49c5e42db887253894726eed4b7ff3adde7f6da0f31d123ce6587117abb99d80a26e9a0db69bb541368fec4c6561b3b0a9564a8fe5ac27a412b0fb3c0173e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# [v2.1.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v2.0.1...v2.1.0) (2023-04-11 18:24:04)
|
2
|
+
|
3
|
+
### Features
|
4
|
+
|
5
|
+
* [[Feature] Add API entry point to retrieve last updated mods](https://github.com/Muriel-Salvan/nexus_mods/commit/cf702fc2c146cc7d61aadca005aa0e784b807c44)
|
6
|
+
|
1
7
|
# [v2.0.1](https://github.com/Muriel-Salvan/nexus_mods/compare/v2.0.0...v2.0.1) (2023-04-11 10:22:54)
|
2
8
|
|
3
9
|
### Patches
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class NexusMods
|
2
|
+
|
3
|
+
module Api
|
4
|
+
|
5
|
+
# A NexusMods mod updates.
|
6
|
+
class ModUpdates
|
7
|
+
|
8
|
+
attr_reader(
|
9
|
+
*%i[
|
10
|
+
mod_id
|
11
|
+
latest_file_update
|
12
|
+
latest_mod_activity
|
13
|
+
]
|
14
|
+
)
|
15
|
+
|
16
|
+
# Constructor
|
17
|
+
#
|
18
|
+
# Parameters::
|
19
|
+
# * *mod_id* (Integer): The mod's id
|
20
|
+
# * *latest_file_update* (Time): The mod's latest file update
|
21
|
+
# * *latest_mod_activity* (Time): The mod's latest activity
|
22
|
+
def initialize(
|
23
|
+
mod_id:,
|
24
|
+
latest_file_update:,
|
25
|
+
latest_mod_activity:
|
26
|
+
)
|
27
|
+
@mod_id = mod_id
|
28
|
+
@latest_file_update = latest_file_update
|
29
|
+
@latest_mod_activity = latest_mod_activity
|
30
|
+
end
|
31
|
+
|
32
|
+
# Equality operator
|
33
|
+
#
|
34
|
+
# Parameters::
|
35
|
+
# * *other* (Object): Other object to compare with
|
36
|
+
# Result::
|
37
|
+
# * Boolean: Are objects equal?
|
38
|
+
def ==(other)
|
39
|
+
other.is_a?(ModUpdates) &&
|
40
|
+
@mod_id == other.mod_id &&
|
41
|
+
@latest_file_update == other.latest_file_update &&
|
42
|
+
@latest_mod_activity == other.latest_mod_activity
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -50,25 +50,27 @@ class NexusMods
|
|
50
50
|
#
|
51
51
|
# Parameters::
|
52
52
|
# * *path* (String): API path to contact (from v1/ and without .json)
|
53
|
+
# * *parameters* (Hash<Symbol,Object>): Optional parameters to add to the path [default: {}]
|
53
54
|
# * *verb* (Symbol): Verb to be used (:get, :post...) [default: :get]
|
54
55
|
# * *clear_cache* (Boolean): Should we clear the API cache for this resource? [default: false]
|
55
56
|
# Result::
|
56
57
|
# * Object: The JSON response
|
57
|
-
def api(path, verb: :get, clear_cache: false)
|
58
|
-
clear_cached_api_cache(path, verb:) if clear_cache
|
59
|
-
cached_api(path, verb:)
|
58
|
+
def api(path, parameters: {}, verb: :get, clear_cache: false)
|
59
|
+
clear_cached_api_cache(path, parameters:, verb:) if clear_cache
|
60
|
+
cached_api(path, parameters:, verb:)
|
60
61
|
end
|
61
62
|
|
62
63
|
# Send an HTTP request to the API and get back the HTTP response
|
63
64
|
#
|
64
65
|
# Parameters::
|
65
66
|
# * *path* (String): API path to contact (from v1/ and without .json)
|
67
|
+
# * *parameters* (Hash<Symbol,Object>): Optional parameters to add to the path [default: {}]
|
66
68
|
# * *verb* (Symbol): Verb to be used (:get, :post...) [default: :get]
|
67
69
|
# Result::
|
68
70
|
# * Faraday::Response: The HTTP response
|
69
|
-
def http(path, verb: :get)
|
71
|
+
def http(path, parameters: {}, verb: :get)
|
70
72
|
@http_client.send(verb) do |req|
|
71
|
-
req.url api_uri(path)
|
73
|
+
req.url api_uri(path, parameters:)
|
72
74
|
req.headers['apikey'] = @api_key
|
73
75
|
req.headers['User-Agent'] = "nexus_mods/#{NexusMods::VERSION} (#{RUBY_PLATFORM}) Ruby/#{RUBY_VERSION}"
|
74
76
|
end
|
@@ -106,11 +108,12 @@ class NexusMods
|
|
106
108
|
#
|
107
109
|
# Parameters::
|
108
110
|
# * *path* (String): API path to contact (from v1/ and without .json)
|
111
|
+
# * *parameters* (Hash<Symbol,Object>): Optional parameters to add to the path [default: {}]
|
109
112
|
# * *verb* (Symbol): Verb to be used (:get, :post...) [default: :get]
|
110
113
|
# Result::
|
111
114
|
# * Object: The JSON response
|
112
|
-
def cached_api(path, verb: :get)
|
113
|
-
res = http(path, verb:)
|
115
|
+
def cached_api(path, parameters: {}, verb: :get)
|
116
|
+
res = http(path, parameters:, verb:)
|
114
117
|
json = JSON.parse(res.body)
|
115
118
|
uri = api_uri(path)
|
116
119
|
@logger.debug "[API call] - #{verb} #{uri} => #{res.status}\n#{
|
@@ -139,11 +142,14 @@ class NexusMods
|
|
139
142
|
cacheable_api(
|
140
143
|
:cached_api,
|
141
144
|
key_format: proc do |_target, _method_name, method_args, method_kwargs|
|
142
|
-
"#{method_kwargs[:verb]}/#{method_args.first}
|
145
|
+
"#{method_kwargs[:verb]}/#{method_args.first}#{
|
146
|
+
method_kwargs[:parameters].empty? ? '' : "/#{method_kwargs[:parameters].map { |param, value| "#{param}=#{value}" }.sort.join('/')}"
|
147
|
+
}"
|
143
148
|
end,
|
144
149
|
expiry_from_key: proc do |key|
|
145
150
|
# Example of keys:
|
146
151
|
# get/games
|
152
|
+
# get/games/skyrimspecialedition/mods/updated/period=1d
|
147
153
|
# get/games/skyrimspecialedition/mods/2014
|
148
154
|
# get/games/skyrimspecialedition/mods/2014/files
|
149
155
|
# get/users/validate
|
@@ -155,13 +161,19 @@ class NexusMods
|
|
155
161
|
else
|
156
162
|
case key_components[2]
|
157
163
|
when 'mods'
|
158
|
-
case key_components[
|
159
|
-
when
|
160
|
-
|
161
|
-
|
162
|
-
ApiClient.api_client.api_cache_expiry[:mod_files]
|
164
|
+
case key_components[3]
|
165
|
+
when 'updated'
|
166
|
+
# According to the API doc, this is updated every 5 minutes
|
167
|
+
5 * 60
|
163
168
|
else
|
164
|
-
|
169
|
+
case key_components[4]
|
170
|
+
when nil
|
171
|
+
ApiClient.api_client.api_cache_expiry[:mod]
|
172
|
+
when 'files'
|
173
|
+
ApiClient.api_client.api_cache_expiry[:mod_files]
|
174
|
+
else
|
175
|
+
raise "Unknown API path: #{key}"
|
176
|
+
end
|
165
177
|
end
|
166
178
|
else
|
167
179
|
raise "Unknown API path: #{key}"
|
@@ -183,10 +195,11 @@ class NexusMods
|
|
183
195
|
#
|
184
196
|
# Parameters::
|
185
197
|
# * *path* (String): API path to contact (from v1/ and without .json)
|
198
|
+
# * *parameters* (Hash<Symbol,Object>): Optional parameters to add to the path [default: {}]
|
186
199
|
# Result::
|
187
200
|
# * String: The URI
|
188
|
-
def api_uri(path)
|
189
|
-
"https://api.nexusmods.com/v1/#{path}.json"
|
201
|
+
def api_uri(path, parameters: {})
|
202
|
+
"https://api.nexusmods.com/v1/#{path}.json#{parameters.empty? ? '' : "?#{parameters.map { |param, value| "#{param}=#{value}" }.join('&')}"}"
|
190
203
|
end
|
191
204
|
|
192
205
|
end
|
data/lib/nexus_mods/version.rb
CHANGED
data/lib/nexus_mods.rb
CHANGED
@@ -8,6 +8,7 @@ require 'nexus_mods/api/game'
|
|
8
8
|
require 'nexus_mods/api/user'
|
9
9
|
require 'nexus_mods/api/mod'
|
10
10
|
require 'nexus_mods/api/mod_file'
|
11
|
+
require 'nexus_mods/api/mod_updates'
|
11
12
|
|
12
13
|
# Ruby API to access NexusMods REST API
|
13
14
|
class NexusMods
|
@@ -130,7 +131,7 @@ class NexusMods
|
|
130
131
|
nexusmods_url: game_json['nexusmods_url'],
|
131
132
|
genre: game_json['genre'],
|
132
133
|
domain_name: game_json['domain_name'],
|
133
|
-
approved_date: Time.at(game_json['approved_date']),
|
134
|
+
approved_date: Time.at(game_json['approved_date']).utc,
|
134
135
|
files_count: game_json['file_count'],
|
135
136
|
files_views: game_json['file_views'],
|
136
137
|
files_endorsements: game_json['file_endorsements'],
|
@@ -213,4 +214,33 @@ class NexusMods
|
|
213
214
|
end
|
214
215
|
end
|
215
216
|
|
217
|
+
# Get a list of updated mod ids since a given time
|
218
|
+
#
|
219
|
+
# Parameters::
|
220
|
+
# * *game_domain_name* (String): Game domain name to query by default [default: @game_domain_name]
|
221
|
+
# * *since* (Symbol): The time from which we look for updated mods [default: :one_day]
|
222
|
+
# Possible values are:
|
223
|
+
# * *one_day*: Since 1 day
|
224
|
+
# * *one_week*: Since 1 week
|
225
|
+
# * *one_month*: Since 1 month
|
226
|
+
# * *clear_cache* (Boolean): Should we clear the API cache for this resource? [default: false]
|
227
|
+
# Result::
|
228
|
+
# * Array<ModUpdates>: Mod's updates information
|
229
|
+
def updated_mods(game_domain_name: @game_domain_name, since: :one_day, clear_cache: false)
|
230
|
+
nexus_mods_period = {
|
231
|
+
one_day: '1d',
|
232
|
+
one_week: '1w',
|
233
|
+
one_month: '1m'
|
234
|
+
}[since]
|
235
|
+
raise "Unknown time stamp: #{since}" if nexus_mods_period.nil?
|
236
|
+
|
237
|
+
@api_client.api("games/#{game_domain_name}/mods/updated", parameters: { period: nexus_mods_period }, clear_cache:).map do |updated_mod_json|
|
238
|
+
Api::ModUpdates.new(
|
239
|
+
mod_id: updated_mod_json['mod_id'],
|
240
|
+
latest_file_update: Time.at(updated_mod_json['latest_file_update']).utc,
|
241
|
+
latest_mod_activity: Time.at(updated_mod_json['latest_mod_activity']).utc
|
242
|
+
)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
216
246
|
end
|
@@ -63,7 +63,7 @@ module NexusModsTest
|
|
63
63
|
# Expect a mod's file to be the example one with id 2472
|
64
64
|
#
|
65
65
|
# Parameters::
|
66
|
-
# * *mod_file* (NexusMods::Api::
|
66
|
+
# * *mod_file* (NexusMods::Api::ModFile): Mod file to validate
|
67
67
|
def expect_mod_file_to_be2472(mod_file)
|
68
68
|
expect(mod_file.ids).to eq [2472, 1704]
|
69
69
|
expect(mod_file.uid).to eq 7_318_624_274_856
|
@@ -87,7 +87,7 @@ module NexusModsTest
|
|
87
87
|
# Expect a mod's file to be the example one with id 2487
|
88
88
|
#
|
89
89
|
# Parameters::
|
90
|
-
# * *mod_file* (NexusMods::Api::
|
90
|
+
# * *mod_file* (NexusMods::Api::ModFile): Mod file to validate
|
91
91
|
def expect_mod_file_to_be2487(mod_file)
|
92
92
|
expect(mod_file.ids).to eq [2487, 1705]
|
93
93
|
expect(mod_file.uid).to eq 7_318_624_274_857
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module NexusModsTest
|
2
|
+
|
3
|
+
module Factories
|
4
|
+
|
5
|
+
module ModUpdates
|
6
|
+
|
7
|
+
# Test mod updates with id 2014
|
8
|
+
def json_mod_updates2014
|
9
|
+
{
|
10
|
+
'mod_id' => 2014,
|
11
|
+
'latest_file_update' => 1_655_813_855,
|
12
|
+
'latest_mod_activity' => 1_681_169_675
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Test mod updates with id 100
|
17
|
+
def json_mod_updates100
|
18
|
+
{
|
19
|
+
'mod_id' => 100,
|
20
|
+
'latest_file_update' => 1_681_143_964,
|
21
|
+
'latest_mod_activity' => 1_681_143_964
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Expect a mod's updates to be the example one with id 2014
|
26
|
+
#
|
27
|
+
# Parameters::
|
28
|
+
# * *mod_updates* (NexusMods::Api::ModUpdates): Mod updates to validate
|
29
|
+
def expect_mod_file_to_be2014(mod_updates)
|
30
|
+
expect(mod_updates.mod_id).to eq 2014
|
31
|
+
expect(mod_updates.latest_file_update).to eq Time.parse('2022-06-21 12:17:35 UTC')
|
32
|
+
expect(mod_updates.latest_mod_activity).to eq Time.parse('2023-04-10 23:34:35 UTC')
|
33
|
+
end
|
34
|
+
|
35
|
+
# Expect a mod's updates to be the example one with id 100
|
36
|
+
#
|
37
|
+
# Parameters::
|
38
|
+
# * *mod_updates* (NexusMods::Api::ModUpdates): Mod updates to validate
|
39
|
+
def expect_mod_file_to_be100(mod_updates)
|
40
|
+
expect(mod_updates.mod_id).to eq 100
|
41
|
+
expect(mod_updates.latest_file_update).to eq Time.parse('2023-04-10 16:26:04 UTC')
|
42
|
+
expect(mod_updates.latest_mod_activity).to eq Time.parse('2023-04-10 16:26:04 UTC')
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -4,6 +4,7 @@ require 'rspec/support/object_formatter'
|
|
4
4
|
require 'nexus_mods_test/factories/games'
|
5
5
|
require 'nexus_mods_test/factories/mods'
|
6
6
|
require 'nexus_mods_test/factories/mod_files'
|
7
|
+
require 'nexus_mods_test/factories/mod_updates'
|
7
8
|
require 'nexus_mods'
|
8
9
|
|
9
10
|
module NexusModsTest
|
@@ -180,6 +181,7 @@ RSpec.configure do |config|
|
|
180
181
|
config.include NexusModsTest::Factories::Games
|
181
182
|
config.include NexusModsTest::Factories::Mods
|
182
183
|
config.include NexusModsTest::Factories::ModFiles
|
184
|
+
config.include NexusModsTest::Factories::ModUpdates
|
183
185
|
config.before do
|
184
186
|
@nexus_mods = nil
|
185
187
|
# Reload the ApiClient as it stores caches at class level
|
@@ -0,0 +1,91 @@
|
|
1
|
+
describe NexusMods::Api::ModUpdates do
|
2
|
+
|
3
|
+
context 'when testing mod updates' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
expect_validate_user
|
7
|
+
end
|
8
|
+
|
9
|
+
# Expect the given array of mod updates to be the ones of examples (for mods 100 and 2014)
|
10
|
+
#
|
11
|
+
# Parameters::
|
12
|
+
# * *mod_updates* (Array<NexusMods::Api::ModUpdates>): The list of mod updates to validate
|
13
|
+
def expect_mod_updates_to_be_example(mod_updates)
|
14
|
+
sorted_mod_updates = mod_updates.sort_by(&:mod_id)
|
15
|
+
expect_mod_file_to_be100(sorted_mod_updates.first)
|
16
|
+
expect_mod_file_to_be2014(sorted_mod_updates[1])
|
17
|
+
end
|
18
|
+
|
19
|
+
{
|
20
|
+
'last day' => {
|
21
|
+
since: :one_day,
|
22
|
+
expected_url_params: 'period=1d'
|
23
|
+
},
|
24
|
+
'last week' => {
|
25
|
+
since: :one_week,
|
26
|
+
expected_url_params: 'period=1w'
|
27
|
+
},
|
28
|
+
'last month' => {
|
29
|
+
since: :one_month,
|
30
|
+
expected_url_params: 'period=1m'
|
31
|
+
}
|
32
|
+
}.each do |since, since_config|
|
33
|
+
|
34
|
+
context "when testing updated months since #{since}" do
|
35
|
+
|
36
|
+
it 'returns updated mods' do
|
37
|
+
expect_http_call_to(
|
38
|
+
path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
|
39
|
+
json: [
|
40
|
+
json_mod_updates2014,
|
41
|
+
json_mod_updates100
|
42
|
+
]
|
43
|
+
)
|
44
|
+
expect_mod_updates_to_be_example(nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since]))
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns updated mods information for the default game' do
|
48
|
+
expect_http_call_to(
|
49
|
+
path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
|
50
|
+
json: [
|
51
|
+
json_mod_updates2014,
|
52
|
+
json_mod_updates100
|
53
|
+
]
|
54
|
+
)
|
55
|
+
expect_mod_updates_to_be_example(nexus_mods(game_domain_name: 'skyrimspecialedition').updated_mods(since: since_config[:since]))
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns updated mods information for the default game set using accessor' do
|
59
|
+
expect_http_call_to(
|
60
|
+
path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
|
61
|
+
json: [
|
62
|
+
json_mod_updates2014,
|
63
|
+
json_mod_updates100
|
64
|
+
]
|
65
|
+
)
|
66
|
+
nexus_mods.game_domain_name = 'skyrimspecialedition'
|
67
|
+
expect_mod_updates_to_be_example(nexus_mods.updated_mods(since: since_config[:since]))
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'compares objects for equality' do
|
71
|
+
expect_http_call_to(
|
72
|
+
path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
|
73
|
+
json: [json_mod_updates2014]
|
74
|
+
)
|
75
|
+
mod_updates1 = nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since])
|
76
|
+
mod_updates2 = nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since])
|
77
|
+
expect(mod_updates1.object_id).not_to eq mod_updates2.object_id
|
78
|
+
expect(mod_updates1).to eq mod_updates2
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'fails to fetch updated mods for an unknown period' do
|
86
|
+
expect { nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: :unknown_since) }.to raise_error 'Unknown time stamp: unknown_since'
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -20,7 +20,7 @@ describe NexusMods do
|
|
20
20
|
]
|
21
21
|
)
|
22
22
|
games = nexus_mods.games
|
23
|
-
expect(nexus_mods.games).to eq
|
23
|
+
expect(nexus_mods.games).to eq games
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'does not cache games queries if asked' do
|
@@ -34,7 +34,7 @@ describe NexusMods do
|
|
34
34
|
times: 2
|
35
35
|
)
|
36
36
|
games = nexus_mods.games
|
37
|
-
expect(nexus_mods.games(clear_cache: true)).to eq
|
37
|
+
expect(nexus_mods.games(clear_cache: true)).to eq games
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'caches mod queries' do
|
@@ -44,7 +44,7 @@ describe NexusMods do
|
|
44
44
|
json: json_complete_mod
|
45
45
|
)
|
46
46
|
mod = nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014)
|
47
|
-
expect(nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq
|
47
|
+
expect(nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq mod
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'does not cache mod queries if asked' do
|
@@ -55,7 +55,7 @@ describe NexusMods do
|
|
55
55
|
times: 2
|
56
56
|
)
|
57
57
|
mod = nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014)
|
58
|
-
expect(nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014, clear_cache: true)).to eq
|
58
|
+
expect(nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014, clear_cache: true)).to eq mod
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'caches mod files queries' do
|
@@ -65,7 +65,7 @@ describe NexusMods do
|
|
65
65
|
json: { files: [json_mod_file2472, json_mod_file2487] }
|
66
66
|
)
|
67
67
|
mod_files = nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)
|
68
|
-
expect(nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq
|
68
|
+
expect(nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq mod_files
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'does not cache mod files queries if asked' do
|
@@ -76,7 +76,55 @@ describe NexusMods do
|
|
76
76
|
times: 2
|
77
77
|
)
|
78
78
|
mod_files = nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)
|
79
|
-
expect(nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014, clear_cache: true)).to eq
|
79
|
+
expect(nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014, clear_cache: true)).to eq mod_files
|
80
|
+
end
|
81
|
+
|
82
|
+
{
|
83
|
+
'last day' => {
|
84
|
+
since: :one_day,
|
85
|
+
expected_url_params: 'period=1d'
|
86
|
+
},
|
87
|
+
'last week' => {
|
88
|
+
since: :one_week,
|
89
|
+
expected_url_params: 'period=1w'
|
90
|
+
},
|
91
|
+
'last month' => {
|
92
|
+
since: :one_month,
|
93
|
+
expected_url_params: 'period=1m'
|
94
|
+
}
|
95
|
+
}.each do |since, since_config|
|
96
|
+
|
97
|
+
context "when testing updated months since #{since}" do
|
98
|
+
|
99
|
+
it 'caches mod updates queries' do
|
100
|
+
expect_validate_user
|
101
|
+
expect_http_call_to(
|
102
|
+
path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
|
103
|
+
json: [
|
104
|
+
json_mod_updates2014,
|
105
|
+
json_mod_updates100
|
106
|
+
]
|
107
|
+
)
|
108
|
+
mod_updates = nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since])
|
109
|
+
expect(nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since])).to eq mod_updates
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'does not cache mod updates queries if asked' do
|
113
|
+
expect_validate_user
|
114
|
+
expect_http_call_to(
|
115
|
+
path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
|
116
|
+
json: [
|
117
|
+
json_mod_updates2014,
|
118
|
+
json_mod_updates100
|
119
|
+
],
|
120
|
+
times: 2
|
121
|
+
)
|
122
|
+
mod_updates = nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since])
|
123
|
+
expect(nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since], clear_cache: true)).to eq mod_updates
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
80
128
|
end
|
81
129
|
|
82
130
|
it 'expires games queries cache' do
|
@@ -92,7 +140,7 @@ describe NexusMods do
|
|
92
140
|
nexus_mods_instance = nexus_mods(api_cache_expiry: { games: 1 })
|
93
141
|
games = nexus_mods_instance.games
|
94
142
|
sleep 2
|
95
|
-
expect(nexus_mods_instance.games).to eq
|
143
|
+
expect(nexus_mods_instance.games).to eq games
|
96
144
|
end
|
97
145
|
|
98
146
|
it 'expires mod queries cache' do
|
@@ -105,7 +153,7 @@ describe NexusMods do
|
|
105
153
|
nexus_mods_instance = nexus_mods(api_cache_expiry: { mod: 1 })
|
106
154
|
mod = nexus_mods_instance.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014)
|
107
155
|
sleep 2
|
108
|
-
expect(nexus_mods_instance.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq
|
156
|
+
expect(nexus_mods_instance.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq mod
|
109
157
|
end
|
110
158
|
|
111
159
|
it 'expires mod files queries cache' do
|
@@ -118,7 +166,7 @@ describe NexusMods do
|
|
118
166
|
nexus_mods_instance = nexus_mods(api_cache_expiry: { mod_files: 1 })
|
119
167
|
mod_files = nexus_mods_instance.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)
|
120
168
|
sleep 2
|
121
|
-
expect(nexus_mods_instance.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq
|
169
|
+
expect(nexus_mods_instance.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)).to eq mod_files
|
122
170
|
end
|
123
171
|
|
124
172
|
it 'only clears the cache of the wanted resource' do
|
@@ -136,8 +184,8 @@ describe NexusMods do
|
|
136
184
|
mod_files20151 = nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2015)
|
137
185
|
mod_files20142 = nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014, clear_cache: true)
|
138
186
|
mod_files20152 = nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2015)
|
139
|
-
expect(mod_files20141).to eq
|
140
|
-
expect(mod_files20151).to eq
|
187
|
+
expect(mod_files20141).to eq mod_files20142
|
188
|
+
expect(mod_files20151).to eq mod_files20152
|
141
189
|
end
|
142
190
|
|
143
191
|
context 'with file persistence' do
|
@@ -276,10 +324,10 @@ describe NexusMods do
|
|
276
324
|
nexus_mods_instance3 = nexus_mods(api_cache_file:)
|
277
325
|
mod_files20143 = nexus_mods_instance3.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014)
|
278
326
|
mod_files20153 = nexus_mods_instance3.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2015)
|
279
|
-
expect(mod_files20141).to eq
|
280
|
-
expect(mod_files20141).to eq
|
281
|
-
expect(mod_files20151).to eq
|
282
|
-
expect(mod_files20151).to eq
|
327
|
+
expect(mod_files20141).to eq mod_files20142
|
328
|
+
expect(mod_files20141).to eq mod_files20143
|
329
|
+
expect(mod_files20151).to eq mod_files20152
|
330
|
+
expect(mod_files20151).to eq mod_files20153
|
283
331
|
end
|
284
332
|
end
|
285
333
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexus_mods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muriel Salvan
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/nexus_mods/api/game.rb
|
138
138
|
- lib/nexus_mods/api/mod.rb
|
139
139
|
- lib/nexus_mods/api/mod_file.rb
|
140
|
+
- lib/nexus_mods/api/mod_updates.rb
|
140
141
|
- lib/nexus_mods/api/user.rb
|
141
142
|
- lib/nexus_mods/api_client.rb
|
142
143
|
- lib/nexus_mods/cacheable_api.rb
|
@@ -146,12 +147,14 @@ files:
|
|
146
147
|
- lib/nexus_mods/version.rb
|
147
148
|
- spec/nexus_mods_test/factories/games.rb
|
148
149
|
- spec/nexus_mods_test/factories/mod_files.rb
|
150
|
+
- spec/nexus_mods_test/factories/mod_updates.rb
|
149
151
|
- spec/nexus_mods_test/factories/mods.rb
|
150
152
|
- spec/nexus_mods_test/helpers.rb
|
151
153
|
- spec/nexus_mods_test/scenarios/nexus_mods/api/api_limits_spec.rb
|
152
154
|
- spec/nexus_mods_test/scenarios/nexus_mods/api/game_spec.rb
|
153
155
|
- spec/nexus_mods_test/scenarios/nexus_mods/api/mod_file_spec.rb
|
154
156
|
- spec/nexus_mods_test/scenarios/nexus_mods/api/mod_spec.rb
|
157
|
+
- spec/nexus_mods_test/scenarios/nexus_mods/api/mod_updates_spec.rb
|
155
158
|
- spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_access_spec.rb
|
156
159
|
- spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_caching_spec.rb
|
157
160
|
- spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_common_spec.rb
|