-
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.
- Loading branch information
Jose Bovet
committed
Jul 30, 2015
1 parent
6602dcb
commit 0f3905c
Showing
7 changed files
with
246 additions
and
23 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
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,71 @@ | ||
package cl.kleedy.sbif.api | ||
|
||
import cl.kleedy.sbif.api.indicadores.UF | ||
|
||
/** | ||
* Operaciones con la unidad de fomento | ||
* Created by josebovet on 7/30/15. | ||
*/ | ||
interface UFOperations { | ||
|
||
/*** | ||
* Permite obtener el valor de la UF para el día actual. | ||
* @return | ||
* @throws SBIFClientException | ||
*/ | ||
def UF getUF() throws SBIFClientException; | ||
|
||
/*** | ||
* Permite obtener un listado con el valor de la UF para cada día del año que se indique. | ||
* @param year | ||
* @return | ||
* @throws SBIFClientException | ||
*/ | ||
def List<UF> getUFByYear(int year) throws SBIFClientException; | ||
|
||
/*** | ||
* Permite obtener un listado con el valor de la UF para cada día del mes y año que se indique. | ||
* @param year | ||
* @param month | ||
* @return | ||
* @throws SBIFClientException | ||
*/ | ||
def List<UF> getUFByYear(int year, int month) throws SBIFClientException; | ||
|
||
/*** | ||
* Permite obtener el valor de la UF para el día del mes y año que se indique. | ||
* @param year | ||
* @param month | ||
* @param day | ||
* @return | ||
* @throws SBIFClientException | ||
*/ | ||
def UF getUFByYear(int year, int month, int day) throws SBIFClientException; | ||
|
||
/*** | ||
* Permite obtener un listado con el valor de la UF para una fecha posterior al año que se indique. | ||
* @param year | ||
* @return | ||
* @throws SBIFClientException | ||
*/ | ||
def List<UF> getUFLaterYear(int year) throws SBIFClientException; | ||
|
||
/*** | ||
* Permite obtener un listado con el valor de la UF para una fecha posterior al mes y año que se indique. | ||
* @param year | ||
* @param month | ||
* @return | ||
* @throws SBIFClientException | ||
*/ | ||
def List<UF> getUFLaterYear(int year, int month) throws SBIFClientException; | ||
|
||
/*** | ||
* Permite obtener el valor de la UF para una fecha posterior al año que se indique. | ||
* @param year | ||
* @param month | ||
* @param day | ||
* @return UF | ||
* @throws SBIFClientException | ||
*/ | ||
def UF getUFLaterYear(int year, int month, int day) throws SBIFClientException; | ||
} |
87 changes: 87 additions & 0 deletions
87
src/main/groovy/cl/kleedy/sbif/api/impl/UFOperationTemplate.groovy
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,87 @@ | ||
package cl.kleedy.sbif.api.impl | ||
|
||
import cl.kleedy.sbif.api.BasicOperations | ||
import cl.kleedy.sbif.api.SBIFClientException | ||
import cl.kleedy.sbif.api.UFOperations | ||
import cl.kleedy.sbif.api.indicadores.UF | ||
import wslite.rest.RESTClient | ||
|
||
/** | ||
* Implemetacion operaciones UF | ||
* Created by josebovet on 7/30/15. | ||
*/ | ||
class UFOperationTemplate extends BasicOperations implements UFOperations { | ||
|
||
UFOperationTemplate(RESTClient restClient, String apiKey) { | ||
super(restClient, apiKey) | ||
} | ||
|
||
@Override | ||
UF getUF() throws SBIFClientException { | ||
return getResource([:], 'uf', 'getUFs').first() | ||
} | ||
|
||
@Override | ||
List<UF> getUFByYear(int year) throws SBIFClientException { | ||
return getUFByDate(year,0,0) | ||
} | ||
|
||
@Override | ||
List<UF> getUFByYear(int year, int month) throws SBIFClientException { | ||
return getUFByDate(year, month,0) | ||
} | ||
|
||
@Override | ||
UF getUFByYear(int year, int month, int day) throws SBIFClientException { | ||
return getUFByDate(year,month,day).first() | ||
} | ||
|
||
private List<UF> getUFByDate(int year, int month, int day){ | ||
def params = ['year': year] | ||
if (month) params.month = month | ||
if (day) params.day = day | ||
return getResource(params, 'uf', 'getUFs') | ||
} | ||
|
||
@Override | ||
List<UF> getUFLaterYear(int year) throws SBIFClientException { | ||
return getUFLaterYear(year,0) | ||
} | ||
|
||
@Override | ||
List<UF> getUFLaterYear(int year, int month) throws SBIFClientException { | ||
return getUFLaterByDate(year, month,0) | ||
} | ||
|
||
@Override | ||
UF getUFLaterYear(int year, int month, int day) throws SBIFClientException { | ||
return getUFLaterByDate(year, month, day).first() | ||
} | ||
|
||
private List<UF> getUFLaterByDate(int year, int month, int day) throws SBIFClientException { | ||
def params = ['year': year] | ||
if (month) params.month = month | ||
if (day) params.day = day | ||
return getResource(params, 'uf','/posteriores','getUFs') | ||
} | ||
|
||
/*** | ||
* Llama al recurso UF, parseando la respuesta en formato json | ||
* @param url | ||
* @return List<UF> | ||
*/ | ||
private List<UF> getUFs(String url) throws SBIFClientException { | ||
def ufList = call(url).json.UFs | ||
def list = [] | ||
ufList.each() { data -> | ||
def v = data.Valor.trim() | ||
if (v.any { it == ',' }) { | ||
v = v.substring(0, v.indexOf(',')) | ||
} | ||
//TODO revisar tipo de mascara para Double | ||
v = (v != null && v.length() > 0) ? Double.parseDouble(v.replace(".", '')) : 0 | ||
list << new UF(valor: v, fecha: Date.parse('yyyy-MM-dd', data.Fecha)) | ||
} | ||
return list | ||
} | ||
} |
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,7 @@ | ||
package cl.kleedy.sbif.api.indicadores | ||
|
||
/** | ||
* Created by josebovet on 7/30/15. | ||
*/ | ||
class UF extends Indicador { | ||
} |
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,71 @@ | ||
package cl.kleedy.sbif.api | ||
|
||
/** | ||
* Created by josebovet on 7/30/15. | ||
*/ | ||
class UFClientSpec extends SBIFClientSpec { | ||
|
||
UFOperations client | ||
|
||
void setup() { | ||
client = sbifTemplate.getUfOperations() | ||
} | ||
|
||
void "should retrieve today UF"() { | ||
when: | ||
def uf = client.getUF() | ||
uf.valor >= 24000 | ||
|
||
then: | ||
uf.fecha != null | ||
} | ||
|
||
void "should retrieve UF list from 2015"() { | ||
when: | ||
def ufList = client.getUFByYear(2015) | ||
|
||
then: | ||
ufList.size() >= 0 | ||
} | ||
|
||
void "should retrieve UF list from 2015-05"() { | ||
when: | ||
def ufList = client.getUFByYear(2015,5) | ||
|
||
then: | ||
ufList.size() == 31 | ||
} | ||
|
||
void "should retrieve UF list from 2015-5-5"() { | ||
when: | ||
def uf = client.getUFByYear(2015,5,5) | ||
|
||
then: | ||
uf.valor >= 24779.0 | ||
} | ||
|
||
void "should retrieve UF list later from 2014"() { | ||
//TODO test with 2015 404 | ||
when: | ||
def ufList = client.getUFLaterYear(2014) | ||
|
||
then: | ||
ufList.size()==221 | ||
} | ||
|
||
void "should retrieve UF list later from 2014-5"() { | ||
when: | ||
def ufList = client.getUFLaterYear(2014,5) | ||
|
||
then: | ||
ufList.size()>=0 | ||
} | ||
|
||
void "should retrieve UF list later from 2014-5-6"() { | ||
when: | ||
def uf = client.getUFLaterYear(2014,5,5) | ||
|
||
then: | ||
uf.valor >= 0 | ||
} | ||
} |