1 | <?php namespace Crunch\Salesforce; |
||
8 | class Client |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $salesforceLoginUrl; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $clientId; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $clientSecret; |
||
24 | |||
25 | /** |
||
26 | * @var AccessToken |
||
27 | */ |
||
28 | private $accessToken; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $baseUrl; |
||
34 | |||
35 | /** |
||
36 | * @var \GuzzleHttp\Client |
||
37 | */ |
||
38 | private $guzzleClient; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Create a sf client using a client config object or an array of params |
||
43 | * |
||
44 | * @param ClientConfigInterface $clientConfig |
||
45 | * @param \GuzzleHttp\Client $guzzleClient |
||
46 | * @throws \Exception |
||
47 | */ |
||
48 | public function __construct(ClientConfigInterface $clientConfig, \GuzzleHttp\Client $guzzleClient) |
||
56 | |||
57 | /** |
||
58 | * Create an instance of the salesforce client using the passed in config data |
||
59 | * |
||
60 | * @param $salesforceLoginUrl |
||
61 | * @param $clientId |
||
62 | * @param $clientSecret |
||
63 | * @return Client |
||
64 | */ |
||
65 | public static function create($salesforceLoginUrl, $clientId, $clientSecret) |
||
69 | |||
70 | /** |
||
71 | * Fetch a specific object |
||
72 | * |
||
73 | * @param string $objectType |
||
74 | * @param string $sfId |
||
75 | * @param array $fields |
||
76 | * @return string |
||
77 | */ |
||
78 | public function getRecord($objectType, $sfId, array $fields) |
||
85 | |||
86 | /** |
||
87 | * Fetch a blob field of a specific object |
||
88 | * |
||
89 | * @param string $objectType |
||
90 | * @param string $sfId |
||
91 | * @param string $blobField |
||
92 | * @return Response |
||
93 | */ |
||
94 | public function getBlob($objectType, $sfId, $blobField) |
||
101 | |||
102 | /** |
||
103 | * Execute an SOQL query and return the result set |
||
104 | * This will loop through large result sets collecting all the data so the query should be limited |
||
105 | * |
||
106 | * @param string|null $query |
||
107 | * @param string|null $next_url |
||
108 | * @return array |
||
109 | * @throws \Exception |
||
110 | */ |
||
111 | public function search($query = null, $next_url = null) |
||
131 | |||
132 | /** |
||
133 | * Make an update request |
||
134 | * |
||
135 | * @param string $object The object type to update |
||
136 | * @param string $id The ID of the record to update |
||
137 | * @param array $data The data to put into the record |
||
138 | * @return bool |
||
139 | * @throws \Exception |
||
140 | */ |
||
141 | public function updateRecord($object, $id, array $data) |
||
152 | |||
153 | /** |
||
154 | * Create a new object in salesforce |
||
155 | * |
||
156 | * @param string $object |
||
157 | * @param string $data |
||
158 | * @return bool |
||
159 | * @throws \Exception |
||
160 | */ |
||
161 | public function createRecord($object, $data) |
||
173 | |||
174 | /** |
||
175 | * Delete an object with th specified id |
||
176 | * |
||
177 | * @param $object |
||
178 | * @param $id |
||
179 | * @return bool |
||
180 | * @throws \Exception |
||
181 | */ |
||
182 | public function deleteRecord($object, $id) |
||
190 | |||
191 | /** |
||
192 | * Complete the oauth process by confirming the code and returning an access token |
||
193 | * |
||
194 | * @param $code |
||
195 | * @param $redirect_url |
||
196 | * @return array|mixed |
||
197 | * @throws \Exception |
||
198 | */ |
||
199 | public function authorizeConfirm($code, $redirect_url) |
||
215 | |||
216 | /** |
||
217 | * Get the url to redirect users to when setting up a salesforce access token |
||
218 | * |
||
219 | * @param $redirectUrl |
||
220 | * @return string |
||
221 | */ |
||
222 | public function getLoginUrl($redirectUrl) |
||
233 | |||
234 | /** |
||
235 | * Refresh an existing access token |
||
236 | * |
||
237 | * @return AccessToken |
||
238 | * @throws \Exception |
||
239 | */ |
||
240 | public function refreshToken() |
||
258 | |||
259 | /** |
||
260 | * @param AccessToken $accessToken |
||
261 | */ |
||
262 | public function setAccessToken(AccessToken $accessToken) |
||
267 | |||
268 | /** |
||
269 | * @param string $method |
||
270 | * @param string $url |
||
271 | * @param array $data |
||
272 | * @return mixed |
||
273 | * @throws AuthenticationException |
||
274 | * @throws RequestException |
||
275 | */ |
||
276 | private function makeRequest($method, $url, $data) |
||
297 | |||
298 | /** |
||
299 | * @return string |
||
300 | */ |
||
301 | private function getAuthHeader() |
||
309 | |||
310 | } |
||
311 |