Skip to content

Commit

Permalink
R client: added addtional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstruck committed Sep 4, 2019
1 parent dc9b6f3 commit 7ba5f09
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions gripql/R/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export(distinct)
export(eq)
export(execute)
export(fields)
export(getSchema)
export(graph)
export(gripql)
export(gt)
Expand All @@ -30,6 +31,7 @@ export(inV)
export(in_)
export(inside)
export(limit)
export(listGraphs)
export(lt)
export(lte)
export(match)
Expand Down
34 changes: 32 additions & 2 deletions gripql/R/R/gripql.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ print.gripql <- function(x) {
print(sprintf("host: %s", attr(x, "host")))
}

#' @export
listGraphs <- function(conn) {
check_class(conn, "gripql")
response <- httr::GET(url = sprintf("%s/v1/graph", attr(conn, "host")),
httr::add_headers(unlist(attr(conn, "header"), use.names = TRUE)),
httr::verbose())
httr::stop_for_status(response)
if (!grepl("application/json", response$headers$`content-type`)) {
stop(sprintf("unexpected content-type '%s' in query response",
response$headers$`content-type`))
}
r <- httr::content(response, as = "parsed", encoding = "UTF-8")
r$graphs
}

#' @export
graph <- function(conn, graph_name) {
check_class(conn, "gripql")
Expand All @@ -57,6 +72,21 @@ print.gripql.graph <- function(x) {
print(sprintf("graph: %s", attr(x, "graph")))
}

#' @export
getSchema <- function(conn) {
check_class(conn, "gripql.graph")
response <- httr::GET(url = sprintf("%s/v1/graph/%s/schema", attr(conn, "host"), attr(conn, "graph")),
httr::add_headers(unlist(attr(conn, "header"), use.names = TRUE)),
httr::verbose())
httr::stop_for_status(response)
if (!grepl("application/json", response$headers$`content-type`)) {
stop(sprintf("unexpected content-type '%s' in query response",
response$headers$`content-type`))
}
r <- httr::content(response, as = "parsed", encoding = "UTF-8")
r
}

#' @export
query <- function(conn) {
check_class(conn, "gripql.graph")
Expand Down Expand Up @@ -102,7 +132,7 @@ execute <- function(q) {
stop(sprintf("unexpected content-type '%s' in query response",
response$headers$`content-type`))
}
httr::content(response, as="text") %>%
httr::content(response, as="text", encoding = "UTF-8") %>%
trimws() %>%
strsplit("\n") %>%
unlist() %>%
Expand All @@ -119,7 +149,7 @@ execute <- function(q) {
r <- r$selections$selections
} else if ("render" %in% names(r)) {
r <- r$render
}}
}
r
})
}
Expand Down
12 changes: 11 additions & 1 deletion gripql/python/gripql/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, url, graph, user=None, password=None, token=None, credential_

def addSchema(self, vertices=[], edges=[]):
"""
Add vertex to a graph.
Add the schema for a graph.
"""
payload = {
"graph": self.graph,
Expand All @@ -28,6 +28,16 @@ def addSchema(self, vertices=[], edges=[]):
raise_for_status(response)
return response.json()

def getSchema(self):
"""
Get the schema for a graph.
"""
response = self.session.get(
self.url + "/schema"
)
raise_for_status(response)
return response.json()

def addVertex(self, gid, label, data={}):
"""
Add vertex to a graph.
Expand Down

0 comments on commit 7ba5f09

Please sign in to comment.