Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/85bc57e85826a0887f09 to your computer and use it in GitHub Desktop.
Save JogoShugh/85bc57e85826a0887f09 to your computer and use it in GitHub Desktop.
> print(res)
[1] "[\r\n [\r\n {\r\n \"_oid\": \"Member:20\",\r\n \"Name\": \"Administrator\"\r\n }\r\n ]\r\n]"
attr(,"Content-Type")
charset
"application/json" "utf-8"
>
> res <- fromJSON(res)
> print(res)
[[1]]
_oid Name
1 Member:20 Administrator
>
> str(res)
List of 1
$ :'data.frame': 1 obs. of 2 variables:
..$ _oid: chr "Member:20"
..$ Name: chr "Administrator"
>
> # Get results back...
> query <- list(
+ from="Member",
+ select="Name"
+ )
> json <- toJSON(query, auto_unbox=T)
> res <- getURLContent(url=paste(api, json, sep=''), userpwd=creds, httpauth=auth)
> res <- fromJSON(res)
> print(res)
[[1]]
_oid Name
1 Member:20 Administrator
2 Member:2004 V1 User
3 Member:2005 Andre Agile
4 Member:2006 Danny Developer
5 Member:2007 Tammy Tester
6 Member:2008 Willy Webguy
7 Member:2048 Clarity PPM Service
> str(res)
List of 1
$ :'data.frame': 7 obs. of 2 variables:
..$ _oid: chr [1:7] "Member:20" "Member:2004" "Member:2005" "Member:2006" ...
..$ Name: chr [1:7] "Administrator" "V1 User" "Andre Agile" "Danny Developer" ...
>
library(RCurl)
library(jsonlite)
#'https://www14.v1host.com/v1sdktesting/query.legacy.v1?query=' -> api
'http://54.242.130.237/VersionOne/query.legacy.v1?query=' -> api
auth <- 1L
'admin:admin' -> creds # Just another way of assigning values to variables!
# Get aroud Server-side SSL errors!
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
# Create a basic "list" object in R with named values
query <- list(
from="Member",
select="Name",
where=list(ID="Member:20")
)
# Convert the list to JSON data with jsonlite, and the new auto_unbox param which ensures that single-element list
# or vector values translate as scalars, not arrays.
json <- toJSON(query, auto_unbox=T)
# Run the query and get the result!
res <- getURLContent(url=paste(api, json, sep=''), userpwd=creds, httpauth=auth)
print(res)
res <- fromJSON(res)
print(res)
str(res)
# Get multiple member results back...
query <- list(
from="Member",
select="Name"
)
json <- toJSON(query, auto_unbox=T)
res <- getURLContent(url=paste(api, json, sep=''), userpwd=creds, httpauth=auth)
res <- fromJSON(res)
print(res)
str(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment