File tree Expand file tree Collapse file tree 2 files changed +80
-3
lines changed
Expand file tree Collapse file tree 2 files changed +80
-3
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,43 @@ $data = $rates->getRates();
8484echo print_r( $data, true );
8585```
8686
87- Por ahora el resultado es el XML de indicadores económicos, pero se está trabajando en mejorarlo.
87+
88+ Esto imprime el siguiente objecto:
89+
90+ ```
91+ stdClass Object
92+ (
93+ [dolar] => stdClass Object
94+ (
95+ [venta] => stdClass Object
96+ (
97+ [valor] => 558.05000000
98+ [fecha] => 2023-02-27T00:00:00-06:00
99+ )
100+
101+ [compra] => stdClass Object
102+ (
103+ [valor] => 556.40000000
104+ [fecha] => 2023-02-28T00:00:00-06:00
105+ )
106+
107+ )
108+
109+ )
110+
111+ Acceder a los valores:
112+ ```
113+ echo "Dólar venta: " . $data->dolar->venta->valor;
114+ echo PHP_EOL;
115+ echo "Dólar compra: " . $data->dolar->venta->valor;
116+ echo PHP_EOL;
117+ ```
118+
119+ El resultado sería:
120+ ```
121+ Dólar venta: 558.05000000
122+ Dólar compra: 558.05000000
123+ ```
88124
89125
90126### Pull Request are Welcome | Los Pull Request son bienvenidos
Original file line number Diff line number Diff line change @@ -15,7 +15,48 @@ public function getRates(){
1515 }
1616 $ this ->url = rtrim ( $ this ->url , '& ' );
1717 }
18- echo print_r ( $ this ->url , true );
19- return file_get_contents ( $ this ->url );
18+
19+ $ data = file_get_contents ( $ this ->url );
20+ $ xml = new DOMDocument ();
21+ $ xml ->loadXML ( $ data );
22+
23+ $ dolar_venta = $ xml ->getElementsByTagName ('INGC011_CAT_INDICADORECONOMIC ' )
24+ ->item (0 )
25+ ->getElementsByTagName ('NUM_VALOR ' )
26+ ->item (0 )
27+ ->nodeValue ;
28+
29+ $ dolar_venta_fecha = $ xml ->getElementsByTagName ('INGC011_CAT_INDICADORECONOMIC ' )
30+ ->item (0 )
31+ ->getElementsByTagName ('DES_FECHA ' )
32+ ->item (0 )
33+ ->nodeValue ;
34+
35+ $ dolar_compra = $ xml ->getElementsByTagName ('INGC011_CAT_INDICADORECONOMIC ' )
36+ ->item (1 )
37+ ->getElementsByTagName ('NUM_VALOR ' )
38+ ->item (0 )
39+ ->nodeValue ;
40+
41+ $ dolar_compra_fecha = $ xml ->getElementsByTagName ('INGC011_CAT_INDICADORECONOMIC ' )
42+ ->item (1 )
43+ ->getElementsByTagName ('DES_FECHA ' )
44+ ->item (0 )
45+ ->nodeValue ;
46+
47+ $ response = (object ) [
48+ 'dolar ' => (object ) [
49+ 'venta ' => (object ) [
50+ 'valor ' => $ dolar_venta ,
51+ 'fecha ' => $ dolar_venta_fecha
52+ ],
53+ 'compra ' => (object ) [
54+ 'valor ' => $ dolar_compra ,
55+ 'fecha ' => $ dolar_compra_fecha
56+ ]
57+ ]
58+ ];
59+
60+ return $ response ;
2061 }
2162}
You can’t perform that action at this time.
0 commit comments