File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ pom.xml
2+ * jar
3+ lib
4+ classes
Original file line number Diff line number Diff line change 1+ # clj-googl
2+
3+ Very basic goo.gl url shortener service API implementation.
4+
5+ No error handling implemented.
6+
7+ ## Usage
8+
9+ user=> (shorten "http://google.com")
10+ "http://goo.gl/mR2d"
11+ user=> (expand "http://goo.gl/mR2d")
12+ "http://google.com/"
13+
14+ ## License
15+
16+ Copyright (C) 2010 zw0rk
17+
18+ Distributed under the Eclipse Public License, the same as Clojure.
Original file line number Diff line number Diff line change 1+ (defproject clj-googl " 0.0.1-SNAPSHOT"
2+ :description " Goo.gl API implementation for clojure"
3+ :dependencies [[org.clojure/clojure " 1.2.0" ]
4+ [org.clojure/clojure-contrib " 1.2.0" ]
5+ [com.twinql.clojure/clj-apache-http " 2.2.0" ]])
Original file line number Diff line number Diff line change 1+ (ns clj-googl.core
2+ (:refer-clojure )
3+ (:require [clojure.contrib.json :as json]
4+ [com.twinql.clojure.http :as http])
5+ (:import (java.net URI)
6+ (org.apache.http.entity StringEntity)))
7+
8+ (def *apiuri* (java.net.URI. " https://www.googleapis.com/urlshortener/v1/url" ))
9+
10+ (defn shorten [url]
11+ " Shorten long URL"
12+ (:id (:content (http/post
13+ *apiuri*
14+ :headers {" Content-Type" " application/json" }
15+ :body (StringEntity. (json/json-str {:longUrl url}))
16+ :as :json ))))
17+
18+ (defn expand [url]
19+ " Expand short URL"
20+ (:longUrl (:content (http/get *apiuri* :query {:shortUrl url} :as :json ))))
Original file line number Diff line number Diff line change 1+ (ns clj-googl.test.core
2+ (:use [clj-googl.core] :reload )
3+ (:use [clojure.test]))
4+
5+ (deftest replace-me ; ; FIXME: write
6+ (is false " No tests have been written." ))
You can’t perform that action at this time.
0 commit comments