community

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

README

go-dualuniverse-api

go-dualuniverse-api is a small library to gather the raw data of the Dual Universe organizations. In fact, this library simply automizes a few requests which are needed to access the AJAX api for the Dual Universe organizations.

Installation

go get gitlab.eisengrind.de/eiengrind/dual-universe/go-dualuniverse-api@latest

Usage

package main

import (
    "context"
    "fmt"
    api "gitlab.eisengrind.de/eiengrind/dual-universe/go-dualuniverse-api"
)

func main() {
    orgs, err := api.Organizations.GetOrganizations(context.Background(), 0, 100)
    if err != nil {
        log.Fatal(err)
    }

    ...
}

This project is an inofficial library to interact with the Dual Universe organization API. The project is not affiliated with NOVAQUARK.

Documentation

Index

Constants

View Source
const (
	// SortByName sorts the organizations by their name
	SortByName = iota
	// SortByCreatedAt sorts the organizations by their creation date
	SortByCreatedAt = iota
	// SortByPlayerCount sorts the organizations by their player count
	SortByPlayerCount = iota
)
View Source
const (
	// OrderDescending orders the organizations descending by their sort filter
	OrderDescending = 0
	// OrderAscending orders the organizations ascending by their sort filter
	OrderAscending = 1
)

Variables

View Source
var ErrInternalServerError = errors.New("internal server error")

ErrInternalServerError is thrown if the Dual Universe servers return an internal server error

Functions

This section is empty.

Types

type AuthenticatedClient added in v1.0.1

type AuthenticatedClient interface {
	Client
	User(ctx context.Context, id uint) (*User, error)

	Close() error
	Wait()
}

AuthenticatedClient extends the Client interface with methods to fetch information that requires authentication

func NewAuthenticatedClient added in v1.0.1

func NewAuthenticatedClient(httpClient *http.Client, initSessionID string) AuthenticatedClient

NewAuthenticatedClient creates a new instance of an authenticated client.

type Client added in v1.0.1

type Client interface {
	// Organizations returns all Dual Universe organizations
	Organizations(ctx context.Context, start, length, sort, order int) (*OrganizationsResp, error)

	// OrganizationMembers returns all members of a given organization
	OrganizationMembers(ctx context.Context, id string, start, length int) (*OrganizationMembersResp, error)

	// OrganizationExtraDescription returns the descriptions
	// provided on the organizations page
	OrganizationExtraDescription(ctx context.Context, id string) (*OrganizationDescription, error)
}

Client provides methods to fetch information from the Dual Universe Community page without authentication

func NewClient added in v1.0.1

func NewClient(httpClient *http.Client) Client

NewClient creates a new instance of an unauthenticated client.

type Organization added in v1.0.1

type Organization struct {
	ID           int               `json:"id"`
	OwnerID      int               `json:"ownerId"`
	Active       bool              `json:"active"`
	Posts        []interface{}     `json:"posts"`
	Description  string            `json:"description"`
	Keywords     string            `json:"keywords"`
	Language     string            `json:"language"`
	Manifest     string            `json:"manifest"`
	Name         string            `json:"name"`
	IsRecruiting bool              `json:"recruiting"`
	Tag          string            `json:"tag"`
	CreatedAt    string            `json:"createdAt"`
	MemberCount  int               `json:"memberCount"`
	// contains filtered or unexported fields
}

func (*Organization) ExtractCreated added in v1.0.1

func (o *Organization) ExtractCreated() (time.Time, error)

ExtractCreated extracts the created timestamp

func (*Organization) ExtractID added in v1.0.1

func (o *Organization) ExtractID() (string, error)

ExtractID extracts the identifier of the organization the html tag

func (*Organization) ExtractKeywords added in v1.0.1

func (o *Organization) ExtractKeywords() []string

ExtractKeywords extracts the keywords of the organization

func (*Organization) ExtractLogoURL added in v1.0.1

func (o *Organization) ExtractLogoURL() (string, error)

ExtractLogoURL extracts the logo url from the html tag

func (*Organization) ExtractName added in v1.0.1

func (o *Organization) ExtractName() (string, error)

ExtractName extracts the name from the html tag

type OrganizationDescription added in v1.0.1

type OrganizationDescription struct {
	ShortDescription string `json:"short_description"`
	LongDescription  string `json:"long_description"`
}

OrganizationDescription represents information shown on the organization's overview page

type OrganizationDescriptionResp added in v1.0.1

type OrganizationDescriptionResp struct{}
type OrganizationLogo struct {
	Content string `json:"content"`
	IsSVG   bool   `json:"svg"`
}

type OrganizationMember added in v1.0.1

type OrganizationMember struct {
	MemberID    int    `json:"memberId"`
	UserID      int    `json:"userId"`
	PlayerID    int    `json:"playerId"`
	DisplayName string `json:"displayName"`
	Role        string `json:"role"`
	JoinedAt    string `json:"joinedAt"`
	Avatar      string `json:"avatar"`
}

func (*OrganizationMember) ExtractAvatarURL added in v1.0.1

func (m *OrganizationMember) ExtractAvatarURL() (string, error)

ExtractAvatarURL extracts the avatar URL from the logo html tag

func (*OrganizationMember) ExtractDisplayName added in v1.0.1

func (m *OrganizationMember) ExtractDisplayName() (string, error)

ExtractDisplayName extracts the display name of a org member

func (*OrganizationMember) ExtractJoinedAt added in v1.0.1

func (m *OrganizationMember) ExtractJoinedAt() (time.Time, error)

ExtractJoinedAt extracts the joined at date

func (*OrganizationMember) ExtractRank added in v1.0.1

func (m *OrganizationMember) ExtractRank() (string, error)

ExtractRank extracts the rank from the rank html tag

type OrganizationMembersResp added in v1.0.1

type OrganizationMembersResp struct {
	Draw            int                   `json:"draw"`
	RecordsTotal    int                   `json:"recordsTotal"`
	RecordsFiltered int                   `json:"recordsFiltered"`
	Data            []*OrganizationMember `json:"data"`
}

type OrganizationParser added in v1.0.1

type OrganizationParser struct {
	Document *goquery.Document
}

OrganizationParser is used to parse the organization's overview page for information provided there

func (*OrganizationParser) Parse added in v1.0.1

Parse parses all overview information provided on the Dual Universe page

type OrganizationsResp added in v1.0.1

type OrganizationsResp struct {
	Draw            int             `json:"draw"`
	RecordsTotal    int             `json:"recordsTotal"`
	RecordsFiltered int             `json:"recordsFiltered"`
	Data            []*Organization `json:"data"`
}

type User added in v1.0.1

type User struct {
	ID           uint      `json:"id"`
	Name         string    `json:"name"`
	Status       *string   `json:"status"`
	AboutMe      string    `json:"about_me"`
	Location     *string   `json:"location"`
	JoinedAt     time.Time `json:"joined_at"`
	AvatarURL    string    `json:"avatar_url"`
	TwitterName  *string   `json:"twitter_url"`
	FacebookName *string   `json:"facebook_url"`
}

User represents a dual universe user profile

Directories

Path Synopsis
community module
test

Jump to

Keyboard shortcuts

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