avatar

934

Retrieve account configuration from my.jbidwatcher.com.

by mrs, 30 May, 2009 12:25 AM
927 934  
55 import com.jbidwatcher.util.Parameters;
66 import com.jbidwatcher.util.StringTools;
77 import com.jbidwatcher.util.Constants;
8 import com.jbidwatcher.util.ZoneDate;
89 import com.jbidwatcher.util.html.JHTML;
910 import com.jbidwatcher.util.queue.MQFactory;
1011 import com.jbidwatcher.util.queue.MessageQueue;
------
2122 import java.io.IOException;
2223 import java.net.URLEncoder;
2324 import java.net.HttpURLConnection;
25 import java.util.Date;
2426 
2527 /**
2628  * Created by IntelliJ IDEA.
------
3739   private static final String ITEM_UPLOAD_URL = "http://my.jbidwatcher.com/upload/listing";
3840   private String mSyncQueueURL = null;
3941   private String mReportQueueURL = null;
42   private boolean mUseSSL = false;
43   private boolean mUploadHTML = false;
44   private boolean mUseServerParser = false;
45   private boolean mGixen = false;
46   private boolean mReadSnipesFromServer = false;
47   private ZoneDate mExpiry;
4048 
4149   private Http http() {
4250     if(mNet == null) {
------
193201     });
194202   }
195203 
204   public void getAccountInfo() {
205     StringBuffer sb = http().get("http://my.jbidwatcher.com/services/account");
206     XMLElement xml = new XMLElement();
207     xml.parseString(sb.toString());
208     XMLElement sync = xml.getChild("syncq");
209     XMLElement expires = xml.getChild("expiry");
210     XMLElement listingsRemaining = xml.getChild("listings");
211     XMLElement categoriesRemaining = xml.getChild("categories");
212     XMLElement reporting = xml.getChild("reportingq");
213     XMLElement snipesListen = xml.getChild("snipes");
214     XMLElement ssl = xml.getChild("ssl");
215     XMLElement uploadHTML = xml.getChild("uploadhtml");
216     XMLElement serverParser = xml.getChild("parser");
217     XMLElement gixen = xml.getChild("gixen");
218 
219     if(expires != null) {
220       String date = expires.getContents();
221       mExpiry = StringTools.figureDate(date, "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
222       if(mExpiry.getDate().after(new Date())) {
223         JConfig.setConfiguration("my.jbidwatcher.enabled", "false");
224       }
225     }
226 
227     mSyncQueueURL = sync.getContents();
228     mReportQueueURL = reporting.getContents();
229     mUseSSL = getBoolean(ssl);
230     mReadSnipesFromServer = getBoolean(snipesListen);
231     mUploadHTML = getBoolean(uploadHTML);
232     mUseServerParser = getBoolean(serverParser);
233     mGixen = getBoolean(gixen);
234   }
235 
236   private boolean getBoolean(XMLElement x) {
237     boolean rval = false;
238     if(x != null) {
239       String contents = x.getContents();
240       if(contents != null) {
241         rval = contents.equals("true");
242       }
243     }
244 
245     return rval;
246   }
247 
196248   public boolean createAccount(String email, String password) {
197249     //  TODO - GET http://my.jbidwatcher.com/users/new
198250     //  POST http://my.jbidwatcher.com/users with user[email]={email}&user[password]={password}&user[password_confirmation]={password}