Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept data-raw #13

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Console/Commands/CurlCommand.php
Expand Up @@ -7,7 +7,7 @@

class CurlCommand extends Command
{
protected $signature = 'shift:curl {--X|request=} {--G|get} {--H|header=*} {--d|data=*} {--data-urlencode=*} {--F|form=*} {--digest} {--basic} {--connect-timeout=} {--max-timeout=} {--retry=} {--s|silent} {--u|user=} {--L|location} {url}';
protected $signature = 'shift:curl {--X|request=} {--G|get} {--H|header=*} {--d|data=*} {--data-raw=*} {--data-urlencode=*} {--F|form=*} {--digest} {--basic} {--connect-timeout=} {--max-timeout=} {--retry=} {--s|silent} {--u|user=} {--L|location} {--compressed} {--insecure} {url}';

protected $description = 'Convert a UNIX curl request to an HTTP Client request';

Expand All @@ -29,7 +29,7 @@ private function gatherOptions()
'method' => $this->option('get') ? 'GET' : $this->option('request'),
'url' => $this->argument('url'),
'headers' => $this->option('header'),
'data' => $this->option('data'),
'data' => count($this->option('data-raw')) > 0 ? $this->option('data-raw') : $this->option('data'),
'dataUrlEncode' => $this->option('data-urlencode'),
'fields' => $this->option('form'),
'digest' => $this->option('digest'),
Expand All @@ -39,6 +39,8 @@ private function gatherOptions()
'retry' => $this->option('retry'),
'silent' => $this->option('silent'),
'user' => $this->option('user'),
'compressed' => $this->option('compressed'),
'insecure' => $this->option('insecure'),
];
}
}
3 changes: 3 additions & 0 deletions tests/Feature/Console/Commands/CurlCommandTest.php
Expand Up @@ -27,6 +27,7 @@ public function curlCommandFixtures()
'POST request' => ['basic-post'],
'POST request with data' => ['post-with-data'],
'POST request with JSON data' => ['post-json'],
'POST request with JSON data-raw' => ['post-json-data-raw'],
'POST request with multipart/form-data' => ['post-with-form-data'],
'Request with data defaults to POST' => ['request-with-data'],
'Request with form fields defaults to POST' => ['request-with-form-data'],
Expand All @@ -42,6 +43,8 @@ public function curlCommandFixtures()
'Entire transaction timeout' => ['max-timeout'],
'Ignore location flag' => ['ignore-location-flag'],
'Missing URL scheme' => ['missing-url-scheme'],
'GET request with compressed option' => ['with-compressed-option'],
'GET request with insecure option' => ['with-insecure-option'],
];
}

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/post-json-data-raw.in
@@ -0,0 +1 @@
curl -X POST --header 'Content-Type: application/json' --data-raw '{"messages": ["a","b","c"]}' 'https://api.com'
2 changes: 2 additions & 0 deletions tests/fixtures/post-json-data-raw.out
@@ -0,0 +1,2 @@
Http::withBody('{"messages": ["a","b","c"]}')
->post('https://api.com');
1 change: 1 addition & 0 deletions tests/fixtures/with-compressed-option.in
@@ -0,0 +1 @@
curl -H 'Accept: application/json' https://example.com --compressed
2 changes: 2 additions & 0 deletions tests/fixtures/with-compressed-option.out
@@ -0,0 +1,2 @@
Http::acceptJson()
->get('https://example.com');
1 change: 1 addition & 0 deletions tests/fixtures/with-insecure-option.in
@@ -0,0 +1 @@
curl -H 'Accept: application/json' https://example.com --insecure
2 changes: 2 additions & 0 deletions tests/fixtures/with-insecure-option.out
@@ -0,0 +1,2 @@
Http::acceptJson()
->get('https://example.com');