Skip to content

Commit

Permalink
R client: method signatures wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstruck committed Sep 4, 2019
1 parent f15ea17 commit 543daf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion gripql/R/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by roxygen2: do not edit by hand

S3method(print,gripql)
S3method(print,gripql.query)
S3method(print,gripql.graph)
S3method(print,gripql.graph.query)
export(aggregate)
export(as_)
export(between)
Expand Down
20 changes: 14 additions & 6 deletions gripql/R/R/gripql.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ gripql <- function(host, user=NULL, password=NULL, token=NULL, credential_file=N
if (!is.null(token)) {
header["Authorization"] = paste("Bearer", token, sep=" ")
} else if (!(is.null(user) | is.null(password))) {
header["Authorization"] = paste("Basic", jsonlite::base64_enc(paste(user, password, sep = ":"), sep = " ")
header["Authorization"] = paste("Basic", jsonlite::base64_enc(paste(user, password, sep = ":"), sep = " "))
} else if (!is.null(credential_file)) {
if (!file.exists(credential_file)) {
stop("credential file does not exist!")
Expand All @@ -44,22 +44,30 @@ print.gripql <- function(x) {
}

#' @export
graph.gripql <- function(conn, graph) {
graph <- function(conn, graph) {
class(conn) <- c("gripql.graph", "gripql")
attr(conn, "graph") <- graph
conn
}

#' @export
query.gripql.graph <- function(conn) {
print.gripql.graph <- function(x) {
print(paste("host:", attr(x, "host"), sep = " "))
print(paste("graph:", attr(x, "graph"), sep = " "))
}

#' @export
query <- function(conn) {
class(conn) <- c("gripql.graph.query", "gripql.graph", "gripql")
attr(conn, "query") <- list()
conn
}

#' @export
print.gripql.graph.query <- function(x) {
print(attr(x, "query"))
print(paste("host:", attr(x, "host"), sep = " "))
print(paste("graph:", attr(x, "graph"), sep = " "))
print(paste("query:", attr(x, "query"), sep = " "))
}

append.gripql.graph.gquery <- function(x, values, after = length(x)) {
Expand All @@ -71,12 +79,12 @@ append.gripql.graph.gquery <- function(x, values, after = length(x)) {
}

#' @export
to_json.gripql.graph.query <- function(q) {
to_json <- function(q) {
jsonlite::toJSON(attr(q, "query"), auto_unbox = T, simplifyVector = F)
}

#' @export
execute.gripql.graph.query <- function(q) {
execute <- function(q) {
body <- to_json(q)
response <- httr::POST(url = paste(attr(q, "host"), "/v1/graph/", attr(q, "graph"), "/query", sep = ""),
body = body,
Expand Down

0 comments on commit 543daf9

Please sign in to comment.