nexus_mods 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a55e8c7bacc06ef260c5b4e6f0ac64d3e9391e39f7d1ebb00c74c110a6eae214
4
- data.tar.gz: 9647e6745975eb0c8c0fe9023a2e66936773fd9389a5d5087511e8edb3e06876
3
+ metadata.gz: 6f6c2d6e72c966955e6153a3381458fba4f56c36deac811d125edc962046b5a0
4
+ data.tar.gz: d0a2ec92da860dbb53b608e1de22762b3562bac1d4fe1333066f868612983747
5
5
  SHA512:
6
- metadata.gz: 29732e93998b9b8b88d66af4ebd67d37d8eaa51f8ab47b487bf0ce2aa3f81312aed8e1275e83a428e5cfa60a2330a7603a6c114f9bf8898593695b0df79603c3
7
- data.tar.gz: 8b3542308bd2736695165a337cef28a2e8ea7e63bd7f67d55f74b4ec797edf556d92e4792e3ea7f83a3f7f56dd028b914bcfba8f713b96679687bb29ddac8a00
6
+ metadata.gz: d159a8824c0c6b723ec7f3361f1df52162cebf3d4f91833e072ceeb94089fb84d102d46d597d0ee24e92c6983e56ddcd87a95a6a4ffbb282331a7f3aae94cc84
7
+ data.tar.gz: 9dda81c7f0f593190547ed55aeff36a3040610d13ee59f7c5ff6ffed7df1d95d806685d9cf77e090e3a2410a24a516a32617b9fc047d59cb30f149607022aaba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [v2.5.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v2.4.0...v2.5.0) (2023-04-12 19:15:44)
2
+
3
+ ### Features
4
+
5
+ * [[Feature] Add links between resources](https://github.com/Muriel-Salvan/nexus_mods/commit/84c474b75f3ee1e4ac0c8bbda0d2ad25022f1f07)
6
+
1
7
  # [v2.4.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v2.3.0...v2.4.0) (2023-04-12 17:23:29)
2
8
 
3
9
  ### Features
@@ -1,9 +1,11 @@
1
+ require 'nexus_mods/api/resource'
2
+
1
3
  class NexusMods
2
4
 
3
5
  module Api
4
6
 
5
7
  # Object giving the NexusMods API limits
6
- class ApiLimits
8
+ class ApiLimits < Resource
7
9
 
8
10
  attr_reader(
9
11
  *%i[
@@ -19,6 +21,7 @@ class NexusMods
19
21
  # Constructor
20
22
  #
21
23
  # Parameters::
24
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
22
25
  # * *daily_limit* (Integer): The daily limit
23
26
  # * *daily_remaining* (Integer): The daily remaining
24
27
  # * *daily_reset* (Integer): The daily reset time
@@ -26,6 +29,7 @@ class NexusMods
26
29
  # * *hourly_remaining* (Integer): The hourly remaining
27
30
  # * *hourly_reset* (Integer): The hourly reset time
28
31
  def initialize(
32
+ nexus_mods:,
29
33
  daily_limit:,
30
34
  daily_remaining:,
31
35
  daily_reset:,
@@ -33,6 +37,7 @@ class NexusMods
33
37
  hourly_remaining:,
34
38
  hourly_reset:
35
39
  )
40
+ super(nexus_mods:)
36
41
  @daily_limit = daily_limit
37
42
  @daily_remaining = daily_remaining
38
43
  @daily_reset = daily_reset
@@ -1,9 +1,11 @@
1
+ require 'nexus_mods/api/resource'
2
+
1
3
  class NexusMods
2
4
 
3
5
  module Api
4
6
 
5
7
  # Categories defined for a game in NexusMods
6
- class Category
8
+ class Category < Resource
7
9
 
8
10
  attr_reader(
9
11
  *%i[
@@ -21,14 +23,17 @@ class NexusMods
21
23
  # Constructor
22
24
  #
23
25
  # Parameters::
26
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
24
27
  # *id* (Integer): The category id
25
28
  # *name* (String): The category id
26
29
  # *parent_category* (Category or nil): The parent category, or nil if none [default: nil]
27
30
  def initialize(
31
+ nexus_mods:,
28
32
  id:,
29
33
  name:,
30
34
  parent_category: nil
31
35
  )
36
+ super(nexus_mods:)
32
37
  @id = id
33
38
  @name = name
34
39
  @parent_category = parent_category
@@ -1,3 +1,5 @@
1
+ require 'nexus_mods/api/resource'
2
+
1
3
  class NexusMods
2
4
 
3
5
  module Api
@@ -5,7 +7,7 @@ class NexusMods
5
7
  # A NexusMods game.
6
8
  # Attributes info can be taken from there:
7
9
  # * https://github.com/Nexus-Mods/node-nexus-api/blob/master/docs/interfaces/_types_.igameinfo.md
8
- class Game
10
+ class Game < Resource
9
11
 
10
12
  attr_reader(
11
13
  *%i[
@@ -29,6 +31,7 @@ class NexusMods
29
31
  # Constructor
30
32
  #
31
33
  # Parameters::
34
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
32
35
  # * *id* (Integer): The game's id
33
36
  # * *name* (String): The game's name
34
37
  # * *forum_url* (String): The game's forum's URL
@@ -44,6 +47,7 @@ class NexusMods
44
47
  # * *mods_count* (Integer): The game's mods' count [default: 0]
45
48
  # * *categories* (Array<Category>): The list of game's categories [default: []]
46
49
  def initialize(
50
+ nexus_mods:,
47
51
  id:,
48
52
  name:,
49
53
  forum_url:,
@@ -59,6 +63,7 @@ class NexusMods
59
63
  mods_count: 0,
60
64
  categories: []
61
65
  )
66
+ super(nexus_mods:)
62
67
  @id = id
63
68
  @name = name
64
69
  @forum_url = forum_url
@@ -1,3 +1,5 @@
1
+ require 'nexus_mods/api/resource'
2
+
1
3
  class NexusMods
2
4
 
3
5
  module Api
@@ -5,7 +7,7 @@ class NexusMods
5
7
  # A NexusMods mod.
6
8
  # Attributes info can be taken from there:
7
9
  # * https://github.com/Nexus-Mods/node-nexus-api/blob/master/docs/interfaces/_types_.imodinfo.md
8
- class Mod
10
+ class Mod < Resource
9
11
 
10
12
  attr_reader(
11
13
  *%i[
@@ -36,6 +38,7 @@ class NexusMods
36
38
  # Constructor
37
39
  #
38
40
  # Parameters::
41
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
39
42
  # * *uid* (Integer): The mod's uid
40
43
  # * *mod_id* (Integer): The mod's id
41
44
  # * *game_id* (Integer): The mod's game id
@@ -58,6 +61,7 @@ class NexusMods
58
61
  # * *unique_downloads_count* (Integer): The mod's unique downloads' count [default: 0]
59
62
  # * *endorsements_count* (Integer): The mod's endorsements' count [default: 0]
60
63
  def initialize(
64
+ nexus_mods:,
61
65
  uid:,
62
66
  mod_id:,
63
67
  game_id:,
@@ -80,6 +84,7 @@ class NexusMods
80
84
  unique_downloads_count: 0,
81
85
  endorsements_count: 0
82
86
  )
87
+ super(nexus_mods:)
83
88
  @uid = uid
84
89
  @mod_id = mod_id
85
90
  @game_id = game_id
@@ -134,6 +139,14 @@ class NexusMods
134
139
  @endorsements_count == other.endorsements_count
135
140
  end
136
141
 
142
+ # Get associated files information
143
+ #
144
+ # Result::
145
+ # * Array<ModFile>: The list of mod files information
146
+ def files
147
+ @nexus_mods.mod_files(game_domain_name: domain_name, mod_id:)
148
+ end
149
+
137
150
  end
138
151
 
139
152
  end
@@ -1,3 +1,5 @@
1
+ require 'nexus_mods/api/resource'
2
+
1
3
  class NexusMods
2
4
 
3
5
  module Api
@@ -5,10 +7,12 @@ class NexusMods
5
7
  # A NexusMods file.
6
8
  # Attributes info can be taken from there:
7
9
  # * https://github.com/Nexus-Mods/node-nexus-api/blob/master/docs/interfaces/_types_.ifileinfo.md
8
- class ModFile
10
+ class ModFile < Resource
9
11
 
10
12
  attr_reader(
11
13
  *%i[
14
+ game_domain_name
15
+ mod_id
12
16
  ids
13
17
  uid
14
18
  id
@@ -43,6 +47,9 @@ class NexusMods
43
47
  # Constructor
44
48
  #
45
49
  # Parameters::
50
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
51
+ # * *game_domain_name* (String): The game this file belongs to
52
+ # * *mod_id* (Integer): The mod id this file belongs to
46
53
  # * *ids* (Array<Integer>): The file's list of IDs
47
54
  # * *uid* (Integer): The file's UID
48
55
  # * *id* (Integer): The file's main ID
@@ -60,6 +67,9 @@ class NexusMods
60
67
  # * *changelog_html* (String): The file's change log in HTML
61
68
  # * *content_preview_url* (String): URL to a JSON that gives info on the file's content
62
69
  def initialize(
70
+ nexus_mods:,
71
+ game_domain_name:,
72
+ mod_id:,
63
73
  ids:,
64
74
  uid:,
65
75
  id:,
@@ -77,6 +87,9 @@ class NexusMods
77
87
  changelog_html:,
78
88
  content_preview_url:
79
89
  )
90
+ super(nexus_mods:)
91
+ @game_domain_name = game_domain_name
92
+ @mod_id = mod_id
80
93
  @ids = ids
81
94
  @uid = uid
82
95
  @id = id
@@ -105,6 +118,8 @@ class NexusMods
105
118
  # * Boolean: Are objects equal?
106
119
  def ==(other)
107
120
  other.is_a?(ModFile) &&
121
+ @game_domain_name == other.game_domain_name &&
122
+ @mod_id == other.mod_id &&
108
123
  @ids == other.ids &&
109
124
  @uid == other.uid &&
110
125
  @id == other.id &&
@@ -123,6 +138,14 @@ class NexusMods
123
138
  @content_preview_url == other.content_preview_url
124
139
  end
125
140
 
141
+ # Get associated mod information
142
+ #
143
+ # Result::
144
+ # * Mod: The corresponding mod
145
+ def mod
146
+ @nexus_mods.mod(game_domain_name:, mod_id:)
147
+ end
148
+
126
149
  end
127
150
 
128
151
  end
@@ -1,12 +1,15 @@
1
+ require 'nexus_mods/api/resource'
2
+
1
3
  class NexusMods
2
4
 
3
5
  module Api
4
6
 
5
7
  # A NexusMods mod updates.
6
- class ModUpdates
8
+ class ModUpdates < Resource
7
9
 
8
10
  attr_reader(
9
11
  *%i[
12
+ game_domain_name
10
13
  mod_id
11
14
  latest_file_update
12
15
  latest_mod_activity
@@ -16,14 +19,20 @@ class NexusMods
16
19
  # Constructor
17
20
  #
18
21
  # Parameters::
22
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
23
+ # * *game_domain_name* (String): The game this file belongs to
19
24
  # * *mod_id* (Integer): The mod's id
20
25
  # * *latest_file_update* (Time): The mod's latest file update
21
26
  # * *latest_mod_activity* (Time): The mod's latest activity
22
27
  def initialize(
28
+ nexus_mods:,
29
+ game_domain_name:,
23
30
  mod_id:,
24
31
  latest_file_update:,
25
32
  latest_mod_activity:
26
33
  )
34
+ super(nexus_mods:)
35
+ @game_domain_name = game_domain_name
27
36
  @mod_id = mod_id
28
37
  @latest_file_update = latest_file_update
29
38
  @latest_mod_activity = latest_mod_activity
@@ -37,11 +46,28 @@ class NexusMods
37
46
  # * Boolean: Are objects equal?
38
47
  def ==(other)
39
48
  other.is_a?(ModUpdates) &&
49
+ @game_domain_name == game_domain_name &&
40
50
  @mod_id == other.mod_id &&
41
51
  @latest_file_update == other.latest_file_update &&
42
52
  @latest_mod_activity == other.latest_mod_activity
43
53
  end
44
54
 
55
+ # Get associated mod information
56
+ #
57
+ # Result::
58
+ # * Mod: The corresponding mod
59
+ def mod
60
+ @nexus_mods.mod(game_domain_name:, mod_id:)
61
+ end
62
+
63
+ # Get associated mod files information
64
+ #
65
+ # Result::
66
+ # * Array<ModFile>: The corresponding mod files
67
+ def mod_files
68
+ @nexus_mods.mod_files(game_domain_name:, mod_id:)
69
+ end
70
+
45
71
  end
46
72
 
47
73
  end
@@ -0,0 +1,20 @@
1
+ class NexusMods
2
+
3
+ module Api
4
+
5
+ # Base class for any API resource
6
+ class Resource
7
+
8
+ # Constructor
9
+ #
10
+ # Parameters::
11
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
12
+ def initialize(nexus_mods:)
13
+ @nexus_mods = nexus_mods
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -1,10 +1,12 @@
1
+ require 'nexus_mods/api/resource'
2
+
1
3
  class NexusMods
2
4
 
3
5
  module Api
4
6
 
5
7
  # A user on NExusMods.
6
8
  # Mainly used for uploaders information.
7
- class User
9
+ class User < Resource
8
10
 
9
11
  attr_reader(
10
12
  *%i[
@@ -18,16 +20,19 @@ class NexusMods
18
20
  # Constructor
19
21
  #
20
22
  # Parameters::
23
+ # * *nexus_mods* (NexusMods): The NexusMods API instance that the resource can use to query for other resources
21
24
  # * *member_id* (Integer): The user's member id
22
25
  # * *member_group_id* (Integer): The user's member group id
23
26
  # * *name* (String): The user's name
24
27
  # * *profile_url* (String): The user's profile URL
25
28
  def initialize(
29
+ nexus_mods:,
26
30
  member_id:,
27
31
  member_group_id:,
28
32
  name:,
29
33
  profile_url:
30
34
  )
35
+ super(nexus_mods:)
31
36
  @member_id = member_id
32
37
  @member_group_id = member_group_id
33
38
  @name = name
@@ -1,5 +1,5 @@
1
1
  class NexusMods
2
2
 
3
- VERSION = '2.4.0'
3
+ VERSION = '2.5.0'
4
4
 
5
5
  end
data/lib/nexus_mods.rb CHANGED
@@ -88,6 +88,7 @@ class NexusMods
88
88
  def api_limits
89
89
  api_limits_headers = @api_client.http('users/validate').headers
90
90
  Api::ApiLimits.new(
91
+ nexus_mods: self,
91
92
  daily_limit: Integer(api_limits_headers['x-rl-daily-limit']),
92
93
  daily_remaining: Integer(api_limits_headers['x-rl-daily-remaining']),
93
94
  daily_reset: Time.parse(api_limits_headers['x-rl-daily-reset']).utc,
@@ -113,6 +114,7 @@ class NexusMods
113
114
  category_id,
114
115
  [
115
116
  Api::Category.new(
117
+ nexus_mods: self,
116
118
  id: category_id,
117
119
  name: category_json['name']
118
120
  ),
@@ -125,6 +127,7 @@ class NexusMods
125
127
  category.parent_category = categories[parent_category_id]&.first if parent_category_id
126
128
  end
127
129
  Api::Game.new(
130
+ nexus_mods: self,
128
131
  id: game_json['id'],
129
132
  name: game_json['name'],
130
133
  forum_url: game_json['forum_url'],
@@ -175,6 +178,7 @@ class NexusMods
175
178
  mod_cache_up_to_date?(game_domain_name:, mod_id:) if check_updates
176
179
  mod_json = @api_client.api("games/#{game_domain_name}/mods/#{mod_id}", clear_cache:)
177
180
  Api::Mod.new(
181
+ nexus_mods: self,
178
182
  uid: mod_json['uid'],
179
183
  mod_id: mod_json['mod_id'],
180
184
  game_id: mod_json['game_id'],
@@ -189,6 +193,7 @@ class NexusMods
189
193
  status: mod_json['status'],
190
194
  available: mod_json['available'],
191
195
  uploader: Api::User.new(
196
+ nexus_mods: self,
192
197
  member_id: mod_json['user']['member_id'],
193
198
  member_group_id: mod_json['user']['member_group_id'],
194
199
  name: mod_json['user']['name'],
@@ -241,6 +246,9 @@ class NexusMods
241
246
  mod_files_cache_up_to_date?(game_domain_name:, mod_id:) if check_updates
242
247
  @api_client.api("games/#{game_domain_name}/mods/#{mod_id}/files", clear_cache:)['files'].map do |file_json|
243
248
  Api::ModFile.new(
249
+ nexus_mods: self,
250
+ game_domain_name:,
251
+ mod_id:,
244
252
  ids: file_json['id'],
245
253
  uid: file_json['uid'],
246
254
  id: file_json['file_id'],
@@ -298,6 +306,8 @@ class NexusMods
298
306
  def updated_mods(game_domain_name: @game_domain_name, since: :one_day, clear_cache: false)
299
307
  @api_client.api("games/#{game_domain_name}/mods/updated", parameters: period_to_url_params(since), clear_cache:).map do |updated_mod_json|
300
308
  Api::ModUpdates.new(
309
+ nexus_mods: self,
310
+ game_domain_name:,
301
311
  mod_id: updated_mod_json['mod_id'],
302
312
  latest_file_update: Time.at(updated_mod_json['latest_file_update']).utc,
303
313
  latest_mod_activity: Time.at(updated_mod_json['latest_mod_activity']).utc
@@ -60,6 +60,14 @@ describe NexusMods::Api::ModFile do
60
60
  expect_mod_files_to_be_example(nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition'))
61
61
  end
62
62
 
63
+ it 'returns the mod associated to the mod file' do
64
+ expect_http_call_to(
65
+ path: '/v1/games/skyrimspecialedition/mods/2014.json',
66
+ json: json_complete_mod
67
+ )
68
+ expect_mod_to_be_complete(nexus_mods.mod_files(game_domain_name: 'skyrimspecialedition', mod_id: 2014).first.mod)
69
+ end
70
+
63
71
  end
64
72
 
65
73
  it 'compares objects for equality' do
@@ -83,6 +91,7 @@ describe NexusMods::Api::ModFile do
83
91
  archived: 7,
84
92
  unknown: 100
85
93
  }.each do |category, category_id|
94
+
86
95
  it "accepts mod files having category #{category}" do
87
96
  expect_http_call_to(
88
97
  path: '/v1/games/skyrimspecialedition/mods/2014/files.json',
@@ -119,6 +128,7 @@ describe NexusMods::Api::ModFile do
119
128
  expect(mod_file.category).to eq category
120
129
  expect(mod_file.category_id).to eq category_id
121
130
  end
131
+
122
132
  end
123
133
 
124
134
  context 'when checking cache data freshness' do
@@ -63,6 +63,14 @@ describe NexusMods::Api::Mod do
63
63
  expect(mod1).to eq mod2
64
64
  end
65
65
 
66
+ it 'returns the mod files associated to the mod' do
67
+ expect_http_call_to(
68
+ path: '/v1/games/skyrimspecialedition/mods/2014/files.json',
69
+ json: { 'files' => [json_mod_file2472] }
70
+ )
71
+ expect_mod_file_to_be2472(nexus_mods.mod(game_domain_name: 'skyrimspecialedition', mod_id: 2014).files.first)
72
+ end
73
+
66
74
  end
67
75
 
68
76
  context 'when checking cache data freshness' do
@@ -78,6 +78,34 @@ describe NexusMods::Api::ModUpdates do
78
78
  expect(mod_updates1).to eq mod_updates2
79
79
  end
80
80
 
81
+ it 'returns the mod associated to the mod updates' do
82
+ expect_http_call_to(
83
+ path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
84
+ json: [
85
+ json_mod_updates2014
86
+ ]
87
+ )
88
+ expect_http_call_to(
89
+ path: '/v1/games/skyrimspecialedition/mods/2014.json',
90
+ json: json_complete_mod
91
+ )
92
+ expect_mod_to_be_complete(nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since]).first.mod)
93
+ end
94
+
95
+ it 'returns the mod files associated to the mod updates' do
96
+ expect_http_call_to(
97
+ path: "/v1/games/skyrimspecialedition/mods/updated.json?#{since_config[:expected_url_params]}",
98
+ json: [
99
+ json_mod_updates2014
100
+ ]
101
+ )
102
+ expect_http_call_to(
103
+ path: '/v1/games/skyrimspecialedition/mods/2014/files.json',
104
+ json: { 'files' => [json_mod_file2472] }
105
+ )
106
+ expect_mod_file_to_be2472(nexus_mods.updated_mods(game_domain_name: 'skyrimspecialedition', since: since_config[:since]).first.mod_files.first)
107
+ end
108
+
81
109
  end
82
110
 
83
111
  end
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.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muriel Salvan
@@ -138,6 +138,7 @@ files:
138
138
  - lib/nexus_mods/api/mod.rb
139
139
  - lib/nexus_mods/api/mod_file.rb
140
140
  - lib/nexus_mods/api/mod_updates.rb
141
+ - lib/nexus_mods/api/resource.rb
141
142
  - lib/nexus_mods/api/user.rb
142
143
  - lib/nexus_mods/api_client.rb
143
144
  - lib/nexus_mods/cacheable_api.rb