001package burrows.api.finance.core; 002 003import org.apache.commons.lang3.StringUtils; 004 005import burrows.api.finance.model.RequestURLData; 006 007/** 008 * 009 * 010 * @author <a href="mailto:jaredsburrows@gmail.com">Jared Burrows</a> 011 * @since 0.0.1 012 */ 013public class RequestURLSerializer { 014 015 private final static String YAHOO_FINANCE_BASE_URL = "http://download.finance.yahoo.com/d/quotes.csv?s="; 016 private RequestURLData requestURLData; 017 private StringBuilder requestURL = new StringBuilder(); 018 019 public RequestURLSerializer(final RequestURLData requestURLData) { 020 this.requestURLData = requestURLData; 021 } 022 023 public String getURL() { 024 return requestURL.append(this.getCompany()) 025 .append(this.getFormat()) 026 .append(this.getQuotes()) 027 .toString(); 028 } 029 030 private String getCompany() { 031 switch (this.requestURLData.getCompany()) { 032 default: 033 case YAHOO: 034 return YAHOO_FINANCE_BASE_URL; 035 036 case GOOGLE: 037 throw new UnsupportedOperationException("Not supported."); 038 } 039 } 040 041 private String getFormat() { 042 switch (this.requestURLData.getFormat()) { 043 default: 044 case DEFAULT: 045 // do nothing 046 break; 047 case XML: 048 case JSON: 049 throw new UnsupportedOperationException("Not supported."); 050 } 051 return ""; 052 } 053 054 private String getQuotes() { 055 return StringUtils.join(this.requestURLData.getQuotes(), ","); 056 } 057}