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
708b5a60
Commit
708b5a60
authored
8 years ago
by
Alexander Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Converts Json service to injected service in RestClient
parent
0c920af1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ROADMAP.txt
+4
-5
4 additions, 5 deletions
ROADMAP.txt
salesforce.services.yml
+1
-1
1 addition, 1 deletion
salesforce.services.yml
src/Rest/RestClient.php
+60
-26
60 additions, 26 deletions
src/Rest/RestClient.php
src/Rest/RestClientInterface.php
+10
-4
10 additions, 4 deletions
src/Rest/RestClientInterface.php
with
75 additions
and
36 deletions
ROADMAP.txt
+
4
−
5
View file @
708b5a60
...
...
@@ -26,7 +26,7 @@ Additional details:
- replace strings with consistent, drupal-wide text
e.g. "-- Select --", "--" . t('Select') . "--", "Select Object Type", etc.
Nobody wants to translate all those.
- Replace hooks with interfaces, plugins, event subscribers, etc.
- Automatically pre-add all required Salesforce fields to mappings
...
...
@@ -40,17 +40,17 @@ Additional details:
- easier for other modules to extend, alter behavior
- standardized, consolidated approach
- Since Drupal Queue Interface is a properly OOP now, we should create a
- Since Drupal Queue Interface is a properly OOP now, we should create a
Salesforce Queue implementation that unlocks the full potential of Salesforce API
Whether or not this is dependent on SOAP is somewhat irrelevant, as REST and SOAP
could use the same queue interface, regardless of whether REST can leverage
could use the same queue interface, regardless of whether REST can leverage
the advanced features of SOAP.
- Conversions to do when https://drupal.org/node/1972304 lands
- Migration paths for field mappings
-- wait for dust to settle on field mapping schema
- Migration paths for mapping object
-- wait for dust to settle on mapping object schema
...
...
@@ -203,4 +203,3 @@ salesforce.routing.yml
src/Rest/RestClient.php
58: * @TODO: Consider making a test API call.
149: // @TODO: convert this into Dependency Injection
This diff is collapsed.
Click to expand it.
salesforce.services.yml
+
1
−
1
View file @
708b5a60
services
:
salesforce.client
:
class
:
Drupal\salesforce\Rest\RestClient
arguments
:
[
'
@http_client'
,
'
@config.factory'
,
'
@state'
,
'
@cache.default'
]
arguments
:
[
'
@http_client'
,
'
@config.factory'
,
'
@state'
,
'
@cache.default'
,
'
@serialization.json'
]
This diff is collapsed.
Click to expand it.
src/Rest/RestClient.php
+
60
−
26
View file @
708b5a60
...
...
@@ -23,32 +23,82 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class
RestClient
implements
RestClientInterface
{
/**
* Reponse object.
*
* @var \GuzzleHttp\Psr7\Response
*/
public
$response
;
/**
* GuzzleHttp client.
*
* @var \GuzzleHttp\ClientInterface
*/
protected
$httpClient
;
/**
* Config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected
$configFactory
;
/**
* Salesforce API URL.
*
* @var Drupal\Core\Url
*/
protected
$url
;
/**
* Salesforce config entity.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
private
$config
;
/**
* editable version of config entity.
*
* @var \Drupal\Core\Config\Config
*/
private
$configEditable
;
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface $state
*/
private
$state
;
/**
* The cache service.
*
* @var Drupal\Core\Cache\CacheBackendInterface cache
*/
protected
$cache
;
/**
* The JSON serializer service.
*
* @var \Drupal\Component\Serialization\Json $json
*/
protected
$json
;
const
CACHE_LIFETIME
=
300
;
/**
* Constructor which initializes the consumer.
*
* @param \Drupal\Core\Http\Client $http_client
* The config factory.
* @param \Guzzle\Http\ClientInterface $http_client
* The config factory.
* {@inheritdoc}
*/
public
function
__construct
(
ClientInterface
$http_client
,
ConfigFactoryInterface
$config_factory
,
StateInterface
$state
,
CacheBackendInterface
$cache
)
{
public
function
__construct
(
ClientInterface
$http_client
,
ConfigFactoryInterface
$config_factory
,
StateInterface
$state
,
CacheBackendInterface
$cache
,
Json
$json
)
{
$this
->
configFactory
=
$config_factory
;
$this
->
httpClient
=
$http_client
;
$this
->
config
=
$this
->
configFactory
->
get
(
'salesforce.settings'
);
$this
->
configEditable
=
$this
->
configFactory
->
getEditable
(
'salesforce.settings'
);
$this
->
state
=
$state
;
$this
->
cache
=
$cache
;
$this
->
json
=
$json
;
return
$this
;
}
...
...
@@ -62,22 +112,7 @@ class RestClient implements RestClientInterface {
}
/**
* Make a call to the Salesforce REST API.
*
* @param string $path
* Path to resource.
* @param array $params
* Parameters to provide.
* @param string $method
* Method to initiate the call, such as GET or POST. Defaults to GET.
* @param bool $returnObject
* If true, return a Drupal\salesforce\Rest\RestResponse;
* Otherwise, return json-decoded response body only.
* Defaults to FALSE for backwards compatibility.
*
* @return mixed
*
* @throws GuzzleHttp\Exception\RequestException
* {@inheritdoc}
*/
public
function
apiCall
(
$path
,
array
$params
=
[],
$method
=
'GET'
,
$returnObject
=
FALSE
)
{
if
(
!
$this
->
getAccessToken
())
{
...
...
@@ -148,8 +183,7 @@ class RestClient implements RestClientInterface {
];
$data
=
NULL
;
if
(
!
empty
(
$params
))
{
// @TODO: convert this into Dependency Injection
$data
=
Json
::
encode
(
$params
);
$data
=
$this
->
json
->
encode
(
$params
);
}
return
$this
->
httpRequest
(
$url
,
$data
,
$headers
,
$method
);
}
...
...
@@ -188,7 +222,7 @@ class RestClient implements RestClientInterface {
protected
function
getErrorData
(
RequestException
$e
)
{
$response
=
$e
->
getResponse
();
$response_body
=
$response
->
getBody
()
->
getContents
();
$data
=
J
son
::
decode
(
$response_body
);
$data
=
$this
->
j
son
->
decode
(
$response_body
);
if
(
!
empty
(
$data
[
0
]))
{
$data
=
$data
[
0
];
}
...
...
This diff is collapsed.
Click to expand it.
src/Rest/RestClientInterface.php
+
10
−
4
View file @
708b5a60
...
...
@@ -27,11 +27,17 @@ interface RestClientInterface {
* Constructor which initializes the consumer.
*
* @param \Drupal\Core\Http\Client $http_client
* The
config factory
.
* The
HTTP Client
.
* @param \Guzzle\Http\ClientInterface $http_client
* The config factory.
*/
public
function
__construct
(
ClientInterface
$http_client
,
ConfigFactoryInterface
$config_factory
,
StateInterface
$state
,
CacheBackendInterface
$cache
);
* The Guzzle Client.
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Core\Cache\CacheBackendInterface cache
* The cache service.
* @param \Drupal\Component\Serialization\Json $json
* The JSON serializer service.
*/
public
function
__construct
(
ClientInterface
$http_client
,
ConfigFactoryInterface
$config_factory
,
StateInterface
$state
,
CacheBackendInterface
$cache
,
Json
$json
);
/**
* Determine if this SF instance is fully configured.
...
...
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