Go_Runescape

package module
v0.0.0-...-0369a01 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: MIT Imports: 10 Imported by: 0

README

Go-Runescape Library

Build Status Maintainability codecov Documentation

Overview

Go-Runescape is a library for the Runescape API for Go. The library supports:

  • Getting player Levels
  • Getting a players Rank
  • Getting item details from the grandexchange (RS3 Only)
  • Getting items in categories from the grandexchange (RS3 Only)

If you are after information regarding the old-school grandexchange, read the note at the end.

This project will no longer be updated because the initial goals for the project have been met.

I apollogise if this does not meet the effective go standards. This was primarly built while I was initially learning go (: .


Install

$ go get github.com/kingpulse/Go-Runescape

Documentation

IHttpClient

The IHttpClient is a interface which is used in all of the major functions. The purpose IHttpClient is to add flexibility and testability to the code by allowing the user to define their own Get() method. This allows the user to use proxies, mock returns, etc as long as the struct has a defined Get() method following:

func (t type) Get(url string) (*http.Response, error)

Here is an example of the user using the default http.Client struct to send requests for a players highscores

//Creating default http.Client
defaultClient := htttp.DefaultClient

//Sending request for player highscores.
hs, err := GetPlayerHighscores("le me", highscore_constants.RS3PLAYER, defaultClient)

In the rest of the examples the creation of a struct that inherits the IHttpClient interface will be neglected and HttpClient will be used to fill the parameter where required.

Constants

This package contains two sub-packages dedicated to constants. The constants are stored in sub-packages so the user can easily identify which group they belong to without each constant being prefixed individually.

The two constants packages have constants for information regarding the grandexchange and highscores, they are stored in ge_constants and highscore_constants respectively.

Get a players highscores/levels

To get a players level, rank or experience you can you need to get a PlayerHighscores object and access them from the arrays. This is where the highscore_constants package comes in handy.

Example:

//Getting PlayerHighscores object for passed player and type.
//GetPlayerHighscores method takes the players name and the URL path to the endpoint you are after.
//These have been defined as constants in the Go-Runescape/highscores/highscore_constants package for you.
playerHighscore, err := highscores.GetPlayerHighscores("kingpulse", highscore_constants.RS3PLAYER, HttpClient)

//Getting mining level of the RS3 player "kingpulse" using the highscores_constants package.
miningLevel = playerHighscore.Levels[highscore_constants.MINING]

//Printing the mining level
fmt.Print(strconv.FormatInt(miningLevel, 10))

The same can be done for the players rank or experience in the specified skill. For example:

miningExperience := playerHighscore.XP[highscore_constants.MINING]
miningRank := playerHighscore.Ranks[highscore_constants.MINING]

Get grandexchange item details

Getting details for an item requires the items id. These can be found here. You can get details through a ItemDetail object by doing the following:

//Getting a ItemDetail object
tuna, err := grand_exchange.GetItemDetail(359, HttpClient)

if err != nil {
	//Handle
	return
}
//Displaying the description of a tuna.
fmt.Println(tuna.Description)

Get grandexchange catelog information

You can get information on the grandexchange catelog page through a itemsCatelog object. Before you read the example it is important to note that Jagex and their infinite wisdom have decided to sometimes have price passed as a string or a number which has made it a pain. I've done a simple solution of having the price field as type interface{}. This means you will need to use type assertion to get the type you are after. Generally it is a string. If you have a better solution to this let me know (: Example:

//Getting a itemsCatelog object of based on the first page of high level melee armor starting with the letter b.
catelogue, err := grand_exchange.GetItemsCatalogue(ge_constants.MELEE_ARMOUR_HIGH_LEVEL, 'b', 1, HttpClient)

if err != nil {
	//Handle
	return
}

//Printing the name of the first item on the page    
fmt.Println(catelogue.Items[0].Name)

//Printing todays price of the item.
fmt.Println(catelogue.Items[0].Today.Price.(string))

Get number of items in category for letter

Lets jump right into the example:

//Getting category information for high level melee armor
category, err := grand_exchange.GetCategory(ge_constants.MELEE_ARMOUR_HIGH_LEVEL, HttpClient)

if err != nil {
    //Handle
    return
}

//Getting number of items in category starting with the letter b.
itemCount, err := category.GetItemCountForLetter('b')

if err != nil {
	//Handle
	return
}

//Printing out number of items.
fmt.Println(strconv.FormatInt(itemCount, 10))
Note

Keep in mind Jagex returns very minimal information unfourtunately so not much information is availible from their API. Currently this library does not have any support for the OSBuddy API. If you are looking for a GOOD grand exchange API, use OSBuddy's. It provides much more information than Jagex's.

Documentation

Overview

Go-Runescape is a library for the Runescape API.

The library contains functions to get grandexchange information (RS3 only) and player highscores information (OSRS and RS3). The user is advised to view the IHttpClient interface as it is essential to this package. Extra documentation and examples can be found on the github page.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category []categoryLetterItem

Category is an array containing information on the category. The array is indexed by the alphabet including a hashtag. Indexed as # = 0, a = 1, b = 2, c = 3 ...

func GetCategory

func GetCategory(geConstant string, HttpClient IHttpClient) (Category, error)

GetCategory returns a Category for the passed ge_constant.

func (*Category) GetItemCountForLetter

func (c *Category) GetItemCountForLetter(letter byte) (itemAmount int64, err error)

GetItemCountForLetter returns the amount of items found in the Category starting with a specific character.

type IHttpClient

type IHttpClient interface {
	Get(url string) (*http.Response, error)
}

IHttpUtil is used for all major function calls in the package. An implementing struct should define the Get() method to retrieve the data from the passed url and store the information as a *http.Response. See the github repository for more information.

type ItemDetail

type ItemDetail struct {
	Icon        string              `json:"icon"`
	IconLarge   string              `json:"icon_large"`
	Id          int64               `json:"id"`
	ItemType    string              `json:"type"`
	TypeIconURL string              `json:"typeIcon"`
	Name        string              `json:"name"`
	Description string              `json:"description"`
	Current     timeTrendPrice      `json:"current"`
	Today       timeTrendPrice      `json:"today"`
	Day30       timeTrendPercentage `json:"day30"`
	Day90       timeTrendPercentage `json:"day90"`
	Day180      timeTrendPercentage `json:"day180"`
}

ItemDetail contains information on a item.

func GetItemDetail

func GetItemDetail(itemID int64, HttpClient IHttpClient) (ItemDetail, error)

Gets grandexchage information from the passed item. If the passed item id is invalid a json error will occur and be passed back.

type ItemJson

type ItemJson struct {
	Item ItemDetail `json:"item"`
}

ItemJson defines the json object returned by jagex when requesting for item information.

type Items

type Items struct {
	Icon        string     `json:"icon"`
	IconLarge   string     `json:"icon_lrage"`
	Id          int        `json:"id"`
	Type        string     `json:"type"`
	TypeIcon    string     `json:"typeIcon"`
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Current     TrendPrice `json:"current"`
	Today       TrendPrice `json:"today"`
	Members     string     `json:"members"`
}

Information about item.

type ItemsCatalogue

type ItemsCatalogue struct {
	Items []Items `json:"items"`
	Total int     `json:"total"`
}

Information on an grandexchange category.

func GetItemsCatalogue

func GetItemsCatalogue(geConstant string, letter byte, pageNo int, HttpClient IHttpClient) (c ItemsCatalogue, err error)

Gets information on the passed grandexchange category. It is advised that the user uses the ge_constants package to choose a grandexchange category. Only items starting with the passed letter will be returned. pageNo is the page number of the grandexchange catalogue to return for that category & letter.

type PlayerHighscores

type PlayerHighscores struct {
	Levels []int64
	XP     []int64
	Ranks  []int64
}

This will store the highscore_constants information of a player. The skill indexes can be found in the highscore_constants package. For example Levels[highscore_constants.MINING] would give the mining level of the player.

func GetPlayerHighscores

func GetPlayerHighscores(playerName string, highscoreType string, httpClient IHttpClient) (rsph PlayerHighscores, err error)

GetPlayerHighscores gets a players highscores information. The highscoreType is the type of scoreboard to search. Acceptable values are stored as constants in the highscore_constants package. These constants are:

highscore_constants.RS3PLAYER

highscore_constants.RS3IRONMAN

highscore_constants.RS3HARDCOREIRONMAN

highscore_constants.OSRSPLAYER

highscore_constants.OSRSIRONMAN

highscore_constants.OSRSULTIMATEIRONMAN

type Rank

type Rank struct {
	Name  string `json:"name"`
	Score string `json:"score"`
	Rank  string `json:"rank"`
}

Contains the list of ranked players on the highscores.

func GetRankings

func GetRankings(skill int64, category int64, amountOfPlayers int64, HttpClient IHttpClient) (rankings []Rank, err error)

GetRankings gets the rankings for a passed skill. The user is advised to use the highscore_constants package to specify the skill.

type TrendPrice

type TrendPrice struct {
	Trend string      `json:"trend"`
	Price interface{} `json:"price"`
}

Information on the current price trend.

Directories

Path Synopsis
Contains constants useful as parameters to functions interacting with the grandexchange api.
Contains constants useful as parameters to functions interacting with the grandexchange api.
Contains constants useful as parameters to functions which interact with the highscores api.
Contains constants useful as parameters to functions which interact with the highscores api.

Jump to

Keyboard shortcuts

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