nexus_mods 1.1.0 → 1.1.1

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: a6490bd894c40f7806bb126cb70ade888ab5121499b86ff2cc959ee663dd223d
4
- data.tar.gz: d9fdeb53c88c27ce9503e328a261ddb31a0facbbe0b6c35c304628c6e9580790
3
+ metadata.gz: 9fd9e01b4661eaa68f2a7fea3c52907b55f9bb7379f1e8f5423742f164784b95
4
+ data.tar.gz: 8a87ea1ba913a9f41303918a338649065eef99d5c3b8ec75b4fb4bbdbd782bcc
5
5
  SHA512:
6
- metadata.gz: 7c8f9576edd38dab0076f24ad1d396973c9d1ab8542ff4eef548d9b49758f85b6da465465b10b1e53dbb2db6d8312f31e9b88649916f654e7b8c1a12092aaadb
7
- data.tar.gz: 1b2d1e915594af39c9bd793a8f216fc2796024e2729a2b5596c35b546e04c8e2bb96dce77aa35e11f5d7a98fba1652c79f77f01648a363cfdf9b93ec40ee7602
6
+ metadata.gz: 382f42ee4d79d68ac34c6715fa3ad3f154a9376ff0b0b41b651804adaef512c681fa53a0d9112d1897757a8e77d3f8902bff468099fc78e48a97fc050f7d9bac
7
+ data.tar.gz: 6dd0631ddc2575c33da22390eeef859b3d01a1b805b566337add1eba2bb2fcd23925d250edde5b15d54a92cad5596125330645cff7f4a9eb13e3a2ef1be06f57
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [v1.1.1](https://github.com/Muriel-Salvan/nexus_mods/compare/v1.1.0...v1.1.1) (2023-04-10 19:39:28)
2
+
3
+ ### Patches
4
+
5
+ * [Improved documentation and added examples](https://github.com/Muriel-Salvan/nexus_mods/commit/0eb3fd00e0d1ad34db04a30ab2043a49371dc64f)
6
+
1
7
  # [v1.1.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v1.0.0...v1.1.0) (2023-04-10 19:19:16)
2
8
 
3
9
  ### Features
data/README.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  Simple Ruby API letting you handle [NexusMods](https://www.nexusmods.com/) REST API.
4
4
 
5
+ ## Main features
6
+
7
+ * Get the API **limits**.
8
+ * Get the **games** information.
9
+ * Get individual **mods** and **mod files** information.
10
+ * Configurable **caching** with expiry times to save API calls to nexusmods.com.
11
+ * All served in an object-oriented **API in full Ruby**.
12
+
13
+ See the [examples](examples) for more details on how to use it.
14
+ Those examples expect that you set a valid NexusMods API key in the `NEXUS_MODS_API_KEY` environment variable.
15
+
5
16
  ## Install
6
17
 
7
18
  Via gem
@@ -54,7 +65,7 @@ Any contribution is welcome:
54
65
 
55
66
  ## Credits
56
67
 
57
- - [Muriel Salvan][link-author]
68
+ - [Muriel Salvan](https://x-aeon.com/muriel)
58
69
 
59
70
  ## License
60
71
 
@@ -0,0 +1,41 @@
1
+ require 'nexus_mods'
2
+ require 'fileutils'
3
+
4
+ # Make sure a previous file for caching was not here before
5
+ test_api_cache_file = 'nexus_mods_test_api_cache.json'
6
+ FileUtils.rm_f test_api_cache_file
7
+
8
+ nexus_mods = NexusMods.new(
9
+ api_key: ENV.fetch('NEXUS_MODS_API_KEY'),
10
+ api_cache_file: test_api_cache_file
11
+ )
12
+
13
+ initial_remaining = nexus_mods.api_limits.daily_remaining
14
+ puts "Before fetching anything, daily API remaining is #{initial_remaining}"
15
+
16
+ puts 'Fetch the list of games (without using cache)...'
17
+ puts "Fetched #{nexus_mods.games.size} games."
18
+
19
+ puts "After fetching those games, daily API remaining is #{nexus_mods.api_limits.daily_remaining}"
20
+
21
+ puts 'Now we fetch again the list of games (this should use the cache)...'
22
+ puts "Fetched #{nexus_mods.games.size} games."
23
+
24
+ puts "After fetching those games a second time, daily API remaining is #{nexus_mods.api_limits.daily_remaining}"
25
+
26
+ puts 'Now we close the current NexusMods instance ad re-instantiate a new one from scratch using the same API cache file'
27
+
28
+ new_nexus_mods = NexusMods.new(
29
+ api_key: ENV.fetch('NEXUS_MODS_API_KEY'),
30
+ api_cache_file: test_api_cache_file
31
+ )
32
+
33
+ puts "Before fetching anything from the new instance, daily API remaining is #{new_nexus_mods.api_limits.daily_remaining}"
34
+
35
+ puts 'Now we fetch the list of games from the new instance (this should use the cache that was stored in the file)...'
36
+ puts "Fetched #{new_nexus_mods.games.size} games."
37
+
38
+ puts "After fetching those games from the new instance, daily API remaining is #{new_nexus_mods.api_limits.daily_remaining}"
39
+
40
+ puts
41
+ puts "As a conclusion, we used 2 instances of NexusMods that have fetched games 3 times, and it consumed #{initial_remaining - new_nexus_mods.api_limits.daily_remaining} real API call."
@@ -0,0 +1,12 @@
1
+ require 'nexus_mods'
2
+
3
+ api_limits = NexusMods.new(api_key: ENV.fetch('NEXUS_MODS_API_KEY')).api_limits
4
+ puts <<~EO_OUTPUT
5
+ API limits:
6
+ daily_limit: #{api_limits.daily_limit}
7
+ daily_remaining: #{api_limits.daily_remaining}
8
+ daily_reset: #{api_limits.daily_reset}
9
+ hourly_limit: #{api_limits.hourly_limit}
10
+ hourly_remaining: #{api_limits.hourly_remaining}
11
+ hourly_reset: #{api_limits.hourly_reset}
12
+ EO_OUTPUT
data/examples/games.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'nexus_mods'
2
+
3
+ games = NexusMods.new(api_key: ENV.fetch('NEXUS_MODS_API_KEY')).games
4
+ puts "Found a total of #{games.size} games."
5
+ puts 'Here is the top 10 by number of downloads:'
6
+ games.sort_by { |game| -game.downloads_count }[0..9].each do |game|
7
+ puts "* #{game.name} (#{game.mods_count} mods, #{game.downloads_count} downloads)"
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'nexus_mods'
2
+
3
+ puts 'Example of fetching a mod with log debug activated, and without using the cache (so that we always see the query):'
4
+ puts
5
+ NexusMods.new(
6
+ api_key: ENV.fetch('NEXUS_MODS_API_KEY'),
7
+ log_level: :debug,
8
+ game_domain_name: 'skyrimspecialedition',
9
+ mod_id: 42_521
10
+ ).mod(clear_cache: true)
data/examples/mods.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'nexus_mods'
2
+
3
+ nexus_mods = NexusMods.new(
4
+ api_key: ENV.fetch('NEXUS_MODS_API_KEY'),
5
+ game_domain_name: 'skyrimspecialedition'
6
+ )
7
+ some_mod_ids = [
8
+ 266,
9
+ 2_347,
10
+ 17_230,
11
+ 42_521
12
+ ]
13
+ puts 'Here are some details about a few mods for Skyrim Special Edition:'
14
+ puts
15
+ some_mod_ids.each do |mod_id|
16
+ mod = nexus_mods.mod(mod_id:)
17
+ mod_files = nexus_mods.mod_files(mod_id:)
18
+ puts <<~EO_OUTPUT
19
+ ===== #{mod.name} (v#{mod.version}) by #{mod.uploader.name} (#{mod.downloads_count} downloads)
20
+ #{mod.summary}
21
+ * Last 5 files: #{mod_files.reverse[0..4].map(&:file_name).join(', ')}
22
+
23
+ EO_OUTPUT
24
+ end
@@ -1,5 +1,5 @@
1
1
  class NexusMods
2
2
 
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
 
5
5
  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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muriel Salvan
@@ -131,10 +131,20 @@ extra_rdoc_files:
131
131
  - CHANGELOG.md
132
132
  - LICENSE.md
133
133
  - README.md
134
+ - examples/api_caching.rb
135
+ - examples/api_limits.rb
136
+ - examples/games.rb
137
+ - examples/log_debug.rb
138
+ - examples/mods.rb
134
139
  files:
135
140
  - CHANGELOG.md
136
141
  - LICENSE.md
137
142
  - README.md
143
+ - examples/api_caching.rb
144
+ - examples/api_limits.rb
145
+ - examples/games.rb
146
+ - examples/log_debug.rb
147
+ - examples/mods.rb
138
148
  - lib/nexus_mods.rb
139
149
  - lib/nexus_mods/api/api_limits.rb
140
150
  - lib/nexus_mods/api/category.rb