]> gitweb.factorcode.org Git - factor.git/commitdiff
marvel: Add new vocabulary.
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 26 Apr 2014 01:57:21 +0000 (18:57 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 26 Apr 2014 01:57:21 +0000 (18:57 -0700)
extra/marvel/authors.txt [new file with mode: 0644]
extra/marvel/marvel.factor [new file with mode: 0644]
extra/marvel/tags.txt [new file with mode: 0644]

diff --git a/extra/marvel/authors.txt b/extra/marvel/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/marvel/marvel.factor b/extra/marvel/marvel.factor
new file mode 100644 (file)
index 0000000..810ee79
--- /dev/null
@@ -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 (file)
index 0000000..86e8a9d
--- /dev/null
@@ -0,0 +1 @@
+comics api web