This repository has been archived by the owner on May 30, 2018. It is now read-only.
forked from duncantl/RGoogleDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleMaps.R
92 lines (69 loc) · 2.57 KB
/
GoogleMaps.R
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
# See http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_protocol.html
library(RGoogleDocs)
library(RCurl)
library(XML)
AtomNS = "http://www.w3.org/2005/Atom"
setOldClass("GoogleMapsEntry")
setOldClass(c("GoogleMapsDoc", "XMLInternalDocument", "XMLAbstractDocument"))
makeEntry =
function(node)
{
ans = structure(xmlToList(node), class = "GoogleMapsEntry")
isLink = names(ans) == "link"
names(ans)[isLink] = sprintf("link.%s", sapply(ans[isLink], function(x) gsub(".*#", "#", x["rel"])))
ans
}
getMapInfo = getMapEntries =
function(con = getGoogleDocsConnection(service = "local"),
txt = getURLContent("http://maps.google.com/maps/feeds/maps/default/full", curl = con))
{
doc = xmlParse(I(txt))
getNodeSet(doc, "//a:entry", c(a = AtomNS))
entries = xpathApply(doc, "//a:entry",
makeEntry,
namespaces = c(a = AtomNS))
names(entries) = sapply(entries, "[[", "title")
entries
}
if(FALSE) {
auth = getGoogleAuth(service = "local")
con = getGoogleDocsConnection(auth = auth)
} else
con = getGoogleDocsConnection(service = "local")
setAs("GoogleMapsEntry", "GoogleMapsDoc",
function(from) {
tt = getURLContent(from$link.self["href"], curl = con)
doc = xmlParse(tt, asText = TRUE)
class(doc) = c("GoogleMapsDoc", class(doc)) # last so print methods work.
doc
})
setGeneric("title<-",
function(x, ..., value)
standardGeneric("title<-"))
setMethod("title<-", "GoogleMapsEntry",
function(x, ..., value) {
doc = as(x, "GoogleMapsDoc")
ti = getNodeSet(doc, "//a:title", c(a = AtomNS))
if(length(ti) == 0) {
}
xmlValue(ti) = value
q = httpPUT(getPostLink(x), curl = con,
postfields = saveXML(doc),
httpheader = c('Content-Type' = 'application/atom+xml',
"Authorization" = sprintf('GoogleLogin auth="%s"', con@auth)))
})
setMethod("title<-", "GoogleMapsDoc",
function(x, ..., value) {
})
getPostLink =
#
# What is doc ? the document for a particular map.
# This is for the top-level "folder".
# We may also want it for a particular document.
#
function(doc)
{
topLinks = getNodeSet(doc, "/a:feed/a:link", c(a = AtomNS))
rel = sapply(topLinks, xmlGetAttr, "rel")
postLink = xmlGetAttr(topLinks[grep("#post", rel)][[1]], "href")
}