nexus_mods 0.1.1 → 0.2.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: c443ff1432283f58fd5928a67607934721bd733dd07dc5297451c990cf72ae7f
4
- data.tar.gz: 1f29640cabaa7e862a119cb9116d1f15049af67d7eaaa51d1707e8aa99c2cdd6
3
+ metadata.gz: efdb25aee2a65f563017933ab77b1360d3ab04d26abf3f945cd9c1cf3d0a1a0d
4
+ data.tar.gz: dc538a350901669fbca2e6cbc299daf091bcf0779f82c3e9b718398b5f61e877
5
5
  SHA512:
6
- metadata.gz: 6d94ec311b0e8174052e6c7c352e868928d243c7206ffb97206e7ddf273fbb7e417b29acbc02bc0ec72b7ce1d8bc8d2622a398b8e054423f5669d5700b0a063d
7
- data.tar.gz: 8ed74a2422c6e1109a90859bd5a66b5c440ce9cab86f17aaa2d52821bd1715040aab4031f9a4b879031fae7c03b449515ecdb1ea35683f293ee867252426ded7
6
+ metadata.gz: 6e2f2ee9025ab0650fc96ad4d10ff41e8375caa8c6ab51e64ceec5527630e97806bfdbce74d2db2ba63bc58a45371392c98d4fb20ccbd7399b2711123fce125f
7
+ data.tar.gz: a6519240cb31bc1cf25a5f0b7001be67e91b41588817739f50a8c8b4d1558a2129ecb43ba6239454717fe47d6aea47f152eeb08c374bce18c83fe84003a378fd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [v0.2.0](https://github.com/Muriel-Salvan/nexus_mods/compare/v0.1.1...v0.2.0) (2023-04-10 08:45:44)
2
+
3
+ ### Features
4
+
5
+ * [[Feature] Make objects API comparable correctly](https://github.com/Muriel-Salvan/nexus_mods/commit/ff219c7050aa8421095c666fe2394c621f317e43)
6
+
1
7
  # [v0.1.1](https://github.com/Muriel-Salvan/nexus_mods/compare/v0.1.0...v0.1.1) (2023-03-27 19:57:47)
2
8
 
3
9
  ### 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
@@ -1,5 +1,5 @@
1
1
  class NexusMods
2
2
 
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
 
5
5
  end
data/lib/nexus_mods.rb CHANGED
@@ -3,12 +3,12 @@ require 'json'
3
3
  require 'time'
4
4
  require 'tmpdir'
5
5
  require 'faraday'
6
- require 'nexus_mods/api_limits'
7
- require 'nexus_mods/category'
8
- require 'nexus_mods/game'
9
- require 'nexus_mods/user'
10
- require 'nexus_mods/mod'
11
- require 'nexus_mods/mod_file'
6
+ require 'nexus_mods/api/api_limits'
7
+ require 'nexus_mods/api/category'
8
+ require 'nexus_mods/api/game'
9
+ require 'nexus_mods/api/user'
10
+ require 'nexus_mods/api/mod'
11
+ require 'nexus_mods/api/mod_file'
12
12
 
13
13
  # Ruby API to access NexusMods REST API
14
14
  class NexusMods
@@ -75,7 +75,7 @@ class NexusMods
75
75
  # * ApiLimits: API calls limits
76
76
  def api_limits
77
77
  api_limits_headers = http('users/validate').headers
78
- ApiLimits.new(
78
+ Api::ApiLimits.new(
79
79
  daily_limit: Integer(api_limits_headers['x-rl-daily-limit']),
80
80
  daily_remaining: Integer(api_limits_headers['x-rl-daily-remaining']),
81
81
  daily_reset: Time.parse(api_limits_headers['x-rl-daily-reset']).utc,
@@ -98,7 +98,7 @@ class NexusMods
98
98
  [
99
99
  category_id,
100
100
  [
101
- Category.new(
101
+ Api::Category.new(
102
102
  id: category_id,
103
103
  name: category_json['name']
104
104
  ),
@@ -110,7 +110,7 @@ class NexusMods
110
110
  # Ignore missing parent categories: this situation happens.
111
111
  category.parent_category = categories[parent_category_id]&.first if parent_category_id
112
112
  end
113
- Game.new(
113
+ Api::Game.new(
114
114
  id: game_json['id'],
115
115
  name: game_json['name'],
116
116
  forum_url: game_json['forum_url'],
@@ -138,7 +138,7 @@ class NexusMods
138
138
  # * Mod: Mod information
139
139
  def mod(game_domain_name: @game_domain_name, mod_id: @mod_id)
140
140
  mod_json = api "games/#{game_domain_name}/mods/#{mod_id}"
141
- Mod.new(
141
+ Api::Mod.new(
142
142
  uid: mod_json['uid'],
143
143
  mod_id: mod_json['mod_id'],
144
144
  game_id: mod_json['game_id'],
@@ -152,7 +152,7 @@ class NexusMods
152
152
  contains_adult_content: mod_json['contains_adult_content'],
153
153
  status: mod_json['status'],
154
154
  available: mod_json['available'],
155
- uploader: User.new(
155
+ uploader: Api::User.new(
156
156
  member_id: mod_json['user']['member_id'],
157
157
  member_group_id: mod_json['user']['member_group_id'],
158
158
  name: mod_json['user']['name'],
@@ -189,7 +189,7 @@ class NexusMods
189
189
  category_id = FILE_CATEGORIES[file_json['category_id']]
190
190
  raise "Unknown file category: #{file_json['category_id']}" if category_id.nil?
191
191
 
192
- ModFile.new(
192
+ Api::ModFile.new(
193
193
  ids: file_json['id'],
194
194
  uid: file_json['uid'],
195
195
  id: file_json['file_id'],