Class: CurseForge
- Inherits:
-
Object
- Object
- CurseForge
- Defined in:
- lib/curseforge.rb,
lib/curseforge/error.rb,
lib/curseforge/version.rb
Overview
CurseForge API Wrapper by PackBuilder.io
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'0.3.0'
Instance Method Summary collapse
- #get_mod(mod_id) ⇒ Hash
- #get_mods(*mods_ids, filter_pc_only: true) ⇒ Hash
- #get_mods_from_manifest(json) ⇒ Hash
-
#initialize(token, **options) ⇒ CurseForge
constructor
A new instance of CurseForge.
-
#search_mods(game_id, **query) ⇒ Hash
Filters mods based on the given query parameters.
Constructor Details
#initialize(token, **options) ⇒ CurseForge
12 13 14 15 16 17 18 19 |
# File 'lib/curseforge.rb', line 12 def initialize(token, **) @token = token [:url] ||= 'https://api.curseforge.com' [:headers] ||= {} [:headers]["x-api-key"] = @token @api = Faraday.new() end |
Instance Method Details
#get_mod(mod_id) ⇒ Hash
25 26 27 |
# File 'lib/curseforge.rb', line 25 def get_mod(mod_id) req(:get, "/v1/mods/#{mod_id}") end |
#get_mods(*mods_ids, filter_pc_only: true) ⇒ Hash
34 35 36 37 38 39 |
# File 'lib/curseforge.rb', line 34 def get_mods(*mods_ids, filter_pc_only: true) req(:post, '/v1/mods', body: { modIds: mods_ids, filterPCOnly: filter_pc_only }.to_json, headers: { 'Content-Type' => 'application/json' })["data"] end |
#get_mods_from_manifest(json) ⇒ Hash
54 55 56 |
# File 'lib/curseforge.rb', line 54 def get_mods_from_manifest(json) get_mods(*json['files'].map { |f| f['projectID'] }) end |
#search_mods(game_id, **query) ⇒ Hash
Filters mods based on the given query parameters.
82 83 84 85 |
# File 'lib/curseforge.rb', line 82 def search_mods(game_id, **query) query[:gameId] = game_id req(:get, '/v1/mods/search', body: query) end |