Requests return dynamic

This commit is contained in:
2021-08-01 21:38:15 -06:00
parent 54d871a006
commit aa5a7f9378
6 changed files with 28 additions and 32 deletions

View File

@@ -3,7 +3,6 @@ package requests_externs;
import haxe.extern.EitherType;
import python.Dict;
import python.KwArgs;
import requests_externs.Response;
typedef NativeRequestKwArgs = {
?headers:Dict<String, String>
@@ -15,12 +14,12 @@ typedef RequestKwArgs = {
@:pythonImport("requests")
extern class NativeRequests {
public static function get(url:String, params:Dict<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):NativeResponse;
public static function get(url:String, params:Dict<String, String>, ?kwArgs:KwArgs<NativeRequestKwArgs>):Dynamic;
}
class Requests {
public static function get(url:String, params:Map<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):NativeResponse {
return NativeRequests.get(url, mapToDict(params), kwArgs);
public static function get(url:String, params:Map<String, String>, ?kwArgs:RequestKwArgs):Dynamic {
return NativeRequests.get(url, mapToDict(params), kwArgsToNativeKwArgs(kwArgs));
}
static function mapToDict(?map:Map<String, String>) {
@@ -33,7 +32,9 @@ class Requests {
return dict;
}
static function kwArgsToNativeKwArgs(kwArgs:RequestKwArgs) {
static function kwArgsToNativeKwArgs(?kwArgs:RequestKwArgs) {
if (kwArgs == null)
return null;
return {
headers: mapToDict(kwArgs.headers)
};

View File

@@ -1,6 +0,0 @@
package requests_externs;
@:pythonImport("requests.Response")
extern class NativeResponse {}
typedef Response = {};