rosbotcollector

package module
v0.0.0-...-3acda51 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

🤖 Go-Rosbot-Collector

Scrapes Ros-Bot's user activity page, and returns the parsed server updates.

Table of Contents


Usage

New Client
type Client interface {
    // ParseWithDefaults returns a slice of Ros-Bot server updates based on the default parsing
    // configuration.
    ParseWithDefaults(ctx context.Context) ([]*ServerUpdate, error)
    // ParseWithConfig returns a slice of Ros-Bot server updates based on the provided
    // parsing configuration.
    ParseWithConfig(ctx context.Context, config *ParserConfig) ([]*ServerUpdate, error)
}
rbc, err := rosbotcollector.NewClient("your-username", "password")
if err != nil {
	...
}
Parsing
type ParserConfig struct {
  Destinations []Destination
  RarityLevel  Rarity
  Quality      Quality 
  Page         int8
}
c := rosbotcollector.NewParseConfig()

                OR

c := rosbotcollector.ParseConfig{
	...
}
Defaults

Uses the de-facto configuration.

ParserConfig{
    Destinations: []Destination{},
    RarityLevel:  RarityNonAncient,
    Quality:      QualityAll,
    Page:         1,
}
u, err := rbc.ParseWithDefaults(ctx)
if err != nil {
	...
}
Custom

Uses a custom configuration object.

c := rosbotcollector.NewParseConfig()

                OR

c := rosbotcollector.ParseConfig{...}
u, err := rbc.ParseWithConfig(ctx, &c)
if err != nil {
	...
}
Errors

ErrBadCredentials is returned when the login attempt has failed.

ErrNoFormBuildID is returned when form_build_id could not be parsed from response body.

ErrNoActivityEndpoint is returned when the activity endpoint could not be parsed from response body.

ErrCookiesRefresh is returned when the attempt to refresh user cookies has failed.

Types

Server Update

Corresponds to a Ros-Bot server update.

type ServerUpdate struct {
    Items           []*LegendaryItem `json:"legendaries"`
    ServerTimestamp time.Time        `json:"server_timestamp"`
}
Legendary Item

Corresponds to an in-game item of "legendary" quality.

type LegendaryItem struct {
  Name         string
  IsIdentified bool
  Quality      Quality 
  Rarity       Rarity
  Destination  Destination
  Stats        string
}
Quality
QualityAll    Quality = "*"
QualityNormal Quality = "NORMAL"
QualitySet    Quality = "SET"
Rarity
RarityPrimal     Rarity = "PRIMAL"
RarityAncient    Rarity = "ANCIENT"
RarityNonAncient Rarity = "NON-ANCIENT"
Destination
DestinationStashed  Destination = "STASHED"
DestinationSalvaged Destination = "SALVAGED"
DestinationSold     Destination = "SOLD"

Contributions

  • Improve item property parsing (=? weapon, armour, ring, etc).

  • Improve item stat. parsing (base, primary, secondary, power, sockets)

  • Expand parsing to include items of all qualities.

License

Apache License

Maximilien Zaleski © 2019

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadCredentials is returned when the login attempt has failed.
	ErrBadCredentials = errors.New("provided user credentials are invalid")
	// ErrNoFormBuildID is returned when 'form_build_id' could not be parsed from response body.
	ErrNoFormBuildID = errors.New("could not parse 'form_build_id' from response body")
	// ErrNoActivityEndpoint is returned when the activity endpoint could not be parsed from
	// response body.
	ErrNoActivityEndpoint = errors.New("could not parse bot activity endpoint from response body")
	// ErrCookiesRefresh is returned when the attempt to refresh user cookies has failed.
	ErrCookiesRefresh = errors.New("error refreshing cookies")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// ParseWithDefaults returns a slice of Ros-Bot server updates based on the default parsing
	// configuration.
	ParseWithDefaults(ctx context.Context) ([]*ServerUpdate, error)
	// ParseWithConfig returns a slice of Ros-Bot server updates based on the provided
	// parsing configuration.
	ParseWithConfig(ctx context.Context, config *ParserConfig) ([]*ServerUpdate, error)
}

func NewClient

func NewClient(usernameOrEmail string, password string) (Client, error)

NewClient a instance of the `rosbotcollector.Client` interface.

type Destination

type Destination string

Destination is where the bot placed the item upon collection of it.

const (
	DestinationStashed  Destination = "STASHED"
	DestinationSalvaged Destination = "SALVAGED"
	DestinationSold     Destination = "SOLD"
	DestinationUnknown  Destination = "UNKNOWN"
)

type HTTPService

type HTTPService interface {
	// Authenticate posts the user credentials, and places the resulting cookies in a jar.
	Authenticate() (HTTPService, error)
	// GetActivity retrieves the page body of 'user/{user_id}/bot-activity'.
	GetActivity(searchSegment string) (io.ReadCloser, error)
}

HTTPService handles all the requests made to 'https://www.ros-bot.com'.

type LegendaryItem

type LegendaryItem struct {
	Name         string      `json:"name"`
	Quality      Quality     `json:"type"`
	Rarity       Rarity      `json:"rarity"`
	Destination  Destination `json:"destination"`
	IsIdentified bool        `json:"is_identified"`
	Stats        string      `json:"stats"`
}

LegendaryItem is a Diablo III legendary item.

type Parser

type Parser interface {
	// Parse parses server updates from the '/bot-activity' page.
	Parse(ctx context.Context) ([]*ServerUpdate, error)
}

type ParserConfig

type ParserConfig struct {
	Destinations []Destination
	RarityLevel  Rarity
	Quality      Quality
	Page         int8
}

ParserConfig is the parsing configuration

func NewParseConfig

func NewParseConfig() *ParserConfig

NewParseConfig returns a new instance of `rosbotcollector.ParserConfig` with the default values.

type Quality

type Quality string

Quality is the item's quality.

const (
	QualityAll    Quality = "*"
	QualityNormal Quality = "NORMAL"
	QualitySet    Quality = "SET"
)

type Rarity

type Rarity string

Rarity is the item's rarity.

const (
	RarityPrimal     Rarity = "PRIMAL"
	RarityAncient    Rarity = "ANCIENT"
	RarityNonAncient Rarity = "NON-ANCIENT"
)

type ServerUpdate

type ServerUpdate struct {
	Items           []*LegendaryItem `json:"legendaries"`
	ServerTimestamp time.Time        `json:"server_timestamp"`
}

ServerUpdate is a Ros-Bot server update.

Jump to

Keyboard shortcuts

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