api

package
v0.0.0-...-ae1e397 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2017 License: BSD-2-Clause Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category represents a joke category.

type Client

type Client struct {

	// BaseURL is the url to the Chuck Norris jokes API.
	BaseURL string

	// UserAgent is the user agent to use when interacting with the API.
	UserAgent string
	// contains filtered or unexported fields
}

Client is an API client to the Chuck Norris jokes.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient creates a new API client.

func (*Client) Categories

func (c *Client) Categories() ([]Category, error)

Categories returns the list of categories.

func (*Client) RandomJoke

func (c *Client) RandomJoke(categories ...Category) (*Joke, error)

RandomJoke returns a random joke.

func (*Client) Search

func (c *Client) Search(query string) (*SearchResponse, error)

Search searches for jokes matching a given search query.

type Joke

type Joke struct {
	// IconURL is the url to the Chuck Norris API icon.
	IconURL string `json:"icon_url"`

	// Id is the id of the joke.
	Id string `json:"id"`

	// URL is the url to the joke.
	URL string `json:"url"`

	// Value contains the joke text.
	Value string `json:"value"`
}

Joke type represents a Chuck Norris joke.

type SearchResponse

type SearchResponse struct {
	// Total is the total number of jokes matching the search query.
	Total int `json:"total"`

	// Result is the list of jokes matching the search query.
	Result []Joke `json:"result"`
}

SearchResponse is the response returned by the API when searching for jokes.

Jump to

Keyboard shortcuts

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