Created
November 28, 2008 18:39
-
-
Save drewr/30043 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns rets | |
(:import (org.apache.http.impl.client DefaultHttpClient) | |
(org.apache.http.client.methods HttpGet HttpPost) | |
(org.apache.http.auth UsernamePasswordCredentials) | |
(org.apache.http.util EntityUtils))) | |
(use '[clojure.contrib.str-utils]) | |
(def base-url "http://rets.realtracs.net:6103") | |
(def login-path "/rets/login") | |
(def logout-path "/rets/logout") | |
(def login-url (str base-url login-path)) | |
(def logout-url (str base-url logout-path)) | |
(def default-auth-query-map { :username "parkrets", :password "parks859" }) | |
(def default-query { :querytype "DMQL", :standardnames "0", :count "0", :format "COMPACT" }) | |
(defn- map->querystring | |
"Builds a string in the form of querytype=DMQL&standardnames=0&count=0" | |
[m] | |
(let [join-pair (fn [[k v]] | |
(str-join "=" [(.toUpperCase (name k)) v]))] | |
(str-join "&" | |
(reduce (fn [acc pair] | |
(conj acc (join-pair pair))) [] m)))) | |
(defn- build-request | |
"Build HttpGet/HttpPost request objects for request through HttpClient" | |
([] (HttpPost. login-url)) | |
([m] (let [url (str base-url "?" (map->querystring (conj default-query m)))] | |
(HttpGet. url)))) | |
(defn- authenticate | |
"Authenticate web service via DIGEST method" | |
[] | |
(let [httpclient (DefaultHttpClient.)] | |
(doto httpclient | |
(.getCredentialsProvider) | |
(.setCredentials | |
(UsernamePasswordCredentials. | |
(:username default-auth-query-map) | |
(:password default-auth-query-map))) | |
(.execute (build-request))))) | |
(defn property | |
"Return XML of MLS number" | |
[mlsnum]) | |
;; Usage | |
(authe0nticate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment