nexus_mods 1.0.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: b99b3c80e3d45a5bde54394040517dc6e7c3cb803dfa4b3be263a0283bdf5606
4
- data.tar.gz: cae008f32c14745db775d1791c631f15cab5071e3dcd0ac0d4d0c0ce5ba1a1c8
3
+ metadata.gz: 9fd9e01b4661eaa68f2a7fea3c52907b55f9bb7379f1e8f5423742f164784b95
4
+ data.tar.gz: 8a87ea1ba913a9f41303918a338649065eef99d5c3b8ec75b4fb4bbdbd782bcc
5
5
  SHA512:
6
- metadata.gz: 8c0bf7800a21880cf748a0733d14483e3326d939671a5aa41b3e0076d3ef9ea46ff2e4d498078c95990a729542dd23ca15d229726e70b63eba139abd53ed828e
7
- data.tar.gz: 754f2778855552657f7977d03fd8b84e58fc291b85b21f12dd6ee0d6a9baa6ade16670acc97244a043320f09d8b93e638b0ac4f680725b558b748c10bfcf99ba
6
+ metadata.gz: 382f42ee4d79d68ac34c6715fa3ad3f154a9376ff0b0b41b651804adaef512c681fa53a0d9112d1897757a8e77d3f8902bff468099fc78e48a97fc050f7d9bac
7
+ data.tar.gz: 6dd0631ddc2575c33da22390eeef859b3d01a1b805b566337add1eba2bb2fcd23925d250edde5b15d54a92cad5596125330645cff7f4a9eb13e3a2ef1be06f57
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
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
+
7
+ # [v1.1.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v1.0.0...v1.1.0) (2023-04-10 19:19:16)
8
+
9
+ ### Features
10
+
11
+ * [[Feature] Add log_level parameter while creating nexus_mods instance](https://github.com/Muriel-Salvan/nexus_mods/commit/1b6215be2d9b3a97076bb6b7bf665f8ec8e900ca)
12
+
1
13
  # [v1.0.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v0.6.0...v1.0.0) (2023-04-10 19:03:51)
2
14
 
3
15
  ### Breaking changes
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.0.0'
3
+ VERSION = '1.1.1'
4
4
 
5
5
  end
data/lib/nexus_mods.rb CHANGED
@@ -46,6 +46,7 @@ class NexusMods
46
46
  # * *mod_files*: Expiry associated to queries on mod files [default: 1 day]
47
47
  # * *api_cache_file* (String): File used to store the NexusMods API cache, or nil for no cache [default: "#{Dir.tmpdir}/nexus_mods_api_cache.json"]
48
48
  # * *logger* (Logger): The logger to be used for log messages [default: Logger.new(STDOUT)]
49
+ # * *log_level* (Symbol): The logger level to be set [default: :info]
49
50
  def initialize(
50
51
  api_key: nil,
51
52
  game_domain_name: 'skyrimspecialedition',
@@ -54,12 +55,14 @@ class NexusMods
54
55
  http_cache_file: "#{Dir.tmpdir}/nexus_mods_http_cache.json",
55
56
  api_cache_expiry: {},
56
57
  api_cache_file: "#{Dir.tmpdir}/nexus_mods_api_cache.json",
57
- logger: Logger.new($stdout)
58
+ logger: Logger.new($stdout),
59
+ log_level: :info
58
60
  )
59
61
  @game_domain_name = game_domain_name
60
62
  @mod_id = mod_id
61
63
  @file_id = file_id
62
64
  @logger = logger
65
+ @logger.level = log_level
63
66
  @premium = false
64
67
  @api_client = ApiClient.new(
65
68
  api_key:,
@@ -66,12 +66,20 @@ module NexusModsTest
66
66
  @nexus_mods
67
67
  end
68
68
 
69
+ # Get NexusMods logs
70
+ #
71
+ # Result::
72
+ # * String: The NexusMods logs
73
+ def nexus_mods_logs
74
+ @nexus_mods_logger.string
75
+ end
76
+
69
77
  # Reset the NexusMods instance.
70
78
  # Dump the output if needed for debugging purposes.
71
79
  def reset_nexus_mods
72
80
  if @nexus_mods && test_debug?
73
81
  puts '===== NexusMods output BEGIN ====='
74
- puts @nexus_mods_logger.string
82
+ puts nexus_mods_logs
75
83
  puts '===== NexusMods output END ====='
76
84
  end
77
85
  @nexus_mods = nil
@@ -6,14 +6,6 @@ describe NexusMods::Api::Mod do
6
6
  expect_validate_user
7
7
  end
8
8
 
9
- it 'returns the default game domain name' do
10
- expect(nexus_mods(game_domain_name: 'skyrimspecialedition').game_domain_name).to eq 'skyrimspecialedition'
11
- end
12
-
13
- it 'returns the default game mod id' do
14
- expect(nexus_mods(mod_id: 2014).mod_id).to eq 2014
15
- end
16
-
17
9
  it 'returns a mod complete information' do
18
10
  expect_http_call_to(
19
11
  path: '/v1/games/skyrimspecialedition/mods/2014.json',
@@ -0,0 +1,32 @@
1
+ describe NexusMods do
2
+
3
+ context 'when testing authentication and access' do
4
+
5
+ it 'returns the default game domain name' do
6
+ expect_validate_user
7
+ expect(nexus_mods(game_domain_name: 'skyrimspecialedition').game_domain_name).to eq 'skyrimspecialedition'
8
+ end
9
+
10
+ it 'returns the default game mod id' do
11
+ expect_validate_user
12
+ expect(nexus_mods(mod_id: 2014).mod_id).to eq 2014
13
+ end
14
+
15
+ it 'accepts the log level' do
16
+ expect_validate_user(times: 2)
17
+ expect_http_call_to(
18
+ path: '/v1/games.json',
19
+ json: [],
20
+ times: 2
21
+ )
22
+ nexus_mods(log_level: :debug).games
23
+ log_debug = nexus_mods_logs
24
+ reset_nexus_mods
25
+ nexus_mods(log_level: :info).games
26
+ log_info = nexus_mods_logs
27
+ expect(log_debug.size).to be > log_info.size
28
+ end
29
+
30
+ end
31
+
32
+ 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.0.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
@@ -157,8 +167,9 @@ files:
157
167
  - spec/nexus_mods_test/scenarios/nexus_mods/api/game_spec.rb
158
168
  - spec/nexus_mods_test/scenarios/nexus_mods/api/mod_file_spec.rb
159
169
  - spec/nexus_mods_test/scenarios/nexus_mods/api/mod_spec.rb
160
- - spec/nexus_mods_test/scenarios/nexus_mods_access_spec.rb
161
- - spec/nexus_mods_test/scenarios/nexus_mods_caching_spec.rb
170
+ - spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_access_spec.rb
171
+ - spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_caching_spec.rb
172
+ - spec/nexus_mods_test/scenarios/nexus_mods/nexus_mods_common_spec.rb
162
173
  - spec/nexus_mods_test/scenarios/rubocop_spec.rb
163
174
  - spec/spec_helper.rb
164
175
  homepage: https://github.com/Muriel-Salvan/nexus_mods