Class: CurseForge

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(token, **options) ⇒ CurseForge



12
13
14
15
16
17
18
19
# File 'lib/curseforge.rb', line 12

def initialize(token, **options)
  @token = token

  options[:url] ||= 'https://api.curseforge.com'
  options[:headers] ||= {}
  options[:headers]["x-api-key"] = @token
  @api = Faraday.new(options)
end

Instance Method Details

#get_mod(mod_id) ⇒ Hash

Raises:

  • (Faraday::Error)

See Also:



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

Raises:

  • (Faraday::Error)

See Also:



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

Examples:

require 'json'
require 'curseforge'

file = File.open('manifest.json')
json = JSON.parse(file.read)
file.close
client = CurseForge.new('token')
mods = client.get_mods_from_manifest(json)

Raises:

  • (Faraday::Error)

See Also:



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.

Options Hash (**query):

  • classId (Integer)

    Filter by section ID.

  • categoryId (Integer)

    Filter by category ID.

  • categoryIds (String)

    Filter by a list of category IDs (overrides categoryId)

  • gameVersion (String)

    Filter by game version string

  • gameVersions (String)

    Filter by a list of game version strings (overrides gameVersion)

  • searchFilter (String)

    Free text search in the mod name and author

  • sortField (String)

    Filter by ModsSearchSortField enumeration

  • sortOrder (String)

    asc for ascending, desc for descending

  • modLoaderType (String)

    Filter mods associated with a specific modloader (requires gameVersion)

  • modLoaderTypes (String)

    Filter by a list of mod loader types (overrides modLoaderType)

  • gameVersionTypeId (Integer)

    Filter mods tagged with versions of the given gameVersionTypeId

  • authorId (Integer)

    Filter by mods authored by the given authorId

  • primaryAuthorId (Integer)

    Filter by mods owned by the given primaryAuthorId

  • slug (String)

    Filter by slug (use with classId for unique result)

  • index (Integer)

    Zero-based index of the first item to include in the response (max: index + pageSize <= 10,000)

  • pageSize (Integer)

    Number of items to include in the response (default/max: 50).

Raises:

  • (Faraday::Error)

See Also:



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