Skip to content

Commit

Permalink
addition of the upload method
Browse files Browse the repository at this point in the history
  • Loading branch information
nnjeim committed Oct 11, 2021
1 parent 1c8c770 commit 1c46ae8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ All notable changes will be documented in this file
## 1.1.0 - 2021-09-19
- General refactoring
- Addition of the FetchInterface class.

## 1.1.1 - 2021-10-11
- Addition of the upload method.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"authors": [
{
"name": "Najm Njeim",
"email": "nnjeim@nnjeim.com",
"email": "nnjeim@nnjeim.net",
"role": "Developer"
}
],
Expand Down
35 changes: 26 additions & 9 deletions src/FetchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,30 @@ public function setData(array $data): self
*/
public function __call($method, $args)
{
$bodyFormats = [
'get' => 'query',
'post' => 'form_params',
'put' => 'form_params',
'delete' => 'query',
'upload' => 'multipart',
$methods = [
'get' => [
'bodyFormat' => 'query',
'verb' => 'get',
],
'post' => [
'bodyFormat' => 'form_params',
'verb' => 'post',
],
'put' => [
'bodyFormat' => 'form_params',
'verb' => 'put',
],
'delete' => [
'bodyFormat' => 'query',
'verb' => 'delete',
],
'upload' => [
'bodyFormat' => 'multipart',
'verb' => 'post',
],
];

if (in_array(strtolower($method), array_keys($bodyFormats))) {
if (in_array(strtolower($method), array_keys($methods))) {

[$url, $data] = [...$args] + ['', null];

Expand All @@ -109,9 +124,11 @@ public function __call($method, $args)
$this->setData($data);
}

['verb' => $verb, 'bodyFormat' => $bodyFormat] = $methods[strtolower($method)];

return $this
->setMethod($method)
->setBodyFormat($bodyFormats[$method])
->setMethod($verb)
->setBodyFormat($bodyFormat)
->fetch();
}

Expand Down

0 comments on commit 1c46ae8

Please sign in to comment.