]> gitweb.factorcode.org Git - factor.git/commitdiff
bit.ly: URL shortening web service
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 13 Apr 2010 05:54:30 +0000 (22:54 -0700)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 13 Apr 2010 05:55:33 +0000 (22:55 -0700)
extra/bit/ly/authors.txt [new file with mode: 0644]
extra/bit/ly/ly.factor [new file with mode: 0644]
extra/bit/ly/summary.txt [new file with mode: 0644]
extra/bit/ly/tags.txt [new file with mode: 0644]

diff --git a/extra/bit/ly/authors.txt b/extra/bit/ly/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/extra/bit/ly/ly.factor b/extra/bit/ly/ly.factor
new file mode 100644 (file)
index 0000000..32d4078
--- /dev/null
@@ -0,0 +1,23 @@
+! Copyright (C) 2010 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: assocs http.client json.reader kernel namespaces urls ;
+IN: bit.ly
+
+SYMBOLS: login api-key ;
+
+<PRIVATE
+
+: make-request ( long-url -- request )
+    "http://api.bit.ly/v3/shorten" >url
+        login get "login" set-query-param
+        api-key get "apiKey" set-query-param
+        "json" "format" set-query-param
+        swap "longUrl" set-query-param ;
+
+: parse-response ( response data -- short-url )
+    nip json> "data" swap at "url" swap at ;
+
+PRIVATE>
+
+: shorten-url ( long-url -- short-url )
+    make-request http-get parse-response ;
diff --git a/extra/bit/ly/summary.txt b/extra/bit/ly/summary.txt
new file mode 100644 (file)
index 0000000..29020a6
--- /dev/null
@@ -0,0 +1 @@
+Wrapper for bit.ly URL shortening web service
diff --git a/extra/bit/ly/tags.txt b/extra/bit/ly/tags.txt
new file mode 100644 (file)
index 0000000..0a8d552
--- /dev/null
@@ -0,0 +1 @@
+web services