diff --git a/extra/marvel/authors.txt b/extra/marvel/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/marvel/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/marvel/marvel.factor b/extra/marvel/marvel.factor new file mode 100644 index 0000000000..810ee79190 --- /dev/null +++ b/extra/marvel/marvel.factor @@ -0,0 +1,42 @@ +! Copyright (C) 2014 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: assocs checksums checksums.md5 http.client json.reader +kernel locals math.parser namespaces sequences strings system +urls ; +IN: marvel + +! http://developer.marvel.com/docs +! Register for an api key. +SYMBOLS: marvel-base-url marvel-public-key marvel-private-key ; + +marvel-base-url [ "http://gateway.marvel.com/v1/public/" ] initialize + +: calculate-hash ( ts -- hash ) + number>string + marvel-private-key get + marvel-public-key get + 3append md5 checksum-bytes hex-string ; + +:: make-marvel-params-url ( endpoint params -- url ) + nano-count + [ "ts" params set-at ] + [ calculate-hash "hash" params set-at ] bi + marvel-public-key get "apikey" params set-at + marvel-base-url get endpoint [ >url ] bi@ derive-url + params [ swap set-query-param ] assoc-each ; + +: make-marvel-url ( endpoint -- string ) + H{ } clone make-marvel-params-url ; + +: get-marvel-params-url ( endpoint params -- data ) + make-marvel-params-url http-get nip >string json> ; + +: get-marvel-url ( endpoint -- data ) + H{ } clone get-marvel-params-url ; + +: get-characters ( -- json ) "characters" get-marvel-url ; +: get-comics ( -- json ) "comics" get-marvel-url ; +: get-creators ( -- json ) "creators" get-marvel-url ; +: get-events ( -- json ) "events" get-marvel-url ; +: get-series ( -- json ) "series" get-marvel-url ; +: get-stories ( -- json ) "stories" get-marvel-url ; diff --git a/extra/marvel/tags.txt b/extra/marvel/tags.txt new file mode 100644 index 0000000000..86e8a9d3ec --- /dev/null +++ b/extra/marvel/tags.txt @@ -0,0 +1 @@ +comics api web