forked from foss42/apidash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request foss42#424 from ketan-sonar/resolve-issue-126
Resolve issue foss42#126
- Loading branch information
Showing
21 changed files
with
616 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:apidash/consts.dart'; | ||
import 'package:apidash/models/models.dart'; | ||
import 'package:apidash/utils/utils.dart'; | ||
import 'package:curl_converter/curl_converter.dart'; | ||
|
||
class CurlFileImport { | ||
HttpRequestModel? getHttpRequestModel(String content) { | ||
content = content.trim(); | ||
try { | ||
final curl = Curl.parse(content); | ||
final url = stripUriParams(curl.uri); | ||
final method = HTTPVerb.values.byName(curl.method.toLowerCase()); | ||
|
||
final headers = curl.headers?.entries | ||
.map((entry) => NameValueModel( | ||
name: entry.key, | ||
value: entry.value, | ||
)) | ||
.toList(); | ||
|
||
final params = curl.uri.queryParameters.entries | ||
.map((entry) => NameValueModel( | ||
name: entry.key, | ||
value: entry.value, | ||
)) | ||
.toList(); | ||
|
||
// TODO: parse curl data to determine the type of body | ||
final body = curl.data; | ||
|
||
return HttpRequestModel( | ||
method: method, | ||
url: url, | ||
headers: headers, | ||
params: params, | ||
body: body, | ||
); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:apidash/consts.dart'; | ||
import 'package:apidash/models/models.dart'; | ||
import 'curl/curl.dart'; | ||
|
||
class Importer { | ||
Future<HttpRequestModel?> getHttpRequestModel( | ||
ImportFormat fileType, | ||
String content, | ||
) async { | ||
switch (fileType) { | ||
case ImportFormat.curl: | ||
return CurlFileImport().getHttpRequestModel(content); | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:apidash/consts.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:file_selector/file_selector.dart'; | ||
import 'drag_and_drop_area.dart'; | ||
import 'dropdown_import_format.dart'; | ||
|
||
showImportDialog({ | ||
required BuildContext context, | ||
required ImportFormat importFormat, | ||
Function(ImportFormat?)? onImportFormatChange, | ||
Function(XFile)? onFileDropped, | ||
}) { | ||
showDialog( | ||
context: context, | ||
builder: (context) { | ||
return AlertDialog( | ||
contentPadding: const EdgeInsets.all(12), | ||
content: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
const Text("Import "), | ||
DropdownButtonImportFormat( | ||
importFormat: importFormat, | ||
onChanged: onImportFormatChange, | ||
), | ||
], | ||
), | ||
DragAndDropArea( | ||
onFileDropped: onFileDropped, | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
); | ||
} |
Oops, something went wrong.