Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
salesforce-3257058
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
salesforce-3257058
Commits
988e6b9e
Commit
988e6b9e
authored
7 years ago
by
Aaron Bauman
Browse files
Options
Downloads
Patches
Plain Diff
Change apiCall() to allow RestClient to be used for custom endpoints
parent
ebf649bf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Rest/RestClient.php
+14
-9
14 additions, 9 deletions
src/Rest/RestClient.php
src/Rest/RestClientInterface.php
+8
-0
8 additions, 0 deletions
src/Rest/RestClientInterface.php
with
22 additions
and
9 deletions
src/Rest/RestClient.php
+
14
−
9
View file @
988e6b9e
...
...
@@ -107,8 +107,6 @@ class RestClient implements RestClientInterface {
/**
* Determine if this SF instance is fully configured.
*
* @TODO: Consider making a test API call.
*/
public
function
isAuthorized
()
{
return
$this
->
getConsumerKey
()
&&
$this
->
getConsumerSecret
()
&&
$this
->
getRefreshToken
();
...
...
@@ -122,8 +120,15 @@ class RestClient implements RestClientInterface {
$this
->
refreshToken
();
}
if
(
strpos
(
$path
,
'/'
)
===
0
)
{
$url
=
$this
->
getInstanceUrl
()
.
$path
;
}
else
{
$url
=
$this
->
getApiEndPoint
()
.
$path
;
}
try
{
$this
->
response
=
new
RestResponse
(
$this
->
apiHttpRequest
(
$
path
,
$params
,
$method
));
$this
->
response
=
new
RestResponse
(
$this
->
apiHttpRequest
(
$
url
,
$params
,
$method
));
}
catch
(
RequestException
$e
)
{
// RequestException gets thrown for any response status but 2XX.
...
...
@@ -141,7 +146,7 @@ class RestClient implements RestClientInterface {
// throws anything but a RequestException, let it bubble up.
$this
->
refreshToken
();
try
{
$this
->
response
=
new
RestResponse
(
$this
->
apiHttpRequest
(
$
path
,
$params
,
$method
));
$this
->
response
=
new
RestResponse
(
$this
->
apiHttpRequest
(
$
url
,
$params
,
$method
));
}
catch
(
RequestException
$e
)
{
$this
->
response
=
$e
->
getResponse
();
...
...
@@ -165,8 +170,9 @@ class RestClient implements RestClientInterface {
/**
* Private helper to issue an SF API request.
*
* @param string $path
* Path to resource.
* @param string $url
* Fully-qualified URL to resource.
*
* @param array $params
* Parameters to provide.
* @param string $method
...
...
@@ -175,11 +181,10 @@ class RestClient implements RestClientInterface {
* @return GuzzleHttp\Psr7\Response
* Response object.
*/
protected
function
apiHttpRequest
(
$
path
,
array
$params
,
$method
)
{
protected
function
apiHttpRequest
(
$
url
,
array
$params
,
$method
)
{
if
(
!
$this
->
getAccessToken
())
{
throw
new
\Exception
(
'Missing OAuth Token'
);
}
$url
=
$this
->
getApiEndPoint
()
.
$path
;
$headers
=
[
'Authorization'
=>
'OAuth '
.
$this
->
getAccessToken
(),
...
...
@@ -376,7 +381,7 @@ class RestClient implements RestClientInterface {
*
* @throws Exception
*/
p
rotected
function
refreshToken
()
{
p
ublic
function
refreshToken
()
{
$refresh_token
=
$this
->
getRefreshToken
();
if
(
empty
(
$refresh_token
))
{
throw
new
\Exception
(
t
(
'There is no refresh token.'
));
...
...
This diff is collapsed.
Click to expand it.
src/Rest/RestClientInterface.php
+
8
−
0
View file @
988e6b9e
...
...
@@ -23,6 +23,14 @@ interface RestClientInterface {
*
* @param string $path
* Path to resource.
*
* If $path begins with a slash, the resource will be considered absolute,
* and only the instance URL will be pre-pended. This can be used, for
* example, to issue an API call to a custom Apex Rest endpoint.
*
* If $path does not begin with a slash, the resource will be considered
* relative and the Rest API Endpoint will be pre-pended.
*
* @param array $params
* Parameters to provide.
* @param string $method
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment