forked from junghao/geonet-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volcano.go
104 lines (91 loc) · 3.41 KB
/
volcano.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"github.com/GeoNet/web"
"github.com/GeoNet/web/api/apidoc"
"html/template"
"net/http"
)
var volcanoDoc = apidoc.Endpoint{Title: "Volcano",
Description: "Look up volcano information. <b>Caution - under development, subject to change.</b>",
Queries: []*apidoc.Query{
alertLevelD,
alertBulletinD,
},
}
const alertBulletinURL = `http://info.geonet.org.nz/createrssfeed.action?types=blogpost&spaces=volc&title=GeoNet+Volcano+RSS+Feed&labelString=vab&excludedSpaceKeys%3D&sort=created&maxResults=10&timeSpan=500&showContent=true&publicFeed=true&confirm=Create+RSS+Feed`
var alertLevelD = &apidoc.Query{
Accept: web.V1GeoJSON,
Title: "Volcanic Alert Level",
Description: `Volcanic Alert Level information for all volcanoes.`,
Discussion: `<p>Volcanic Alert Level information for all volcanoes. Please refer to <a href="http://info.geonet.org.nz/x/PYAO">Volcanic Alert Levels</a> for additional information.</p>`,
Example: "/volcano/alert/level",
ExampleHost: exHost,
URI: "/volcano/alert/level",
Required: map[string]template.HTML{
"none": `no query parameters are required.`,
},
Props: map[string]template.HTML{
`volcanoID`: `a unique identifier for the volcano.`,
`volcanoTitle`: `the volcano title.`,
`level`: `volcanic alert level.`,
`activity`: `volcanic activity.`,
`hazards`: `most likely hazards.`,
},
}
func alertLevel(w http.ResponseWriter, r *http.Request) {
if len(r.URL.Query()) != 0 {
web.BadRequest(w, r, "incorrect number of query parameters.")
return
}
var d string
err := db.QueryRow(`SELECT row_to_json(fc)
FROM ( SELECT 'FeatureCollection' as type, array_to_json(array_agg(f)) as features
FROM (SELECT 'Feature' as type,
ST_AsGeoJSON(v.location)::json as geometry,
row_to_json((SELECT l FROM
(
SELECT
id AS "volcanoID",
title AS "volcanoTitle",
alert_level as "level",
activity,
hazards
) as l
)) as properties FROM (qrt.volcano JOIN qrt.volcanic_alert_level using (alert_level)) as v ) As f ) as fc`).Scan(&d)
if err != nil {
web.ServiceUnavailable(w, r, err)
return
}
b := []byte(d)
web.Ok(w, r, &b)
}
var alertBulletinD = &apidoc.Query{
Accept: web.V1JSON,
Title: "Volcanic Alert Bulletins",
Description: " Returns a simple JSON version of the GeoNet Volcanic Alert Bulletin RSS feed.",
Example: "/volcano/alert/bulletin",
ExampleHost: exHost,
URI: "/volcano/alert/bulletin",
Required: map[string]template.HTML{
"none": `no query parameters are required.`,
},
Props: map[string]template.HTML{
"mlink": "a link to a mobile version of the bulletin.",
"link": "a link to the bulletin.",
"published": "the date the bulletin was published",
"title": "the title of the bulletin.",
},
}
func alertBulletin(w http.ResponseWriter, r *http.Request) {
if len(r.URL.Query()) != 0 {
web.BadRequest(w, r, "incorrect number of query parameters.")
return
}
j, err := fetchRSS(alertBulletinURL)
if err != nil {
web.ServiceUnavailable(w, r, err)
return
}
w.Header().Set("Surrogate-Control", web.MaxAge300)
web.Ok(w, r, &j)
}