If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Wednesday, September 12, 2012

How to easily deal with timestamp based URLs

Let me shortly describe the problem. You have to fetch data from some website which exposes the data based upon timestamped URL's. For the below use case the report is generated weekly on monday.

An example {server}:{port}/exports/classificationreport_20120924.csv

So you can't exactly hardcode the URL as a property but will need to generate it dynamically whenever a request is made to that resource. I've already used joda-time in the past so I decided to use it again.
public String getClassificationReportURL() {
   MutableDateTime now = new MutableDateTime();
   DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
   return getExportsBaseURL() + "classificationreport_" + fmt.print(now) + ".csv";

No comments:

Post a Comment