nexusapi

package
v0.0.0-...-c9f76b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package nexusapi implements NexusMods api in go. Nexusmods is used here as: Nexus, NexusMods, nexusmods.com. All means the same in context of this library.

Official API documentation: SSO Registration description:

Generate a random unique id (we suggest uuid v4)

Create a websocket connection to wss://sso.nexusmods.com

When the connection is established, send a JSON encoded message containing the id you just generated and the appid you got on registration. Example: { "id": "4c694264-1fdb-48c6-a5a0-8edd9e53c7a6", "appid": "your_fancy_app" }

From now on, until the connection is closed, send a websocket ping once every 30 seconds.

Have the user open https://www.nexusmods.com/sso?id=xyz (id being the random id you generated in step 1) in the default browser On the website users will be asked to log-in to Nexus Mods if they aren't already. Then they will be asked to authorize your application to use their account.

Once the user confirms, a message will be sent to your websocket with the APIKEY (not encoded, just the plain key). This is the only non-error message you will ever receive from the server.

Save away the key and close the connection.

taken from: https://github.com/Nexus-Mods/node-nexus-api readme file.

Swagger: https://app.swaggerhub.com/apis-docs/NexusMods/nexus-mods_public_api_params_in_form_data/1.0#/

Example usage:

  fmt.Println("check your browser! it waits for confirmation")
	 uu, err := uuid.NewV4()
	 n := New("My app test", "0.1", myuuid.String(), "")
	 c := make(chan os.Signal, 1)
	 signal.Notify(c, os.Interrupt)

	 apikey, err := n.RegisterTest(c)
	 if err != nil {
		 fmt.Println(err)
	 }
  fmt.Println(apikey)

For more examples look into test file in this dir.

Index

Constants

View Source
const (
	// URLBASE contains nexus api server address
	URLBASE = "https://api.nexusmods.com"
	// APIVER contains nexus api version
	APIVER = "v1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Mod

type Mod struct {
	ID      int
	FileID  int
	Game    string
	Expires int
	Key     string
	UserID  int
}

Mod contains data neccessary to work with API.

type ModDownload

type ModDownload []struct {
	Name      string `json:"-"`
	ShortName string `json:"-"`
	URI       string `json:"URI"`
}

ModDownload struct represents download info. Only URI is used.

type ModInfo

type ModInfo struct {
	FileID               int       `json:"file_id"`
	Name                 string    `json:"name"`
	Version              string    `json:"version"`
	CategoryID           int       `json:"category_id"`
	CategoryName         string    `json:"category_name"`
	IsPrimary            bool      `json:"is_primary"`
	Size                 int       `json:"size"`
	FileName             string    `json:"file_name"`
	UploadedTimestamp    int       `json:"uploaded_timestamp"`
	UploadedTime         time.Time `json:"uploaded_time"`
	ModVersion           string    `json:"mod_version"`
	ExternalVirusScanURL string    `json:"external_virus_scan_url"`
	Description          string    `json:"description"`
	SizeKb               int       `json:"size_kb"`
	ChangelogHTML        string    `json:"changelog_html"`
}

ModInfo contains all data returned from mod info query.

type ModMD5Info

type ModMD5Info []struct {
	Mod struct {
		Name                    string    `json:"name"`
		Summary                 string    `json:"summary"`
		Description             string    `json:"description"`
		PictureURL              string    `json:"picture_url"`
		ModID                   int       `json:"mod_id"`
		GameID                  int       `json:"game_id"`
		DomainName              string    `json:"domain_name"`
		CategoryID              int       `json:"category_id"`
		Version                 string    `json:"version"`
		CreatedTimestamp        int       `json:"created_timestamp"`
		CreatedTime             time.Time `json:"created_time"`
		UpdatedTimestamp        int       `json:"updated_timestamp"`
		UpdatedTime             time.Time `json:"updated_time"`
		Author                  string    `json:"author"`
		UploadedBy              string    `json:"uploaded_by"`
		UploadedUsersProfileURL string    `json:"uploaded_users_profile_url"`
		ContainsAdultContent    bool      `json:"contains_adult_content"`
		Status                  string    `json:"status"`
		Available               bool      `json:"available"`
		User                    struct {
			MemberID      int    `json:"member_id"`
			MemberGroupID int    `json:"member_group_id"`
			Name          string `json:"name"`
		} `json:"user"`
		Endorsement interface{} `json:"endorsement"`
	} `json:"mod"`
	FileDetails struct {
		FileID               int         `json:"file_id"`
		Name                 string      `json:"name"`
		Version              string      `json:"version"`
		CategoryID           int         `json:"category_id"`
		CategoryName         string      `json:"category_name"`
		IsPrimary            bool        `json:"is_primary"`
		Size                 int         `json:"size"`
		FileName             string      `json:"file_name"`
		UploadedTimestamp    int         `json:"uploaded_timestamp"`
		UploadedTime         time.Time   `json:"uploaded_time"`
		ModVersion           string      `json:"mod_version"`
		ExternalVirusScanURL string      `json:"external_virus_scan_url"`
		ChangelogHTML        interface{} `json:"changelog_html"`
		Md5                  string      `json:"md5"`
	} `json:"file_details"`
}

ModMD5Info represents enormous amount of info returned when searching for mod by md5 hash

type Nexus

type Nexus struct {
	// contains filtered or unexported fields
}

Nexus represents NexusMods connection.

func New

func New(appName, appVersion, appUUID, apikey string) *Nexus

New returns Nexus type. AppUUID should be generated every time you want to make new registration. If reused NexusMods will start terminating websocket connection, error: websocket: close 1006 (abnormal closure): unexpected EOF Store apikey somewhere safe, reuse.

func (*Nexus) GetModByMD5

func (n *Nexus) GetModByMD5(md5, game string) (*ModMD5Info, error)

GetModByMD5 retrieves info from nexus based on file MD5 hash. This is very good way to retrieve info it You have only downloaded file.

func (n *Nexus) GetModDownloadLink(mod *Mod) (string, error)

GetModDownloadLink returns mod file download link.

func (*Nexus) GetModFileInfo

func (n *Nexus) GetModFileInfo(mod *Mod) (*ModInfo, error)

GetModFileInfo returns file metadata.

func (*Nexus) Register

func (n *Nexus) Register(exit chan os.Signal) (string, error)

Register registers NexusMods SSO via websocket, it returns apikey or error. It will open NexusMods page in the browser, waiting for user to confirm. At the end websocet is disconected and never used again. exit channel is used to correctly end connection with server, use it like that:

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)

You can always send signal to channel when needed:

interrupt <- os.Interrupt

If apikey param is not empty string, it will not perform any action, but return apikey back.

func (*Nexus) RegisterTest

func (n *Nexus) RegisterTest(exit chan os.Signal) (string, error)

RegisterTest is the same as Register, but do not send application name, to NexusMods. This allow to register as Vortex and works without contacting NexusMods. Do not overuse this! Contact NexusMods to get your app registered.

type NexusError

type NexusError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

NexusError represent message sent when error occured. It implements error interface, so it is used as sentinel error.

func (*NexusError) Error

func (ne *NexusError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL