Skip to content

Commit d6c5767

Browse files
authored
Merge pull request #61 from Jhut89/custom_curl_settings
Add custom curl settings options
2 parents 3b09d49 + bb17498 commit d6c5767

File tree

6 files changed

+137
-5
lines changed

6 files changed

+137
-5
lines changed

src/Mailchimp.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function account()
5353

5454
/**
5555
* Retrieves a new AuthorizedApps instance.
56+
*
5657
* @param null $app_id The ID for an app if retrieving an instance
58+
*
5759
* @return Resources\AuthorizedApps
5860
*/
5961
public function apps($app_id = null)
@@ -63,6 +65,7 @@ public function apps($app_id = null)
6365

6466
/**
6567
* @param null $workflow_id
68+
*
6669
* @return Resources\Automations
6770
*/
6871
public function automations($workflow_id = null)
@@ -72,6 +75,7 @@ public function automations($workflow_id = null)
7275

7376
/**
7477
* @param null $batch_id
78+
*
7579
* @return Resources\BatchOperations
7680
*/
7781
public function batches($batch_id = null)
@@ -81,6 +85,7 @@ public function batches($batch_id = null)
8185

8286
/**
8387
* @param null $batch_webhook_id
88+
*
8489
* @return Resources\BatchWebhooks
8590
*/
8691
public function batchWebhooks($batch_webhook_id = null)
@@ -90,6 +95,7 @@ public function batchWebhooks($batch_webhook_id = null)
9095

9196
/**
9297
* @param null $folder_id
98+
*
9399
* @return Resources\CampaignFolders
94100
*/
95101
public function campaignFolders($folder_id = null)
@@ -99,6 +105,7 @@ public function campaignFolders($folder_id = null)
99105

100106
/**
101107
* @param null $campaign_id
108+
*
102109
* @return Resources\Campaigns
103110
*/
104111
public function campaigns($campaign_id = null)
@@ -108,6 +115,7 @@ public function campaigns($campaign_id = null)
108115

109116
/**
110117
* @param null $site_id
118+
*
111119
* @return Resources\ConnectedSites
112120
*/
113121
public function connectedSites($site_id = null)
@@ -117,6 +125,7 @@ public function connectedSites($site_id = null)
117125

118126
/**
119127
* @param null $conversation_id
128+
*
120129
* @return Resources\Conversations
121130
*/
122131
public function conversations($conversation_id = null)
@@ -127,6 +136,7 @@ public function conversations($conversation_id = null)
127136

128137
/**
129138
* @param null $store_id
139+
*
130140
* @return Resources\EcommerceStores
131141
*/
132142
public function ecommerceStores($store_id = null)
@@ -136,6 +146,7 @@ public function ecommerceStores($store_id = null)
136146

137147
/**
138148
* @param null $outreach_id
149+
*
139150
* @return Resources\FacebookAds
140151
*/
141152
public function facebookAds($outreach_id = null)
@@ -145,6 +156,7 @@ public function facebookAds($outreach_id = null)
145156

146157
/**
147158
* @param null $file_id
159+
*
148160
* @return Resources\FileManagerFiles
149161
*/
150162
public function fileManagerFiles($file_id = null)
@@ -154,6 +166,7 @@ public function fileManagerFiles($file_id = null)
154166

155167
/**
156168
* @param null $folder_id
169+
*
157170
* @return Resources\FileManagerFolders
158171
*/
159172
public function fileManagerFolders($folder_id = null)
@@ -163,6 +176,7 @@ public function fileManagerFolders($folder_id = null)
163176

164177
/**
165178
* @param null $outreach_id
179+
*
166180
* @return Resources\GoogleAds
167181
*/
168182
public function googleAds($outreach_id = null)
@@ -172,6 +186,7 @@ public function googleAds($outreach_id = null)
172186

173187
/**
174188
* @param null $page_id
189+
*
175190
* @return Resources\LandingPages
176191
*/
177192
public function landingPages($page_id = null)
@@ -181,6 +196,7 @@ public function landingPages($page_id = null)
181196

182197
/**
183198
* @param null $list_id
199+
*
184200
* @return Resources\Lists
185201
*/
186202
public function lists($list_id = null)
@@ -198,6 +214,7 @@ public function ping()
198214

199215
/**
200216
* @param null $campaign_id
217+
*
201218
* @return Resources\Reports
202219
*/
203220
public function reports($campaign_id = null)
@@ -223,6 +240,7 @@ public function searchMembers()
223240

224241
/**
225242
* @param null $folder_id
243+
*
226244
* @return Resources\TemplateFolders
227245
*/
228246
public function templateFolders($folder_id = null)
@@ -232,6 +250,7 @@ public function templateFolders($folder_id = null)
232250

233251
/**
234252
* @param null $template_id
253+
*
235254
* @return Resources\Templates
236255
*/
237256
public function templates($template_id = null)
@@ -252,6 +271,7 @@ public function verifiedDomains($domain_name = null)
252271
/**
253272
* @param $client_id
254273
* @param $redirect_uri
274+
*
255275
* @return string
256276
*/
257277
public static function getAuthUrl(
@@ -273,6 +293,7 @@ public static function getAuthUrl(
273293
* @param $client_id
274294
* @param $client_sec
275295
* @param $redirect_uri
296+
*
276297
* @return string
277298
* @throws MailchimpException
278299
*/
@@ -298,6 +319,7 @@ public static function oauthExchange(
298319

299320
/**
300321
* @param $oauth_string
322+
*
301323
* @return mixed
302324
* @throws MailchimpException
303325
*/
@@ -324,6 +346,7 @@ private static function requestAccessToken($oauth_string)
324346

325347
/**
326348
* @param $access_token
349+
*
327350
* @return string
328351
* @throws MailchimpException
329352
*/
@@ -344,7 +367,10 @@ private static function requestKeyFromToken($access_token)
344367

345368
/**
346369
* @param MailchimpRequest $request
370+
*
347371
* @return MailchimpConnection
372+
*
373+
* @throws MailchimpException
348374
*/
349375
protected static function getStaticConnection(MailchimpRequest $request)
350376
{

src/Requests/HttpRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface HttpRequest
1212
/**
1313
* @param $name
1414
* @param $value
15+
*
1516
* @return mixed
1617
*/
1718
public function setOption($name, $value);
@@ -23,6 +24,7 @@ public function executeCurl();
2324

2425
/**
2526
* @param $name
27+
*
2628
* @return mixed
2729
*/
2830
public function getInfo($name);

src/Requests/MailchimpConnection.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ class MailchimpConnection implements HttpRequest
8181

8282
/**
8383
* MailchimpConnection constructor.
84-
* @param MailchimpRequest $request
84+
*
85+
* @param MailchimpRequest $request
8586
* @param MailchimpSettings|null $settings
87+
*
88+
* @throws MailchimpException
8689
*/
8790
public function __construct(MailchimpRequest &$request, MailchimpSettings &$settings = null)
8891
{
@@ -100,7 +103,10 @@ public function __construct(MailchimpRequest &$request, MailchimpSettings &$sett
100103

101104
/**
102105
* Prepares this connections handle for execution
106+
*
103107
* @return void
108+
*
109+
* @throws MailchimpException
104110
*/
105111
private function prepareHandle()
106112
{
@@ -124,6 +130,23 @@ private function prepareHandle()
124130

125131
// set the callback to run against each of the response headers
126132
$this->setOption(CURLOPT_HEADERFUNCTION, [&$this, "parseResponseHeader"]);
133+
134+
// if an custom curl settings are present set them now
135+
$this->setCustomHandleOptions($this->current_settings->getCustomCurlSettings());
136+
}
137+
138+
/**
139+
* Set custom curl handler options
140+
*
141+
* @param array $options
142+
*/
143+
private function setCustomHandleOptions(array $options)
144+
{
145+
if (!empty($options)) {
146+
foreach ($options as $option => $value) {
147+
$this->setOption($option, $value);
148+
}
149+
}
127150
}
128151

129152
/**
@@ -156,8 +179,8 @@ private function setHandlerOptionsForMethod()
156179

157180
/**
158181
* Executes a connection with the current request and settings
159-
* @throws MailchimpException
160182
* @return MailchimpResponse
183+
* @throws MailchimpException
161184
*/
162185
public function execute()
163186
{
@@ -167,7 +190,7 @@ public function execute()
167190
}
168191

169192
$this->http_code = $this->getInfo(CURLINFO_HTTP_CODE);
170-
$head_len = $this->getInfo(CURLINFO_HEADER_SIZE);
193+
$head_len = $this->getInfo(CURLINFO_HEADER_SIZE);
171194
$this->response_body = substr(
172195
$this->response,
173196
$head_len,
@@ -193,7 +216,9 @@ public function execute()
193216

194217
/**
195218
* Gets the currently set curl options by key
219+
*
196220
* @param $key
221+
*
197222
* @return mixed
198223
*/
199224
public function getCurrentOption($key)
@@ -204,6 +229,7 @@ public function getCurrentOption($key)
204229
/**
205230
* Bulk set curl options
206231
* Update current settings
232+
*
207233
* @param array $options
208234
*/
209235
public function setCurrentOptions($options)
@@ -254,6 +280,7 @@ public function close()
254280
*
255281
* @param $handle
256282
* @param $header
283+
*
257284
* @return int
258285
*/
259286
private function parseResponseHeader($handle, $header)
@@ -263,7 +290,7 @@ private function parseResponseHeader($handle, $header)
263290
if (count($header_array) == 2) {
264291
$this->pushToHeaders($header_array);
265292
}
266-
293+
267294
return $header_length;
268295
}
269296

0 commit comments

Comments
 (0)