Skip to content

Commit 19db7c2

Browse files
committed
Initial commit
0 parents  commit 19db7c2

5 files changed

Lines changed: 53 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pom.xml
2+
*jar
3+
lib
4+
classes

README

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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.

project.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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"]])

src/clj_googl/core.clj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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))))

test/clj_googl/test/core.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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."))

0 commit comments

Comments
 (0)