marvel

package
v0.1.4-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	CharacterEndpoint string // Define the character endpoint. maybe remove and find more elegant solution for testing.
	// contains filtered or unexported fields
}

API defines the client for connecting to the Marvel API.

func NewMarvelAPI

func NewMarvelAPI(client *http.Client) *API

NewMarvelAPI creates the new client with the http client.

func (*API) Characters

func (api *API) Characters(criteria *Criteria) (*CharactersResultWrapper, *ErrorResult, error)

Characters returns the API response for getting characters, an error from the API result, or a system-related error.

func (*API) TotalCharacters

func (api *API) TotalCharacters() (int, error)

TotalCharacters gets the total characters in the APi.

type Character

type Character struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Thumbnail   struct {
		Path      string `json:"path"`
		Extension string `json:"extension"`
	} `json:"thumbnail"`
	URLs []struct {
		Type string `json:"type"`
		URL  string `json:"url"`
	} `json:"urls"`
	Comics struct {
		Available int `json:"available"`
	} `json:"comics"`
}

Character defines the struct for a Marvel character from their API.

type CharactersResultContainer

type CharactersResultContainer struct {
	Container
	Results []*Character `json:"results"`
}

CharactersResultContainer is the result for multiple characters returned.

type CharactersResultWrapper

type CharactersResultWrapper struct {
	Result
	CharactersResultContainer `json:"data"`
}

CharactersResultWrapper - ....yet another wrapper. :/

type Container

type Container struct {
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
	Total  int `json:"total"`
	Count  int `json:"count"`
}

Container is a container for meta results returned.

type Criteria

type Criteria struct {
	Limit   int
	Offset  int
	OrderBy string
}

Criteria defines the criteria for querying the API.

type ErrorResult

type ErrorResult struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorResult - Marvel *sometimes* returns a completely different JSON structure if is an error. But for invalid input or 409's they return a regular result.

type Result

type Result struct {
	Code            int    `json:"code"`
	Status          string `json:"status"`
	Copyright       string `json:"copyright"`
	AttributionText string `json:"attributionText"`
	ETag            string `json:"ETag"`
}

Result is the result of the API.

Jump to

Keyboard shortcuts

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