nexus_mods 1.1.1 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fd9e01b4661eaa68f2a7fea3c52907b55f9bb7379f1e8f5423742f164784b95
4
- data.tar.gz: 8a87ea1ba913a9f41303918a338649065eef99d5c3b8ec75b4fb4bbdbd782bcc
3
+ metadata.gz: 3aa5f91eb62460b72b2f0f31434cc1d3741c70970b3e4db5f22b57e95bbe6b4c
4
+ data.tar.gz: 31cdf30406cbed8fa23a432cc7b916ed8223c9344a3d07379adb5cff19f4bfea
5
5
  SHA512:
6
- metadata.gz: 382f42ee4d79d68ac34c6715fa3ad3f154a9376ff0b0b41b651804adaef512c681fa53a0d9112d1897757a8e77d3f8902bff468099fc78e48a97fc050f7d9bac
7
- data.tar.gz: 6dd0631ddc2575c33da22390eeef859b3d01a1b805b566337add1eba2bb2fcd23925d250edde5b15d54a92cad5596125330645cff7f4a9eb13e3a2ef1be06f57
6
+ metadata.gz: 03a0ddca6e1d752aee0cb6ec887067340d3f31546cb6212da7c01082327fd47f898aa176f0c24175483db6657a8ff54d00bedd71411c37a00141b26e5c68b09c
7
+ data.tar.gz: ffd3177a8b3dcee3f1c96eeb03e5a9526c5bbcf967ae81c6d926a0f7158eeccae5b7214b4e8c0d769e98f6d5d2058135d8cab5e27436c1ae3df890378c6bca1e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [v2.0.1](https://github.com/Muriel-Salvan/nexus_mods/compare/v2.0.0...v2.0.1) (2023-04-11 10:22:54)
2
+
3
+ ### Patches
4
+
5
+ * [Added NexusMods version in the user agent](https://github.com/Muriel-Salvan/nexus_mods/commit/41092e06db91d1dc3e3badb66aeccf85d62a2d00)
6
+
7
+ # [v2.0.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v1.1.1...v2.0.0) (2023-04-11 10:15:58)
8
+
9
+ ### Breaking changes
10
+
11
+ * [[Breaking] Remove http cache file and useless support for etags as the API does not cache at http level](https://github.com/Muriel-Salvan/nexus_mods/commit/e157524e17ef0ed1a7013f14b15eaa35bb309592)
12
+
1
13
  # [v1.1.1](https://github.com/Muriel-Salvan/nexus_mods/compare/v1.1.0...v1.1.1) (2023-04-10 19:39:28)
2
14
 
3
15
  ### Patches
@@ -1,7 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'faraday'
3
- require 'faraday-http-cache'
4
- require 'nexus_mods/file_cache'
3
+ require 'nexus_mods/version'
5
4
  require 'nexus_mods/cacheable_api'
6
5
 
7
6
  class NexusMods
@@ -23,7 +22,6 @@ class NexusMods
23
22
  #
24
23
  # Parameters::
25
24
  # * *api_key* (String or nil): The API key to be used, or nil for another authentication [default: nil]
26
- # * *http_cache_file* (String): File used to store the HTTP cache, or nil for no cache [default: "#{Dir.tmpdir}/nexus_mods_http_cache.json"]
27
25
  # * *api_cache_expiry* (Hash<Symbol,Integer>): Expiry times in seconds, per expiry key. Possible keys are:
28
26
  # * *games*: Expiry associated to queries on games [default: 1 day]
29
27
  # * *mod*: Expiry associated to queries on mod [default: 1 day]
@@ -32,7 +30,6 @@ class NexusMods
32
30
  # * *logger* (Logger): The logger to be used for log messages [default: Logger.new(STDOUT)]
33
31
  def initialize(
34
32
  api_key: nil,
35
- http_cache_file: "#{Dir.tmpdir}/nexus_mods_http_cache.json",
36
33
  api_cache_expiry: DEFAULT_API_CACHE_EXPIRY,
37
34
  api_cache_file: "#{Dir.tmpdir}/nexus_mods_api_cache.json",
38
35
  logger: Logger.new($stdout)
@@ -43,16 +40,7 @@ class NexusMods
43
40
  ApiClient.api_client = self
44
41
  @logger = logger
45
42
  # Initialize our HTTP client
46
- @http_cache = http_cache_file.nil? ? nil : FileCache.new(http_cache_file)
47
- @http_client = Faraday.new do |builder|
48
- # Indicate that the cache is not shared, meaning that private resources (depending on the session) can be cached as we consider only 1 user is using it for a given file cache.
49
- # Use Marshal serializer as some URLs can't get decoded correctly due to UTF-8 issues
50
- builder.use :http_cache,
51
- store: @http_cache,
52
- shared_cache: false,
53
- serializer: Marshal
54
- builder.adapter Faraday.default_adapter
55
- end
43
+ @http_client = Faraday.new
56
44
  Cacheable.cache_adapter = :persistent_json
57
45
  load_api_cache
58
46
  end
@@ -82,7 +70,7 @@ class NexusMods
82
70
  @http_client.send(verb) do |req|
83
71
  req.url api_uri(path)
84
72
  req.headers['apikey'] = @api_key
85
- req.headers['User-Agent'] = "nexus_mods (#{RUBY_PLATFORM}) Ruby/#{RUBY_VERSION}"
73
+ req.headers['User-Agent'] = "nexus_mods/#{NexusMods::VERSION} (#{RUBY_PLATFORM}) Ruby/#{RUBY_VERSION}"
86
74
  end
87
75
  end
88
76
 
@@ -1,5 +1,5 @@
1
1
  class NexusMods
2
2
 
3
- VERSION = '1.1.1'
3
+ VERSION = '2.0.1'
4
4
 
5
5
  end
data/lib/nexus_mods.rb CHANGED
@@ -39,7 +39,6 @@ class NexusMods
39
39
  # * *game_domain_name* (String): Game domain name to query by default [default: 'skyrimspecialedition']
40
40
  # * *mod_id* (Integer): Mod to query by default [default: 1]
41
41
  # * *file_id* (Integer): File to query by default [default: 1]
42
- # * *http_cache_file* (String): File used to store the HTTP cache, or nil for no cache [default: "#{Dir.tmpdir}/nexus_mods_http_cache.json"]
43
42
  # * *api_cache_expiry* (Hash<Symbol,Integer>): Expiry times in seconds, per expiry key. Possible keys are:
44
43
  # * *games*: Expiry associated to queries on games [default: 1 day]
45
44
  # * *mod*: Expiry associated to queries on mod [default: 1 day]
@@ -52,7 +51,6 @@ class NexusMods
52
51
  game_domain_name: 'skyrimspecialedition',
53
52
  mod_id: 1,
54
53
  file_id: 1,
55
- http_cache_file: "#{Dir.tmpdir}/nexus_mods_http_cache.json",
56
54
  api_cache_expiry: {},
57
55
  api_cache_file: "#{Dir.tmpdir}/nexus_mods_api_cache.json",
58
56
  logger: Logger.new($stdout),
@@ -66,7 +64,6 @@ class NexusMods
66
64
  @premium = false
67
65
  @api_client = ApiClient.new(
68
66
  api_key:,
69
- http_cache_file:,
70
67
  api_cache_expiry:,
71
68
  api_cache_file:,
72
69
  logger:
@@ -56,7 +56,6 @@ module NexusModsTest
56
56
  if @nexus_mods.nil?
57
57
  args[:api_key] = MOCKED_API_KEY unless args.key?(:api_key)
58
58
  # By default running tests should not persistent cache files
59
- args[:http_cache_file] = nil unless args.key?(:http_cache_file)
60
59
  args[:api_cache_file] = nil unless args.key?(:api_cache_file)
61
60
  # Redirect any log into a string so that they don't pollute the tests output and they could be asserted.
62
61
  @nexus_mods_logger = StringIO.new
@@ -112,14 +111,9 @@ module NexusModsTest
112
111
  json_as_str = json.to_json
113
112
  mocked_etag = "W/\"#{Digest::MD5.hexdigest("#{path}|#{json_as_str}")}\""
114
113
  expected_request_headers = {
115
- 'User-Agent' => "nexus_mods (#{RUBY_PLATFORM}) Ruby/#{RUBY_VERSION}",
114
+ 'User-Agent' => "nexus_mods/#{NexusMods::VERSION} (#{RUBY_PLATFORM}) Ruby/#{RUBY_VERSION}",
116
115
  'apikey' => api_key
117
116
  }
118
- if @expected_returned_etags.include? mocked_etag
119
- expected_request_headers['If-None-Match'] = mocked_etag
120
- else
121
- @expected_returned_etags << mocked_etag
122
- end
123
117
  @expected_stubs << [
124
118
  stub_request(http_method, "https://#{host}#{path}").with(headers: expected_request_headers).to_return(
125
119
  status: [code, message],
@@ -190,9 +184,6 @@ RSpec.configure do |config|
190
184
  @nexus_mods = nil
191
185
  # Reload the ApiClient as it stores caches at class level
192
186
  NexusMods::ApiClient.clear_cacheable_expiry_caches
193
- # Keep a list of the etags we should have returned, so that we know when queries should contain them
194
- # Array<String>
195
- @expected_returned_etags = []
196
187
  # List of expected stubs and the number of times they were supposed to mock
197
188
  # Array< [ WebMock::RequestStub, Integer ] >
198
189
  @expected_stubs = []
@@ -205,6 +196,7 @@ RSpec.configure do |config|
205
196
  config.around do |example|
206
197
  example.call
207
198
  ensure
199
+ # This would dump the logs in case of debug mode
208
200
  reset_nexus_mods
209
201
  end
210
202
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_mods
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muriel Salvan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-10 00:00:00.000000000 Z
11
+ date: 2023-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.7'
27
- - !ruby/object:Gem::Dependency
28
- name: faraday-http-cache
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.4'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.4'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: cacheable
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -157,7 +143,6 @@ files:
157
143
  - lib/nexus_mods/cacheable_with_expiry.rb
158
144
  - lib/nexus_mods/core_extensions/cacheable/cache_adapters/persistent_json_adapter.rb
159
145
  - lib/nexus_mods/core_extensions/cacheable/method_generator.rb
160
- - lib/nexus_mods/file_cache.rb
161
146
  - lib/nexus_mods/version.rb
162
147
  - spec/nexus_mods_test/factories/games.rb
163
148
  - spec/nexus_mods_test/factories/mod_files.rb
@@ -1,71 +0,0 @@
1
- class NexusMods
2
-
3
- # Simple key/value file cache
4
- class FileCache
5
-
6
- # Constructor
7
- #
8
- # Parameters::
9
- # * *file* (String): File to use as a cache
10
- def initialize(file)
11
- @file = file
12
- @cache_content = File.exist?(file) ? JSON.parse(File.read(file)) : {}
13
- end
14
-
15
- # Dump the cache in file
16
- def dump
17
- File.write(@file, @cache_content.to_json)
18
- end
19
-
20
- # Get the cache content as a Hash
21
- #
22
- # Result::
23
- # * Hash<String, Object>: Cache content
24
- def to_h
25
- @cache_content
26
- end
27
-
28
- # Is a given key present in the cache?
29
- #
30
- # Parameters::
31
- # * *key* (String): The key
32
- # Result::
33
- # * Boolean: Is a given key present in the cache?
34
- def key?(key)
35
- @cache_content.key?(key)
36
- end
37
-
38
- # Read a key from the cache
39
- #
40
- # Parameters:
41
- # * *key* (String): The cache key
42
- # Result::
43
- # * Object or nil: JSON-serializable object storing the value, or nil in case of cache-miss
44
- def read(key)
45
- @cache_content.key?(key) ? @cache_content[key] : nil
46
- end
47
-
48
- alias [] read
49
-
50
- # Write a key/value in the cache
51
- #
52
- # Parameters:
53
- # * *key* (String): The key
54
- # * *value* (Object): JSON-serializable object storing the value
55
- def write(key, value)
56
- @cache_content[key] = value
57
- end
58
-
59
- alias []= write
60
-
61
- # Delete a key in the cache
62
- #
63
- # Parameters:
64
- # * *key* (String): The key
65
- def delete(key)
66
- @cache_content.delete(key)
67
- end
68
-
69
- end
70
-
71
- end