Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
genesysr
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Genesys PGR
genesysr
Commits
1621e571
Commit
1621e571
authored
Jun 12, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide internal functions
parent
cc7fae5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
R/api-client.R
R/api-client.R
+7
-7
R/genesys.R
R/genesys.R
+6
-6
No files found.
R/api-client.R
View file @
1621e571
...
...
@@ -77,7 +77,7 @@ authorization <- function(authorization) {
}
#' Ensure that environment has OAuth token
check_auth
<-
function
()
{
.
check_auth
<-
function
()
{
if
(
is.null
(
.genesysEnv
$
Authorization
))
{
warning
(
"You must first authorize with Genesys with user_login() or client_login(...)."
);
}
...
...
@@ -155,8 +155,8 @@ client_login <- function() {
}
api_call
<-
function
(
path
,
method
=
"get"
)
{
check_auth
()
.
api_call
<-
function
(
path
,
method
=
"get"
)
{
.
check_auth
()
resp
<-
httr
::
GET
(
api_url
(
path
),
httr
::
add_headers
(
Authorization
=
.genesysEnv
$
Authorization
)
...
...
@@ -184,8 +184,8 @@ api_url <- function(path) {
paste0
(
.genesysEnv
$
server
,
"/api/v0"
,
path
)
}
get
<-
function
(
path
,
query
=
NULL
)
{
check_auth
()
.
get
<-
function
(
path
,
query
=
NULL
)
{
.
check_auth
()
resp
<-
httr
::
GET
(
api_url
(
path
),
query
=
query
,
httr
::
add_headers
(
Authorization
=
.genesysEnv
$
Authorization
))
...
...
@@ -203,8 +203,8 @@ get <- function(path, query = NULL) {
#' @param content.type Content-Type of the body
#'
#' @return httr response
post
<-
function
(
path
,
query
=
NULL
,
body
=
NULL
,
content.type
=
"application/json"
)
{
check_auth
()
.
post
<-
function
(
path
,
query
=
NULL
,
body
=
NULL
,
content.type
=
"application/json"
)
{
.
check_auth
()
content
<-
jsonlite
::
toJSON
(
body
)
if
(
!
is.null
(
body
)
&&
length
(
body
)
==
0
)
{
# If body is provided, but has length of 0
...
...
R/genesys.R
View file @
1621e571
...
...
@@ -19,7 +19,7 @@
#'
#' @export
me
<-
function
()
{
resp
<-
api_call
(
"/me"
)
resp
<-
.
api_call
(
"/me"
)
message
(
jsonlite
::
toJSON
(
resp
,
pretty
=
TRUE
))
invisible
(
resp
)
}
...
...
@@ -38,9 +38,9 @@ me <- function() {
#' accessions <- fetch_accessions(mcpd_filter(ORIGCTY = c("DEU", "SVN")))
#'
#' @return Paged data structure
fetch_accessions_page
<-
function
(
filters
=
list
(),
page
=
0
,
size
=
1000
,
selector
=
NULL
)
{
.
fetch_accessions_page
<-
function
(
filters
=
list
(),
page
=
0
,
size
=
1000
,
selector
=
NULL
)
{
start_time
<-
as.numeric
(
as.numeric
(
Sys.time
())
*
1000
,
digits
=
15
)
resp
<-
post
(
path
=
"/acn/filter"
,
query
=
list
(
p
=
page
,
l
=
size
),
body
=
filters
)
resp
<-
.
post
(
path
=
"/acn/filter"
,
query
=
list
(
p
=
page
,
l
=
size
),
body
=
filters
)
if
(
httr
::
status_code
(
resp
)
!=
200
)
{
stop
(
"Genesys responded with HTTP status code "
,
httr
::
status_code
(
resp
),
". Expected 200."
)
}
...
...
@@ -80,11 +80,11 @@ fetch_accessions_page <- function(filters = list(), page = 0, size = 1000, selec
fetch_accessions
<-
function
(
filters
=
list
(),
page
=
NULL
,
size
=
1000
,
selector
=
NULL
,
at.least
=
NULL
)
{
if
(
!
is.null
(
page
))
{
# Fetch page
return
(
fetch_accessions_page
(
filters
,
page
,
size
,
selector
));
return
(
.
fetch_accessions_page
(
filters
,
page
,
size
,
selector
));
}
# Fetch first page to determine number of records
paged
<-
fetch_accessions_page
(
filters
,
page
=
0
,
size
,
selector
)
paged
<-
.
fetch_accessions_page
(
filters
,
page
=
0
,
size
,
selector
)
pages
<-
paged
$
totalPages
for
(
page
in
1
:
pages
)
{
...
...
@@ -93,7 +93,7 @@ fetch_accessions <- function(filters = list(), page = NULL, size = 1000, selecto
message
(
paste
(
"Not requesting data after page"
,
.MAX_ALLOWED_PAGES
,
"Stopping."
))
break
}
p
<-
fetch_accessions_page
(
filters
,
page
,
size
,
selector
)
p
<-
.
fetch_accessions_page
(
filters
,
page
,
size
,
selector
)
paged
$
content
<-
c
(
paged
$
content
,
p
$
content
)
paged
$
last
<-
p
$
last
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment