spiget

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have response body, and a JSON response body that maps to ErrorResponse.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func Stringify

func Stringify(message interface{}) string

Stringify attempts to create a reasonable string representation of types in the GitHub library. It does things like resolve pointers to their values and omits struct fields with nil values.

Types

type Author

type Author struct {
	ID         int               `json:"id,omitempty"`
	Name       string            `json:"name,omitempty"`
	Icon       Icon              `json:"icon,omitempty"`
	Identities map[string]string // may not be present
}

Author represents a Spiget author.

func (*Author) String

func (a *Author) String() string

type AuthorListOptions

type AuthorListOptions struct {
	ListOptions
}

AuthorListOptions specifies the optional parameters to the AuthorsService.List method.

type AuthorSearchOptions

type AuthorSearchOptions struct {
	Field string `url:"field,omitempty"`

	ListOptions
}

AuthorSearchOptions specifies the optional parameters to the AuthorsService.Search method.

type AuthorsService

type AuthorsService service

AuthorsService handles communication with the author related methods of the Spiget API.

Spiget API docs: https://spiget.org/documentation/#!/authors/get_authors

func (*AuthorsService) Get

func (a *AuthorsService) Get(ctx context.Context, id int) (*Author, *Response, error)

Get fetches a author.

Spiget API docs: https://spiget.org/documentation/#!/authors/get_authors_author

func (*AuthorsService) List

func (a *AuthorsService) List(ctx context.Context, opts *AuthorListOptions) ([]*Author, *Response, error)

Get a list of available authors. Note: This only includes members involved with resources, either being their author or having reviewed a resource.

Spiget API docs: https://spiget.org/documentation/#!/authors/get_authors

func (*AuthorsService) Search

func (a *AuthorsService) Search(ctx context.Context, query string, opts *AuthorSearchOptions) ([]*Author, *Response, error)

Search searches for authors by specified field.

Spiget API docs: https://spiget.org/documentation/#!/authors/get_search_authors_query

type CategoriesService

type CategoriesService service

AuthorsService handles communication with the category related methods of the Spiget API.

Spiget API docs: https://spiget.org/documentation/#!/categories/get_categories

func (*CategoriesService) Get

func (c *CategoriesService) Get(ctx context.Context, id int) (*Category, *Response, error)

Get details about a category

Spiget API docs: https://spiget.org/documentation/#!/categories/get_categories_category

func (*CategoriesService) List

Get a list of categories.

Spiget API docs: https://spiget.org/documentation/#!/categories/get_categories

type Category

type Category struct {
	ID   int    `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

Category represents a Spiget category.

func (*Category) String

func (c *Category) String() string

type CategoryListOptions

type CategoryListOptions struct {
	ListOptions
}

CategoryListOptions specifies the optional parameters to the CategoriesService.List method.

type Client

type Client struct {

	// Base URL for API requests. Defaults to the official Spiget API, but can be
	// set to a domain endpoint to use with your self-hosted instance. BaseURL
	// should always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the GitHub API.
	UserAgent string

	// Services used for talking to different parts of the GitHub API.
	Authors    *AuthorsService
	Categories *CategoriesService
	Resources  *ResourcesService
	Search     *SearchService
	Status     *StatusService
	Webhook    *WebhookService
	// contains filtered or unexported fields
}

Client manages communication with the Spiget API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Spiget API client. If a nil httpClient is provided, a new http.Client will be used.

func NewCustomClient

func NewCustomClient(baseURL string, httpClient *http.Client) (*Client, error)

NewCustomClient returns a new Spiget API client with provided base URL. If a nil httpClient is provided, a new http.Client will be used.

func (*Client) BareDo

func (c *Client) BareDo(ctx context.Context, req *http.Request) (*Response, error)

BareDo sends an API request and lets you handle the api response. If an error or API Error occurs, the error will contain more information. Otherwise you are supposed to read and close the response's Body.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) Client

func (c *Client) Client() *http.Client

Client returns the http client used to make requests.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil, and no error hapens, the response is returned as is.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type Error

type Error struct {
	Resource string `json:"resource"` // resource on which the error occurred
	Field    string `json:"field"`    // field on which the error occurred
	Code     string `json:"code"`     // validation error code
	Message  string `json:"message"`  // Message describing the error. Errors with Code == "custom" will always have this set.
}

An Error reports more details on an individual error in an ErrorResponse. These are the possible validation error codes:

missing:
    resource does not exist
missing_field:
    a required field on a resource has not been set
invalid:
    the formatting of a field is invalid
already_exists:
    another resource has the same valid as this field
custom:
    some resources return this (e.g. github.User.CreateKey()), additional
    information is set in the Message field of the Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(data []byte) error

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Message  string         `json:"message"` // error message
	Errors   []Error        `json:"errors"`  // more detail on individual errors
}

ErrorResponse reports one or more errors caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

func (*ErrorResponse) Is

func (r *ErrorResponse) Is(target error) bool

Is returns whether the provided error equals this error.

type File

type File struct {
	Type        string  `json:"type,omitempty"`
	URL         string  `json:"url,omitempty"`
	Size        float64 `json:"size,omitempty"`
	SizeUnit    string  `json:"sizeUnit,omitempty"`
	ExternalUrl string  `json:"externalUrl,omitempty"`
}

File represents a file.

type Icon

type Icon struct {
	URL  string `json:"url,omitempty"`
	Data string `json:"data,omitempty"`
	Info string `json:"info,omitempty"`
	Hash string `json:"hash,omitempty"`
}

Icon represents a icon, usually user avatar.

type ListOptions

type ListOptions struct {

	// Size of the returned array.
	Size int `url:"size,omitempty"`

	// Page index.
	Page int `url:"page,omitempty"`

	// Field to sort by.
	Sort string `url:"sort,omitempty"`

	// Order of the field to sort by. (asc or desc)
	Order string `url:"order,omitempty"`

	// Fields to return.
	Fields []string `url:"fields,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support offset pagination.

type Rating

type Rating struct {
	Count   int     `json:"count,omitempty"`
	Average float64 `json:"average,omitempty"`
}

Rating represents a rating.

type Resource

type Resource struct {
	ID             int               `json:"id,omitempty"`
	Name           string            `json:"name,omitempty"`
	Tag            string            `json:"tag,omitempty"`
	Contributors   string            `json:"contributors,omitempty"`
	Likes          int               `json:"likes,omitempty"`
	File           File              `json:"file,omitempty"`
	TestedVersions []string          `json:"testedVersions,omitempty"`
	Links          map[string]string `json:"links,omitempty"`
	Rating         Rating            `json:"rating,omitempty"`
	ReleaseDate    int               `json:"releaseDate,omitempty"`
	UpdateDate     int               `json:"updateDate,omitempty"`
	Downloads      int               `json:"downloads,omitempty"`
	External       bool              `json:"external,omitempty"`
	Icon           Icon              `json:"icon,omitempty"`
	Premium        bool              `json:"premium,omitempty"`
	Price          float64           `json:"price,omitempty"`
	Currency       string            `json:"currency,omitempty"`
	Author         Author            `json:"author,omitempty"`
	Category       Category          `json:"category,omitempty"`
	Version        Version           `json:"version,omitempty"`
	Versions       []Version         `json:"versions,omitempty"`
	Updates        []Update          `json:"updates,omitempty"`
	SourceCodeLink string            `json:"sourceCodeLink,omitempty"`
	DonationLink   string            `json:"donationLink,omitempty"`
}

Resource represents a resource.

func (*Resource) String

func (r *Resource) String() string

type ResourceListByVersionsOptions

type ResourceListByVersionsOptions struct {
	Method string `url:"method,omitempty"`

	ListOptions
}

ResourceListOptions specifies the optional parameters to the ResourcesService.ListByVersions method.

type ResourceListOptions

type ResourceListOptions struct {
	ListOptions
}

ResourceListOptions specifies the optional parameters to the ResourcesService.List method.

type ResourceSearchOptions

type ResourceSearchOptions struct {
	Field string `url:"field,omitempty"`

	ListOptions
}

ResourceSearchOptions specifies the optional parameters to the ResourcesService.Search method.

type ResourcesService

type ResourcesService service

ResourcesService handles communication with the resource related methods of the Spiget API.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources

func (*ResourcesService) Download

func (r *ResourcesService) Download(ctx context.Context, id int) (*Response, error)

Download a resource.

This either redirects to spiget's CDN server (cdn.spiget.org) for a direct download of files hosted on spigotmc.org or to the URL of externally hosted resources The external field of a resource should be checked before downloading, to not receive any unexpected data.

func (*ResourcesService) DownloadVersion

func (r *ResourcesService) DownloadVersion(ctx context.Context, id int, version int) (*Response, error)

Download a specific resource version.

Note: This only redirects to the stored download location and might not download a file (i.e. for external resources).

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_versions_version_download

func (*ResourcesService) Get

func (r *ResourcesService) Get(ctx context.Context, id int) (*Resource, *Response, error)

Get a resource by its ID.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource

func (*ResourcesService) GetAuthor

func (r *ResourcesService) GetAuthor(ctx context.Context, id int) (*Author, *Response, error)

Get the resource author.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_author

func (*ResourcesService) GetLatestUpdate

func (r *ResourcesService) GetLatestUpdate(ctx context.Context, id int) (*Update, *Response, error)

Get the latest resource update

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_updates_latest

func (*ResourcesService) GetLatestVersion

func (r *ResourcesService) GetLatestVersion(ctx context.Context, id int) (*Version, *Response, error)

Get the latest resource version.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_versions_latest

func (*ResourcesService) GetReviews

func (r *ResourcesService) GetReviews(ctx context.Context, id int, opts ListOptions) ([]*Review, *Response, error)

Get reviews of a resource.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_reviews

func (*ResourcesService) GetUpdates

func (r *ResourcesService) GetUpdates(ctx context.Context, id int, opts ListOptions) ([]*Update, *Response, error)

Get updates of a resource.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_updates

func (*ResourcesService) GetVersion

func (r *ResourcesService) GetVersion(ctx context.Context, id int, version int) (*Version, *Response, error)

Get a specific resource version by its ID.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_versions_version

func (*ResourcesService) GetVersions

func (r *ResourcesService) GetVersions(ctx context.Context, id int, opts ListOptions) ([]*Version, *Response, error)

Get versions of a resource.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_resource_versions

func (*ResourcesService) List

Get a list of available resources (premium and free).

func (*ResourcesService) ListByVersions

func (r *ResourcesService) ListByVersions(ctx context.Context, versions []string, opts ResourceListByVersionsOptions) ([]*Resource, *Response, error)

Get resources for the specified version(s).

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_for_version

func (*ResourcesService) ListFree

func (r *ResourcesService) ListFree(ctx context.Context, opts *ResourceListOptions) ([]*Resource, *Response, error)

Get a list of available free resources.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_free

func (*ResourcesService) ListNew

Get all new resources.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_new

func (*ResourcesService) ListPremium

func (r *ResourcesService) ListPremium(ctx context.Context, opts *ResourceListOptions) ([]*Resource, *Response, error)

Get a list of available premium resources.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_resources_premium

func (*ResourcesService) Search

func (r *ResourcesService) Search(ctx context.Context, query string, opts *ResourceSearchOptions) ([]*Resource, *Response, error)

Search resources.

Spiget API docs: https://spiget.org/documentation/#!/resources/get_search_resources_query

type Response

type Response struct {
	*http.Response

	// These fields provide the page values for paginating through a set of
	// results. Any or all of these may be set to the zero value for
	// responses that are not part of a paginated set, or for which there
	// are no additional pages.
	//
	// These fields support what is called "offset pagination" and should
	// be used with the ListOptions struct.
	NextPage  int
	PrevPage  int
	FirstPage int
	LastPage  int
}

Response is a Spiget API response. This wraps the standard http.Response returned from Spiget and provides convenient access to things like pagination links.

type Review

type Review struct {
	ID       int    `json:"id,omitempty"`
	Resource int    `json:"resource,omitempty"`
	Author   Author `json:"author,omitempty"`
	Rating   Rating `json:"rating,omitempty"`
	Message  string `json:"message,omitempty"`
	Version  string `json:"version,omitempty"`
	Date     int    `json:"date,omitempty"`
}

Review represents a review.

type SearchService

type SearchService service

func (*SearchService) SearchAuthor

func (s *SearchService) SearchAuthor(ctx context.Context, query string, opts *AuthorSearchOptions) ([]*Author, *Response, error)

Search authors.

Note: This is actually an alias for the AuthorsService.Search method.

func (*SearchService) SearchResource

func (s *SearchService) SearchResource(ctx context.Context, query string, opts *ResourceSearchOptions) ([]*Resource, *Response, error)

Search resources.

Note: This is actually an alias for the ResourcesService.Search method.

type Stats

type Stats struct {
	Resources        int `json:"resources"`
	Authors          int `json:"authors"`
	Categories       int `json:"categories"`
	ResourceUpdates  int `json:"resource_updates"`
	ResourceVersions int `json:"resource_versions"`
	Reviews          int `json:"reviews"`
}

type Status

type Status struct {
	Server struct {
		Name string `json:"name"`
		Mode string `json:"mode"`
	} `json:"server"`

	Fetch struct {
		Start       int64  `json:"start"`
		StartString string `json:"startString"`
		End         int64  `json:"end"`
		Active      bool   `json:"active"`
		Page        struct {
			Amount int `json:"amount"`
			Index  int `json:"index"`
			Item   struct {
				Index  int    `json:"index"`
				Status string `json:"status"`
			} `json:"item"`
		} `json:"page"`
	} `json:"fetch"`

	RestFetch struct {
		Start       int64  `json:"start"`
		StartString string `json:"startString"`
		End         int64  `json:"end"`
		Active      bool   `json:"active"`
		N           struct {
			Num   int `json:"num"`
			Start int `json:"start"`
			End   int `json:"end"`
			Max   int `json:"max"`
			Index int `json:"index"`
		} `json:"n"`
	} `json:"restFetch"`

	Existence struct {
		Start       int64  `json:"start"`
		StartString string `json:"startString"`
		End         int64  `json:"end"`
		Active      bool   `json:"active"`
		Document    struct {
			Amount   int `json:"amount"`
			Suspects int `json:"suspects"`
			Index    int `json:"index"`
			ID       int `json:"id"`
		} `json:"document"`
	} `json:"existence"`
}

type StatusResponse

type StatusResponse struct {
	Status *Status `json:"status"`
	Stats  *Stats  `json:"stats"`
}

func (*StatusResponse) String

func (sr *StatusResponse) String() string

type StatusService

type StatusService service

func (*StatusService) Get

Get the API status

Spiget API docs: https://spiget.org/documentation/#!/status/get_status

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. This is necessary for some fields since the GitHub API is inconsistent in how it represents times. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type Update

type Update struct {
	ID          int    `json:"id,omitempty"`
	Resource    int    `json:"resource,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Date        int    `json:"date,omitempty"`
	Likes       int    `json:"likes,omitempty"`
}

Update represents an update.

type Version

type Version struct {
	ID   int    `json:"id,omitempty"`
	UUID string `json:"uuid,omitempty"`
}

Version represents a version.

type Webhook

type Webhook struct {
	ID     string `json:"id,omitempty"`
	Secret string `json:"secret,omitempty"`
}

type WebhookEvents

type WebhookEvents struct {
	Events []string `json:"events"`
}

type WebhookService

type WebhookService service

func (*WebhookService) Delete

func (w *WebhookService) Delete(ctx context.Context, webhook Webhook) (*Response, error)

Delete a Webhook.

Spiget API docs: https://spiget.org/documentation/#!/webhook/delete_webhook_delete_id_secret

func (*WebhookService) GetEvents

func (w *WebhookService) GetEvents(ctx context.Context) (*WebhookEvents, *Response, error)

Get a list of available events.

Spiget API docs: https://spiget.org/documentation/#!/webhook/get_webhook_events

func (*WebhookService) GetStatus

func (w *WebhookService) GetStatus(ctx context.Context, id string) (*WebhookStatus, *Response, error)

Get the status of a Webhook.

Spiget API docs: https://spiget.org/documentation/#!/webhook/get_webhook_status_id

func (*WebhookService) Register

func (w *WebhookService) Register(ctx context.Context, callbackUrl string, events []string) (*Webhook, *Response, error)

Register a new Webhook.

Spiget API docs: https://spiget.org/documentation/#!/webhook/post_webhook_register

type WebhookStatus

type WebhookStatus struct {
	Status            int `json:"status"`
	FailedConnections int `json:"failedConnections"`
}

Jump to

Keyboard shortcuts

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