在Elm中结合两个不同的API请求

时间:2019-06-21 08:37:37

标签: elm

我有一个依赖于第三方API的客户端,我需要将两个调用合并到一个记录中(或能够在一个视图中显示两个调用的内容)。

我没有Elm的经验,但了解Task的概念可能会有所帮助。我还考虑过将数据收集到两个不同的模型中,但这似乎给我显示数据带来了一些麻烦。

这是我要合并的资源

my @NAMES = ("Name", "VirusDefinitions", "IPAddress", "OperatingSystem", "AgentVersion", "Infected", "LastScanTime","LastUpdateTime","WorstInfectionIDX","LastVirusTime","Threats","StartDateTime","StopDateTime","TotalFiles","Duration","AutoProtectEnabled" );

open( FIL, "< $FILEA" )|| die "cant open file $!" ;
while (defined ($_ = <FIL>)) {
foreach my $N (@NAMES) {
#print "looking for $N\n" ;
    if  ($_ =~ /$N/) {
    if ($DEBUG gt 2){print "report: Looking for $N\n";}
    $_ =~ /$N(.*)$N/;
    my $TMP = $1;
    $TMP =~ s/[\$#@~!&*()<>\[\];,?^ `\\\/]+//g;
    #Switch that has to be extended if the array NAMES is extended
        if ($N eq "Name") {
        $NAME=$TMP; 
        }elsif ($N eq "VirusDefinitions"){ 
        $VIRUSDEF=$TMP;
        }elsif ($N eq "IPAddress") {
        $IP=$TMP;
        }elsif ($N eq "OperatingSystem") {
        $OS=$TMP;
        }elsif ($N eq "AgentVersion") {
        $AGNT=$TMP;
        }elsif ($N eq "Infected") {
        $INFEC=$TMP;
        }elsif ($N eq "LastScanTime") {
        $LAST=$TMP;
        }elsif ($N eq "LastUpdateTime"){
        $LASTUP=$TMP;
        }elsif ($N eq "WorstInfectionIDX") {
        $winfid=$TMP;
        }elsif ($N eq "LastVirusTime") {
        $lastvirust=$TMP;
        }elsif ($N eq "Threats"){
        $threats=$TMP;
        }elsif ($N eq "StartDateTime"){
        $starttime=$TMP;
        }elsif ($N eq "StopDateTime"){
        $stoptime=$TMP;
        }elsif ($N eq "TotalFiles"){
        $totalfil=$TMP;
        }elsif ($N eq "Duration"){
        $scandur=$TMP;
        }elsif ($N eq "AutoProtectEnabled") {
        $autoprot=$TMP;
        $CUST =~ s/\W//g; #We shave special characters off of the $CUST variable and return normal characters
        print LOG "$today $time, <LastUpdateTime><$LASTUP><ProjectNr><$PROJNO><Site><$CUST><Device><$NAME><ThreatsFound><$threats><Definition><$VIRUSDEF><IpAddress><$IP><OS><$OS><AgentVersion><$AGNT><Infected><$INFEC><WorstInfectionID><$winfid><LastVirusDetectionTime><$lastvirust><ScanStartTime><$starttime><ScanStopTime><$stoptime><ScanDuration><$scandur><LastScan><$LAST><AutoProtectionEnabled><$autoprot><FilesScanned><$totalfil><FileName><$FILE1>\n" ;
        #init variables again
        init
        }

我想显示具有data2中增强的c变量的data1。

预期结果

data1 = [{a, b, c1:{x1,y1}, c2:{x2,y2}}, ...]
data2 = [{x1, y1, z1, q1}, {x2, y2, z2, q2}, ...]

是否正在组合本地服务器上的资源,然后将数据作为一种模型来获取是最简单的选择?

0 个答案:

没有答案