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
75131536
Commit
75131536
authored
Jun 12, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for OAuth headers before making API calls
parent
650972db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
R/api-client.R
R/api-client.R
+10
-0
No files found.
R/api-client.R
View file @
75131536
...
...
@@ -76,6 +76,13 @@ authorization <- function(authorization) {
message
(
paste
(
'Genesys Authorization:'
,
authorization
))
}
#' Ensure that environment has OAuth token
check_auth
<-
function
()
{
if
(
is.null
(
.genesysEnv
$
Authorization
))
{
stop
(
"You must first authorize with Genesys with user_login or client_login."
);
}
}
#' Login to Genesys as a user
#'
#' The authorization URL will open in a browser, ask the user to grant
...
...
@@ -149,6 +156,7 @@ client_login <- function() {
api_call
<-
function
(
path
,
method
=
"get"
)
{
check_auth
()
resp
<-
httr
::
GET
(
api_url
(
path
),
httr
::
add_headers
(
Authorization
=
.genesysEnv
$
Authorization
)
...
...
@@ -177,6 +185,7 @@ api_url <- function(path) {
}
get
<-
function
(
path
,
query
=
NULL
)
{
check_auth
()
resp
<-
httr
::
GET
(
api_url
(
path
),
query
=
query
,
httr
::
add_headers
(
Authorization
=
.genesysEnv
$
Authorization
))
...
...
@@ -195,6 +204,7 @@ get <- function(path, query = NULL) {
#'
#' @return httr response
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
...
...
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