HTTPS SSH

ICNDB Ext v0.0.4


Written in: Fantom pod: v0.0.4 Licence: ISC

LEAD: An extension for SkySpark v3.0.12+ that provides Axon functions for retreiving jokes from the Internet Chuck Norris Database (ICNDB).

Overview

LEAD: There's only one thing more awesome than Chuck Norris...

LEAD: And that's Chuck Norris jokes!

Over at the Internet Chuck Norris Database (or ICNDB for short) you can find literally hundreds of Chuck Norris jokes. They have classic ones, rude ones, and even nerdy ones!

The ICNDB boasts a REST-ful API for easy access. It lets you retrieve random jokes, jokes by ID, and jokes by category. Not only that, it even lets you change the words Chuck Norris to any name you want! Be it your name, your friend's name, or your Mum!

And now you can call the ICNDB from Axon!

// get random joke
joke1 : afIcndbGet()     // --> "Love does not hurt. Chuck Norris does."

// get joke by ID
joke2 : afIcndbGet(461)  // --> "Chuck Norris finished World of Warcraft."

// pass options
joke3 : afIcndbGet({
    "firstName" : "Emma",
    "lastName"  : "Statham",
    "limitTo"   : ["nerdy"]
})                       // --> "Emma Statham can install a 64 bit OS on 32 bit machines."

Wow! Just think, now all your SkySpark applications can have a Chuck Norris joke of the day!

Chuck Norris

"All browsers support the hex definitions #chuck and #norris for the colours black and blue."

True dat.

Install

Install ICNDB Ext with the Fantom Pod Manager ( FPM ):

C:\> fpm install afIcndbExt

Or install ICNDB Ext with fanr:

C:\> fanr install -r http://eggbox.fantomfactory.org/fanr/ afIcndbExt

To use in a Fantom project, add a dependency to build.fan:

depends = ["sys 1.0", ..., "afIcndbExt 0.0"]

Documentation

Full API & fandocs are available on the Eggbox - the Fantom Pod Repository.

Reference Documentation

Reference documentation for Axon functions.

afIcndbGet(jokeId: null, options: null)

Returns a joke ( Dict ) from the Internet Chuck Norris Database (ICNDB).

jokeId should be an Number, but if null then a random joke is returned.

options is a Dict of options. If jokeId is null, then options can also be passed as the first argument. Valid options are:

  • firstName (Str) - a replacement for the name Chuck
  • lastName (Str) - a replacement the name Norris
  • limitTo (Str[]) - a list of categories to limit the jokes to
  • exclude (Str[]) - a list of categories to exclude

The returned Dict contains the keys id (Number), joke (Str), and categories (Str[]). Example:

joke : afIcndbGet(461)["joke"]  // --> "Chuck Norris finished World of Warcraft."

joke : afIcndbGet()["joke"]     // --> "Love does not hurt. Chuck Norris does."

joke : afIcndbGet({
  "firstName" : "Emma",
  "lastName"  : "Statham",
  "limitTo"   : ["nerdy"]
})["joke"]                      // --> "Emma Statham can install a 64 bit OS on 32 bit machines."

Since 0.0.4, if no exclude or limitTo options are defined then, to protect the innocent, explicit jokes are excluded.

See http://www.icndb.com/api/ for details.

afIcndbCategories()

Returns a list of joke categories ( Str ) available on the ICNDB. These may be used in limitTo and exclude options when retrieving a joke.

categories : afIcndbCategories()  // --> ["explicit", "nerdy"]

joke : afIcndbGet({
  "limitTo" : ["nerdy"]
})

joke : afIcndbGet({
  "exclude" : ["explicit"]
})

See http://www.icndb.com/api/ for details.

afIcndbNoOfJokes()

Returns the number of jokes on the ICNDB.

noOfJokes : afIcndbNoOfJokes()  // --> 546

See http://www.icndb.com/api/ for details.

Licensing

ICNDB Ext is free software and an open source project licensed under the permissive ISC Licence by the Internet Systems Consortium - it is similar to the popular MIT licence, only shorter!