Skip to content

Commit

Permalink
first import
Browse files Browse the repository at this point in the history
  • Loading branch information
videlalvaro committed Sep 7, 2012
0 parents commit f4dc5af
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/target
/lib
/classes
/checkouts
pom.xml
*.jar
*.class
.lein-deps-sum
.lein-failures
.lein-plugins
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2012 Alvaro Videla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# claude

A Clojure library designed to ease integration with Cloud Foundry

NOTE: Work In Progress

## Usage

With leiningen add it to your project dependencies like this:

[claude "0.1.0-SNAPSHOT"]

And with Maven you can do:

<dependency>
<groupId>claude</groupId>
<artifactId>claude</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>

Then on your code you can use it this way:

(ns my.namespace
(use: [claude.core :as cf]
[langohr.core :as lhc]
[monger.core :as mg]))

(defonce default-url "mongodb://127.0.0.1/cloudstagram")

(defn mongo-connect []
(if (cf/cloudfoundry?)
(mg/connect-via-uri! (cf/mongo-url))
(mg/connect-via-uri! default-url)))

(defn rabbitmq-connect []
(if (cf/cloudfoundry?)
(lhc/connect (lhc/settings-from (cf/rabbit-url)))
(lhc/connect)))

(defonce ^Connection conn (rabbitmq-connect))

## TODO

- Add a proper `groupId` for the Maven repositories
- Improve Integration with Cloud Foundry services
- Improve API for obatining services credentials/info


## License

Copyright © 2012 FIXME

Distributed under the Eclipse Public License, the same as Clojure.
3 changes: 3 additions & 0 deletions doc/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Introduction to claude

TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
8 changes: 8 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(defproject claude "0.1.0-SNAPSHOT"
:description "Utilities to connect Clojure apps to Cloud Foundry"
:url "http://example.com/FIXME"
:license {:name "The MIT License"
:url "http://opensource.org/licenses/mit-license.php"}
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/data.json "0.1.3"]]
:plugins [[lein-swank "1.4.4"]])
29 changes: 29 additions & 0 deletions src/claude/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(ns claude.core
(:use [clojure.data.json :only [read-json]]))

(defn cloudfoundry? []
(not (nil? (System/getenv "VCAP_SERVICES"))))

(defn service-config [label key]
(if-let [services (System/getenv "VCAP_SERVICES")]
(let [services-dict (read-json services false)]
(-> services-dict
(get label)
first ;; maybe in the future allow to use multiple services
(get "credentials")
(get key)))))

(defn mongo-config [key]
(service-config "mongodb-2.0" key))

(defn rabbit-config [key]
(service-config "rabbitmq-2.4" key))

(defn redis-config [key]
(service-config "redis-2.2" key))

(defn mongo-url []
(mongo-config "url"))

(defn rabbit-url []
(rabbit-config "url"))
7 changes: 7 additions & 0 deletions test/claude/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns claude.core-test
(:use clojure.test
claude.core))

(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))

0 comments on commit f4dc5af

Please sign in to comment.