spaceapi update to 0.13
authorBernhard Tittelbach <xro@realraum.at>
Wed, 27 Mar 2013 16:27:55 +0000 (16:27 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Wed, 27 Mar 2013 16:27:55 +0000 (16:27 +0000)
r3-webstatus-spaceapi/main.go
r3-webstatus-spaceapi/spaceapi/spaceapi.go

index 9844717..28c094b 100644 (file)
@@ -22,7 +22,7 @@ var (
        re_temp_        *regexp.Regexp     = regexp.MustCompile("temp0: (\\d+\\.\\d+)")
        re_photo_       *regexp.Regexp     = regexp.MustCompile("photo0: (\\d+)")
        re_querystresc_ *regexp.Regexp     = regexp.MustCompile("[^\x30-\x39\x41-\x7E]")
-       spaceapidata    spaceapi.SpaceInfo = spaceapi.NewSpaceInfo("realraum", "http://realraum.at", "http://realraum.at/logo-red_250x250.png", "http://realraum.at/logo-re_open_100x100.png", "http://realraum.at/logo-re_empty_100x100.png").AddSpaceAddress("Jakoministr. 16 ground level left, 8010 Graz, Austria").AddSpaceLatLon(47.065779129, 15.442322614)
+       spaceapidata    spaceapi.SpaceInfo = spaceapi.NewSpaceInfo("realraum", "http://realraum.at", "http://realraum.at/logo-red_250x250.png", "http://realraum.at/logo-re_open_100x100.png", "http://realraum.at/logo-re_empty_100x100.png",47.065779129, 15.442322614).AddSpaceAddress("Jakoministr. 16 ground level left, 8010 Graz, Austria")
        statusstate     *SpaceState        = new(SpaceState)
 )
 
index 7e08819..3a0f828 100644 (file)
@@ -64,7 +64,7 @@ func (nsi SpaceInfo) AddSpaceFeed(name, mimetype, url string) SpaceInfo {
 }
 
 func (nsi SpaceInfo) AddSpaceEvent(name, eventtype, extra string) SpaceInfo {
-       newevent := SpaceInfo{"name": name, "type": eventtype, "t": time.Now().Unix(), "extra": extra}
+       newevent := SpaceInfo{"name": name, "type": eventtype, "timestamp": time.Now().Unix(), "extra": extra}
        if nsi["events"] == nil {
                eventlist := make([]SpaceInfo, 1)
                eventlist[0] = newevent
@@ -85,12 +85,12 @@ func (nsi SpaceInfo) AddSpaceEvent(name, eventtype, extra string) SpaceInfo {
 
 func (nsi SpaceInfo) AddSpaceAddress(address string) SpaceInfo {
        nsi["address"] = address
-       return nsi
-}
-
-func (nsi SpaceInfo) AddSpaceLatLon(lat float64, lon float64) SpaceInfo {
-       nsi["lat"] = lat
-       nsi["lon"] = lon
+    if nsi["location"] != nil {
+        location, ok := nsi["location"].(SpaceInfo)
+        if ok {
+            location["address"] = address
+        }
+    }
        return nsi
 }
 
@@ -100,7 +100,7 @@ func (nsi SpaceInfo) SetStatus(open bool, status string) {
        nsi["lastchange"] = time.Now().Unix()
 }
 
-func NewSpaceInfo(space string, url string, logo string, open_icon string, closed_icon string) SpaceInfo {
+func NewSpaceInfo(space string, url string, logo string, open_icon string, closed_icon string, lat float64, lon float64) SpaceInfo {
        nsi := map[string]interface{}{
                "api":        "0.13",
                "space":      space,
@@ -108,9 +108,13 @@ func NewSpaceInfo(space string, url string, logo string, open_icon string, close
                "logo":       logo,
                "open":       false,
                "lastchange": time.Now().Unix(),
-               "icon": map[string]interface{}{
+               "icon": SpaceInfo{
                        "open":   open_icon,
-                       "closed": closed_icon}}
+                       "closed": closed_icon},
+        "location": SpaceInfo{
+            "lat": lat,
+            "lon": lon},
+        "contact" : SpaceInfo {}           }
        return nsi
 }