nexus_mods 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/lib/nexus_mods/api/api_limits.rb +64 -0
  4. data/lib/nexus_mods/api/category.rb +54 -0
  5. data/lib/nexus_mods/api/game.rb +106 -0
  6. data/lib/nexus_mods/api/mod.rb +141 -0
  7. data/lib/nexus_mods/api/mod_file.rb +116 -0
  8. data/lib/nexus_mods/api/user.rb +55 -0
  9. data/lib/nexus_mods/api_client.rb +182 -0
  10. data/lib/nexus_mods/cacheable_api.rb +52 -0
  11. data/lib/nexus_mods/cacheable_with_expiry.rb +70 -0
  12. data/lib/nexus_mods/core_extensions/cacheable/cache_adapters/persistent_json_adapter.rb +62 -0
  13. data/lib/nexus_mods/core_extensions/cacheable/method_generator.rb +62 -0
  14. data/lib/nexus_mods/file_cache.rb +71 -0
  15. data/lib/nexus_mods/version.rb +1 -1
  16. data/lib/nexus_mods.rb +32 -86
  17. data/spec/nexus_mods_test/factories/games.rb +135 -0
  18. data/spec/nexus_mods_test/factories/mod_files.rb +113 -0
  19. data/spec/nexus_mods_test/factories/mods.rb +144 -0
  20. data/spec/nexus_mods_test/helpers.rb +39 -14
  21. data/spec/nexus_mods_test/scenarios/nexus_mods/{api_limits_spec.rb → api/api_limits_spec.rb} +10 -3
  22. data/spec/nexus_mods_test/scenarios/nexus_mods/api/game_spec.rb +93 -0
  23. data/spec/nexus_mods_test/scenarios/nexus_mods/api/mod_file_spec.rb +73 -0
  24. data/spec/nexus_mods_test/scenarios/nexus_mods/api/mod_spec.rb +62 -0
  25. data/spec/nexus_mods_test/scenarios/nexus_mods_caching_spec.rb +88 -0
  26. metadata +37 -13
  27. data/lib/nexus_mods/api_limits.rb +0 -44
  28. data/lib/nexus_mods/category.rb +0 -37
  29. data/lib/nexus_mods/game.rb +0 -78
  30. data/lib/nexus_mods/mod.rb +0 -106
  31. data/lib/nexus_mods/mod_file.rb +0 -86
  32. data/lib/nexus_mods/user.rb +0 -37
  33. data/spec/nexus_mods_test/scenarios/nexus_mods/game_spec.rb +0 -180
  34. data/spec/nexus_mods_test/scenarios/nexus_mods/mod_file_spec.rb +0 -140
  35. data/spec/nexus_mods_test/scenarios/nexus_mods/mod_spec.rb +0 -185
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c443ff1432283f58fd5928a67607934721bd733dd07dc5297451c990cf72ae7f
4
- data.tar.gz: 1f29640cabaa7e862a119cb9116d1f15049af67d7eaaa51d1707e8aa99c2cdd6
3
+ metadata.gz: 7858789972e8674c6ba24c53d36e4af87b09b8636e84faced240ff0edd1eb3fa
4
+ data.tar.gz: 29df7fc4849e885e6a9aa705d1ae4868215e1181bdff8814d806787ff948790d
5
5
  SHA512:
6
- metadata.gz: 6d94ec311b0e8174052e6c7c352e868928d243c7206ffb97206e7ddf273fbb7e417b29acbc02bc0ec72b7ce1d8bc8d2622a398b8e054423f5669d5700b0a063d
7
- data.tar.gz: 8ed74a2422c6e1109a90859bd5a66b5c440ce9cab86f17aaa2d52821bd1715040aab4031f9a4b879031fae7c03b449515ecdb1ea35683f293ee867252426ded7
6
+ metadata.gz: 522c72b5d4cabff4d57609f9c593c5e75345c675343397e7e75c0bc10c7b29c8df72c26d7fa51bc73265bb8f0c025d3b929ef5a1810711928f416b851bedfef9
7
+ data.tar.gz: 17b804dfc30795f57c5e862a4990b39aec762f0b3058513956204443e2ebfe59df5285ceda0634a6644cdcd8e45619a8248964bf3028b2aa96852cbc4dd69f9f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [v0.3.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v0.2.0...v0.3.0) (2023-04-10 09:13:43)
2
+
3
+ ### Features
4
+
5
+ * [[Feature] Implement caching of API queries with configurable expiry times](https://github.com/Muriel-Salvan/nexus_mods/commit/7f74e25d046adbcec394ce33a3802ed9e91f3a52)
6
+
7
+ # [v0.2.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v0.1.1...v0.2.0) (2023-04-10 08:45:44)
8
+
9
+ ### Features
10
+
11
+ * [[Feature] Make objects API comparable correctly](https://github.com/Muriel-Salvan/nexus_mods/commit/ff219c7050aa8421095c666fe2394c621f317e43)
12
+
1
13
  # [v0.1.1](https://github.com/Muriel-Salvan/nexus_mods/compare/v0.1.0...v0.1.1) (2023-03-27 19:57:47)
2
14
 
3
15
  ### Patches
@@ -0,0 +1,64 @@
1
+ class NexusMods
2
+
3
+ module Api
4
+
5
+ # Object giving the NexusMods API limits
6
+ class ApiLimits
7
+
8
+ attr_reader(
9
+ *%i[
10
+ daily_limit
11
+ daily_remaining
12
+ daily_reset
13
+ hourly_limit
14
+ hourly_remaining
15
+ hourly_reset
16
+ ]
17
+ )
18
+
19
+ # Constructor
20
+ #
21
+ # Parameters::
22
+ # * *daily_limit* (Integer): The daily limit
23
+ # * *daily_remaining* (Integer): The daily remaining
24
+ # * *daily_reset* (Integer): The daily reset time
25
+ # * *hourly_limit* (Integer): The hourly limit
26
+ # * *hourly_remaining* (Integer): The hourly remaining
27
+ # * *hourly_reset* (Integer): The hourly reset time
28
+ def initialize(
29
+ daily_limit:,
30
+ daily_remaining:,
31
+ daily_reset:,
32
+ hourly_limit:,
33
+ hourly_remaining:,
34
+ hourly_reset:
35
+ )
36
+ @daily_limit = daily_limit
37
+ @daily_remaining = daily_remaining
38
+ @daily_reset = daily_reset
39
+ @hourly_limit = hourly_limit
40
+ @hourly_remaining = hourly_remaining
41
+ @hourly_reset = hourly_reset
42
+ end
43
+
44
+ # Equality operator
45
+ #
46
+ # Parameters::
47
+ # * *other* (Object): Other object to compare with
48
+ # Result::
49
+ # * Boolean: Are objects equal?
50
+ def ==(other)
51
+ other.is_a?(ApiLimits) &&
52
+ @daily_limit == other.daily_limit &&
53
+ @daily_remaining == other.daily_remaining &&
54
+ @daily_reset == other.daily_reset &&
55
+ @hourly_limit == other.hourly_limit &&
56
+ @hourly_remaining == other.hourly_remaining &&
57
+ @hourly_reset == other.hourly_reset
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,54 @@
1
+ class NexusMods
2
+
3
+ module Api
4
+
5
+ # Categories defined for a game in NexusMods
6
+ class Category
7
+
8
+ attr_reader(
9
+ *%i[
10
+ id
11
+ name
12
+ ]
13
+ )
14
+
15
+ attr_accessor(
16
+ *%i[
17
+ parent_category
18
+ ]
19
+ )
20
+
21
+ # Constructor
22
+ #
23
+ # Parameters::
24
+ # *id* (Integer): The category id
25
+ # *name* (String): The category id
26
+ # *parent_category* (Category or nil): The parent category, or nil if none [default: nil]
27
+ def initialize(
28
+ id:,
29
+ name:,
30
+ parent_category: nil
31
+ )
32
+ @id = id
33
+ @name = name
34
+ @parent_category = parent_category
35
+ end
36
+
37
+ # Equality operator
38
+ #
39
+ # Parameters::
40
+ # * *other* (Object): Other object to compare with
41
+ # Result::
42
+ # * Boolean: Are objects equal?
43
+ def ==(other)
44
+ other.is_a?(Category) &&
45
+ @id == other.id &&
46
+ @name == other.name &&
47
+ @parent_category == other.parent_category
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,106 @@
1
+ class NexusMods
2
+
3
+ module Api
4
+
5
+ # A NexusMods game.
6
+ # Attributes info can be taken from there:
7
+ # * https://github.com/Nexus-Mods/node-nexus-api/blob/master/docs/interfaces/_types_.igameinfo.md
8
+ class Game
9
+
10
+ attr_reader(
11
+ *%i[
12
+ id
13
+ name
14
+ forum_url
15
+ nexusmods_url
16
+ genre
17
+ domain_name
18
+ approved_date
19
+ files_count
20
+ files_views
21
+ files_endorsements
22
+ downloads_count
23
+ authors_count
24
+ mods_count
25
+ categories
26
+ ]
27
+ )
28
+
29
+ # Constructor
30
+ #
31
+ # Parameters::
32
+ # * *id* (Integer): The game's id
33
+ # * *name* (String): The game's name
34
+ # * *forum_url* (String): The game's forum's URL
35
+ # * *nexusmods_url* (String): The game's NexusMods' URL
36
+ # * *genre* (String): The game's genre
37
+ # * *domain_name* (String): The game's domain's name
38
+ # * *approved_date* (Time): The game's approved date (time when the game was added)
39
+ # * *files_count* (Integer): The game's files' count [default: 0]
40
+ # * *files_views* (Integer): The game's files' views [default: 0]
41
+ # * *files_endorsements* (Integer): The game's files' endorsements [default: 0]
42
+ # * *downloads_count* (Integer): The game's downloads' count [default: 0]
43
+ # * *authors_count* (Integer): The game's authors's count [default: 0]
44
+ # * *mods_count* (Integer): The game's mods' count [default: 0]
45
+ # * *categories* (Array<Category>): The list of game's categories [default: []]
46
+ def initialize(
47
+ id:,
48
+ name:,
49
+ forum_url:,
50
+ nexusmods_url:,
51
+ genre:,
52
+ domain_name:,
53
+ approved_date:,
54
+ files_count: 0,
55
+ files_views: 0,
56
+ files_endorsements: 0,
57
+ downloads_count: 0,
58
+ authors_count: 0,
59
+ mods_count: 0,
60
+ categories: []
61
+ )
62
+ @id = id
63
+ @name = name
64
+ @forum_url = forum_url
65
+ @nexusmods_url = nexusmods_url
66
+ @genre = genre
67
+ @domain_name = domain_name
68
+ @approved_date = approved_date
69
+ @files_count = files_count
70
+ @files_views = files_views
71
+ @files_endorsements = files_endorsements
72
+ @downloads_count = downloads_count
73
+ @authors_count = authors_count
74
+ @mods_count = mods_count
75
+ @categories = categories
76
+ end
77
+
78
+ # Equality operator
79
+ #
80
+ # Parameters::
81
+ # * *other* (Object): Other object to compare with
82
+ # Result::
83
+ # * Boolean: Are objects equal?
84
+ def ==(other)
85
+ other.is_a?(Game) &&
86
+ @id == other.id &&
87
+ @name == other.name &&
88
+ @forum_url == other.forum_url &&
89
+ @nexusmods_url == other.nexusmods_url &&
90
+ @genre == other.genre &&
91
+ @domain_name == other.domain_name &&
92
+ @approved_date == other.approved_date &&
93
+ @files_count == other.files_count &&
94
+ @files_views == other.files_views &&
95
+ @files_endorsements == other.files_endorsements &&
96
+ @downloads_count == other.downloads_count &&
97
+ @authors_count == other.authors_count &&
98
+ @mods_count == other.mods_count &&
99
+ @categories == other.categories
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,141 @@
1
+ class NexusMods
2
+
3
+ module Api
4
+
5
+ # A NexusMods mod.
6
+ # Attributes info can be taken from there:
7
+ # * https://github.com/Nexus-Mods/node-nexus-api/blob/master/docs/interfaces/_types_.imodinfo.md
8
+ class Mod
9
+
10
+ attr_reader(
11
+ *%i[
12
+ uid
13
+ mod_id
14
+ game_id
15
+ allow_rating
16
+ domain_name
17
+ category_id
18
+ version
19
+ created_time
20
+ updated_time
21
+ author
22
+ contains_adult_content
23
+ status
24
+ available
25
+ uploader
26
+ name
27
+ summary
28
+ description
29
+ picture_url
30
+ downloads_count
31
+ unique_downloads_count
32
+ endorsements_count
33
+ ]
34
+ )
35
+
36
+ # Constructor
37
+ #
38
+ # Parameters::
39
+ # * *uid* (Integer): The mod's uid
40
+ # * *mod_id* (Integer): The mod's id
41
+ # * *game_id* (Integer): The mod's game id
42
+ # * *allow_rating* (Boolean): Does this mod allow endorsements?
43
+ # * *domain_name* (String): The mod's domain name
44
+ # * *category_id* (String): The mod's category id
45
+ # * *version* (String): The mod's version
46
+ # * *created_time* (Time): The mod's creation time
47
+ # * *updated_time* (Time): The mod's update time
48
+ # * *author* (String): The mod's author
49
+ # * *contains_adult_content* (Boolean): Does this mod contain adult content?
50
+ # * *status* (String): The mod's status
51
+ # * *available* (Boolean): Is the mod publicly available?
52
+ # * *uploader* (User): The mod's uploader information
53
+ # * *name* (String or nil): The mod's name, or nil if under moderation [default: nil]
54
+ # * *summary* (String or nil): The mod's summary, or nil if none [default: nil]
55
+ # * *description* (String or nil): The mod's description, or nil if none [default: nil]
56
+ # * *picture_url* (String): The mod's picture_url [default: nil]
57
+ # * *downloads_count* (Integer): The mod's downloads' count [default: 0]
58
+ # * *unique_downloads_count* (Integer): The mod's unique downloads' count [default: 0]
59
+ # * *endorsements_count* (Integer): The mod's endorsements' count [default: 0]
60
+ def initialize(
61
+ uid:,
62
+ mod_id:,
63
+ game_id:,
64
+ allow_rating:,
65
+ domain_name:,
66
+ category_id:,
67
+ version:,
68
+ created_time:,
69
+ updated_time:,
70
+ author:,
71
+ contains_adult_content:,
72
+ status:,
73
+ available:,
74
+ uploader:,
75
+ name: nil,
76
+ summary: nil,
77
+ description: nil,
78
+ picture_url: nil,
79
+ downloads_count: 0,
80
+ unique_downloads_count: 0,
81
+ endorsements_count: 0
82
+ )
83
+ @uid = uid
84
+ @mod_id = mod_id
85
+ @game_id = game_id
86
+ @allow_rating = allow_rating
87
+ @domain_name = domain_name
88
+ @category_id = category_id
89
+ @version = version
90
+ @created_time = created_time
91
+ @updated_time = updated_time
92
+ @author = author
93
+ @contains_adult_content = contains_adult_content
94
+ @status = status
95
+ @available = available
96
+ @uploader = uploader
97
+ @name = name
98
+ @summary = summary
99
+ @description = description
100
+ @picture_url = picture_url
101
+ @downloads_count = downloads_count
102
+ @unique_downloads_count = unique_downloads_count
103
+ @endorsements_count = endorsements_count
104
+ end
105
+
106
+ # Equality operator
107
+ #
108
+ # Parameters::
109
+ # * *other* (Object): Other object to compare with
110
+ # Result::
111
+ # * Boolean: Are objects equal?
112
+ def ==(other)
113
+ other.is_a?(Mod) &&
114
+ @uid == other.uid &&
115
+ @mod_id == other.mod_id &&
116
+ @game_id == other.game_id &&
117
+ @allow_rating == other.allow_rating &&
118
+ @domain_name == other.domain_name &&
119
+ @category_id == other.category_id &&
120
+ @version == other.version &&
121
+ @created_time == other.created_time &&
122
+ @updated_time == other.updated_time &&
123
+ @author == other.author &&
124
+ @contains_adult_content == other.contains_adult_content &&
125
+ @status == other.status &&
126
+ @available == other.available &&
127
+ @uploader == other.uploader &&
128
+ @name == other.name &&
129
+ @summary == other.summary &&
130
+ @description == other.description &&
131
+ @picture_url == other.picture_url &&
132
+ @downloads_count == other.downloads_count &&
133
+ @unique_downloads_count == other.unique_downloads_count &&
134
+ @endorsements_count == other.endorsements_count
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+
141
+ end
@@ -0,0 +1,116 @@
1
+ class NexusMods
2
+
3
+ module Api
4
+
5
+ # A NexusMods file.
6
+ # Attributes info can be taken from there:
7
+ # * https://github.com/Nexus-Mods/node-nexus-api/blob/master/docs/interfaces/_types_.ifileinfo.md
8
+ class ModFile
9
+
10
+ attr_reader(
11
+ *%i[
12
+ ids
13
+ uid
14
+ id
15
+ name
16
+ version
17
+ category_id
18
+ category_name
19
+ is_primary
20
+ size
21
+ file_name
22
+ uploaded_time
23
+ mod_version
24
+ external_virus_scan_url
25
+ description
26
+ changelog_html
27
+ content_preview_url
28
+ ]
29
+ )
30
+
31
+ # Constructor
32
+ #
33
+ # Parameters::
34
+ # * *ids* (Array<Integer>): The file's list of IDs
35
+ # * *uid* (Integer): The file's UID
36
+ # * *id* (Integer): The file's main ID
37
+ # * *name* (String): The file's name
38
+ # * *version* (String): The file's version
39
+ # * *category_id* (Symbol): The file's category's ID
40
+ # * *category_name* (String): The file's category_name
41
+ # * *is_primary* (String): Is this file the primary download one?
42
+ # * *size* (Integer): The file's size (in bytes)
43
+ # * *file_name* (String): The file's exact file name
44
+ # * *uploaded_time* (Time): The file's uploaded time
45
+ # * *mod_version* (String): The file's mod version
46
+ # * *external_virus_scan_url* (String): The URL of virus scan for this file
47
+ # * *description* (String): The file's description
48
+ # * *changelog_html* (String): The file's change log in HTML
49
+ # * *content_preview_url* (String): URL to a JSON that gives info on the file's content
50
+ def initialize(
51
+ ids:,
52
+ uid:,
53
+ id:,
54
+ name:,
55
+ version:,
56
+ category_id:,
57
+ category_name:,
58
+ is_primary:,
59
+ size:,
60
+ file_name:,
61
+ uploaded_time:,
62
+ mod_version:,
63
+ external_virus_scan_url:,
64
+ description:,
65
+ changelog_html:,
66
+ content_preview_url:
67
+ )
68
+ @ids = ids
69
+ @uid = uid
70
+ @id = id
71
+ @name = name
72
+ @version = version
73
+ @category_id = category_id
74
+ @category_name = category_name
75
+ @is_primary = is_primary
76
+ @size = size
77
+ @file_name = file_name
78
+ @uploaded_time = uploaded_time
79
+ @mod_version = mod_version
80
+ @external_virus_scan_url = external_virus_scan_url
81
+ @description = description
82
+ @changelog_html = changelog_html
83
+ @content_preview_url = content_preview_url
84
+ end
85
+
86
+ # Equality operator
87
+ #
88
+ # Parameters::
89
+ # * *other* (Object): Other object to compare with
90
+ # Result::
91
+ # * Boolean: Are objects equal?
92
+ def ==(other)
93
+ other.is_a?(ModFile) &&
94
+ @ids == other.ids &&
95
+ @uid == other.uid &&
96
+ @id == other.id &&
97
+ @name == other.name &&
98
+ @version == other.version &&
99
+ @category_id == other.category_id &&
100
+ @category_name == other.category_name &&
101
+ @is_primary == other.is_primary &&
102
+ @size == other.size &&
103
+ @file_name == other.file_name &&
104
+ @uploaded_time == other.uploaded_time &&
105
+ @mod_version == other.mod_version &&
106
+ @external_virus_scan_url == other.external_virus_scan_url &&
107
+ @description == other.description &&
108
+ @changelog_html == other.changelog_html &&
109
+ @content_preview_url == other.content_preview_url
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,55 @@
1
+ class NexusMods
2
+
3
+ module Api
4
+
5
+ # A user on NExusMods.
6
+ # Mainly used for uploaders information.
7
+ class User
8
+
9
+ attr_reader(
10
+ *%i[
11
+ member_id
12
+ member_group_id
13
+ name
14
+ profile_url
15
+ ]
16
+ )
17
+
18
+ # Constructor
19
+ #
20
+ # Parameters::
21
+ # * *member_id* (Integer): The user's member id
22
+ # * *member_group_id* (Integer): The user's member group id
23
+ # * *name* (String): The user's name
24
+ # * *profile_url* (String): The user's profile URL
25
+ def initialize(
26
+ member_id:,
27
+ member_group_id:,
28
+ name:,
29
+ profile_url:
30
+ )
31
+ @member_id = member_id
32
+ @member_group_id = member_group_id
33
+ @name = name
34
+ @profile_url = profile_url
35
+ end
36
+
37
+ # Equality operator
38
+ #
39
+ # Parameters::
40
+ # * *other* (Object): Other object to compare with
41
+ # Result::
42
+ # * Boolean: Are objects equal?
43
+ def ==(other)
44
+ other.is_a?(User) &&
45
+ @member_id == other.member_id &&
46
+ @member_group_id == other.member_group_id &&
47
+ @name == other.name &&
48
+ @profile_url == other.profile_url
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end