chucknorris

package module
v0.0.0-...-a64712d Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

README

go-icndb

Build Status GoDoc

GoLang client for the Internet Chuck Norris Database API (http://www.icndb.com/api/).

Usage

Get a Random Joke
package main

import (
	"fmt"
	"log"

	"github.com/saadullahsaeed/go-icndb"
)

func main() {
	joke, err := chucknorris.GetRandomJoke(nil)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("\nID: %d ", joke.ID)
	fmt.Printf("\nText: %s", joke)
}
Specify Custom Name for the Joke
  req := &chucknorris.CNDBRequest{
    FirstName: "John",
    LastName: "Doe",
  }
  joke, err := chucknorris.GetRandomJoke(req)
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Printf("\nJoke: %s", joke)

Documentation

Overview

Package chucknorris is a golang implementation of the ICNDB API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CNDBRequest

type CNDBRequest struct {
	FirstName string
	LastName  string
}

CNDBRequest is used to specify request parameters for the API

func (*CNDBRequest) URLValues

func (r *CNDBRequest) URLValues() url.Values

URLValues translates properities of Request struct to URL Parameters for API

type CNDBResponse

type CNDBResponse struct {
	Type  string `json:"type"`
	Value *Joke  `json:"value"`
}

CNDBResponse is the type for API Result

type Joke

type Joke struct {
	ID   int    `json:"id"`
	Joke string `json:"joke"`
}

Joke struct represents the Joke returned by ICNDB API

func GetJokeByID

func GetJokeByID(id int, req *CNDBRequest) (*Joke, error)

GetJokeByID can be used to get a joke specified by its ID

func GetRandomJoke

func GetRandomJoke(req *CNDBRequest) (*Joke, error)

GetRandomJoke returns a random joke from ICNDB API

func (*Joke) String

func (j *Joke) String() string

Stringer interface for Joke struct

Jump to

Keyboard shortcuts

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