shoreleave/shoreleave-services

0.3.0


A smarter client-side with ClojureScript : Shoreleave's API for third-party remote services

dependencies

org.clojure/clojure
1.4.0
shoreleave/shoreleave-core
0.3.0
shoreleave/shoreleave-remote
0.3.0

dev dependencies

lein-marginalia
0.7.1



(this space intentionally left almost blank)
 
(ns shoreleave.client.services.duckduckgo
  (:require [shoreleave.remote :as remote]))
(defn zero-click [query callback-fn]
  (remote/jsonp "http://api.duckduckgo.com"
                :content {:format "json" :pretty "0"
                          :q query}
                :on-success #(callback-fn %)))
 
(ns shoreleave.services.geo)

TODO replace this with: http://maps.google.com/maps/geo?q=nyc&sensor=false and http://closure-library.googlecode.com/svn/docs/classgoognet_Jsonp.html goog.net.Jsonp(uri, opt_callbackParamName)

TODO We should do an include-js function that pulls in google maps:

(defn include-js [] (js/document.write ""))

(defn include-js []
  (js/document.write "<script>window.google || document.write('<script src=\"http://maps.google.com/maps/api/js?sensor=false\"></script>')</script>"))

TODO: I really need to extern these in here

(defn geocoder []
  (try
    (when (undefined? js/google)
      (include-js))
    (catch js/Error err
      (include-js))
    (finally (js/google.maps.Geocoder.)))
  (js/google.maps.Geocoder.))

TODO: if we want the zip, it's the last element in (.-address_components geo-obj)

(defn mapify-location [geocode-results]
  (let [[geo-obj] geocode-results
        lat (.-geometry.location.lat geo-obj)
        lng (.-geometry.location.lng geo-obj)]
    {:lat         lat
     :lng         lng
     :latlng-str  (str lat "," lng)
     :formatted   (.-formatted_address geo-obj)}))
(defn normalize-location
  ([loc-str callback]
   (normalize-location loc-str callback mapify-location))
  ([loc-str callback process-location-fn]
   (.geocode (geocoder)
     (clj->js {:address loc-str})
     #(callback (process-location-fn %1)))))

This version should probably be used instead of `#(callback ...) It makes sure that the call was successful

 
(ns shoreleave.client.services.wikipedia)

http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=wikipedia&srprop=timestamp&format=json&callback=test