moonapi

package module
v0.0.0-...-8a749d3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: MIT Imports: 12 Imported by: 0

README

Moon API

An API for the MoonBoard website, allowing access to problems.

In the future it will allow creating of problems and accessing user information.

Usage
	// Create a new session:
	var session = MoonBoard{}
	
	// Login - auth response will be stored as part of the session
	err := session.Login("Username", "Password")
	
	// Create a query using the builder
	builder := query.New()
	query, _ := builder.Filter(query.Benchmarks).MinGrade(query.SixAPlus).Build()
	
	// Use the session and query to return a slice of Problems
	problems, err := moonBoardSession.GetProblems(query)	
Cli Usage

Build the command line tool using:

	go build .\cmd\cli\main.go

Then run it using the following, to list the options use the --help flag

	.\main.go --help

Example:

	.\main.go -login -user username -pass password -hs os,a,b -f Benchmarks
Testing

To run unit tests use the following command from the root directory, it will run all tests:

	go test ./...
Documentation

Run godoc:

	godoc -http=":<port>"

Then visit localhost: and you can navigate to the docs for the package

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProblemsAsJSON

func ProblemsAsJSON(problems []Problem) (string, error)

ProblemsAsJSON takes an array of Problem and returns the JSON representation of those problems. Errors are returned if it fails to marshal the object.

Types

type AuthToken

type AuthToken struct {
	Name  string
	Value string
}

AuthToken contains the values of the cookie required to be used as authentication against the website.

type HoldSetup

type HoldSetup struct {
	ID                      int         `json:"Id"`
	Description             string      `json:"Description"`
	Setby                   interface{} `json:"Setby"`
	DateInserted            interface{} `json:"DateInserted"`
	DateUpdated             interface{} `json:"DateUpdated"`
	DateDeleted             interface{} `json:"DateDeleted"`
	IsLocked                bool        `json:"IsLocked"`
	Holdsets                interface{} `json:"Holdsets"`
	MoonBoardConfigurations interface{} `json:"MoonBoardConfigurations"`
	HoldLayoutID            int         `json:"HoldLayoutId"`
	AllowClimbMethods       bool        `json:"AllowClimbMethods"`
}

type MbResponse

type MbResponse struct {
	Data             []Problem   `json:"Data"`
	Total            int         `json:"Total"`
	AggregateResults interface{} `json:"AggregateResults"`
	Errors           interface{} `json:"Errors"`
}

type MoonBoard

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

MoonBoard contains all the AuthTokens (cookies) required

func (MoonBoard) Auth

func (m MoonBoard) Auth() []AuthToken

func (MoonBoard) GetProblems

func (m MoonBoard) GetProblems(query Query) (MbResponse, error)

GetProblems can be called on a session object to return all problems that match the provided critieria from the Query passed in. It requires the session to provide the _MoonBoard and __RequestVerificationToken AuthToken errors are retuned if these are missing or the session has expired.

func (MoonBoard) Login

func (m MoonBoard) Login(username string, password string) error

Login takes a username and password, then attempts to use these to enter into the website's login form and submit it, storing the resulting cookies as AuthTokens

func (MoonBoard) SetAuth

func (m MoonBoard) SetAuth(authTokens []AuthToken)

type MoonBoardApi

type MoonBoardApi interface {
	Login(username string, password string) error
	GetProblems(query Query) (MbResponse, error)
	Auth() []AuthToken
	SetAuth(authTokens []AuthToken)
}

MoonBoardApi provides methods for interacting with the website

type MoonBoardConfiguration

type MoonBoardConfiguration struct {
	ID          int         `json:"Id"`
	Description string      `json:"Description"`
	LowGrade    interface{} `json:"LowGrade"`
	HighGrade   interface{} `json:"HighGrade"`
}

type Problem

type Problem struct {
	Method                   string                 `json:"Method"`
	Name                     string                 `json:"Name"`
	Grade                    string                 `json:"Grade"`
	UserGrade                interface{}            `json:"UserGrade"`
	MoonBoardConfiguration   MoonBoardConfiguration `json:"MoonBoardConfiguration"`
	MoonBoardConfigurationID int                    `json:"MoonBoardConfigurationId"`
	Setter                   Setter                 `json:"Setter"`
	FirstAscender            bool                   `json:"FirstAscender"`
	Rating                   int                    `json:"Rating"`
	UserRating               int                    `json:"UserRating"`
	Repeats                  int                    `json:"Repeats"`
	Attempts                 int                    `json:"Attempts"`
	Holdsetup                HoldSetup              `json:"Holdsetup"`
	IsBenchmark              bool                   `json:"IsBenchmark"`
	Moves                    []struct {
		ID          int    `json:"Id"`
		Description string `json:"Description"`
		IsStart     bool   `json:"IsStart"`
		IsEnd       bool   `json:"IsEnd"`
	} `json:"Moves"`
	Holdsets  interface{} `json:"Holdsets"`
	Locations []struct {
		ID              int         `json:"Id"`
		Holdset         interface{} `json:"Holdset"`
		Description     interface{} `json:"Description"`
		X               int         `json:"X"`
		Y               int         `json:"Y"`
		Color           string      `json:"Color"`
		Rotation        int         `json:"Rotation"`
		Type            int         `json:"Type"`
		HoldNumber      interface{} `json:"HoldNumber"`
		Direction       int         `json:"Direction"`
		DirectionString string      `json:"DirectionString"`
	} `json:"Locations"`
	RepeatText     string      `json:"RepeatText"`
	NumberOfTries  interface{} `json:"NumberOfTries"`
	NameForURL     string      `json:"NameForUrl"`
	ID             int         `json:"Id"`
	APIID          int         `json:"ApiId"`
	DateInserted   string      `json:"DateInserted"`
	DateUpdated    interface{} `json:"DateUpdated"`
	DateDeleted    interface{} `json:"DateDeleted"`
	DateTimeString string      `json:"DateTimeString"`
}

type Setter

type Setter struct {
	ID              string `json:"Id"`
	Nickname        string `json:"Nickname"`
	Firstname       string `json:"Firstname"`
	Lastname        string `json:"Lastname"`
	City            string `json:"City"`
	Country         string `json:"Country"`
	ProfileImageURL string `json:"ProfileImageUrl"`
	CanShareData    bool   `json:"CanShareData"`
}

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

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