Skip to content
Browse files

change HTTPRequest to AndCouch and remove command database listener

  • Loading branch information...
1 parent cb961e3 commit e87880680975e848ec1b2db5ea166143801f8cd4 Dale Harvey committed Feb 14, 2011
View
10 src/com/couchone/couchdb/CouchCtrlListener.java
@@ -5,7 +5,7 @@
import org.json.JSONObject;
import com.couchone.libcouch.Base64Coder;
-import com.couchone.libcouch.HTTPRequest;
+import com.couchone.libcouch.AndCouch;
import android.util.Log;
@@ -35,7 +35,7 @@ public void start() {
if (!running) {
try {
running = true;
- JSONObject dbInfo = HTTPRequest.get(couchUrl + ctrl, headers()).json;
+ JSONObject dbInfo = AndCouch.get(couchUrl + ctrl, headers()).json;
int updateSeq = dbInfo.getInt("update_seq");
changes(updateSeq);
} catch (JSONException e) {
@@ -48,7 +48,7 @@ public void start() {
private void doReplication(JSONObject json) throws JSONException {
- HTTPRequest req = HTTPRequest.post(couchUrl + "_replicate", json.toString(), headers());
+ AndCouch req = AndCouch.post(couchUrl + "_replicate", json.toString(), headers());
// Java will just close the connection when it gets a 404
// without reading the result
@@ -63,7 +63,7 @@ private void doReplication(JSONObject json) throws JSONException {
json.put("result", result);
json.put("status", "complete");
String id = json.getString("_id");
- HTTPRequest.put(couchUrl + ctrl + "/" + id, json.toString(), headers());
+ AndCouch.put(couchUrl + ctrl + "/" + id, json.toString(), headers());
}
private void handleChange(JSONObject doc) throws JSONException {
@@ -82,7 +82,7 @@ private void changes(int seq) throws JSONException {
String url = couchUrl + ctrl
+ "/_changes?include_docs=true&feed=longpoll&since="
+ Integer.toString(seq);
- JSONObject json = HTTPRequest.get(url, headers()).json;
+ JSONObject json = AndCouch.get(url, headers()).json;
Log.v(CouchProcess.TAG, "Received Changes for " + ctrl);
seq = json.getInt("last_seq");
View
4 src/com/couchone/couchdb/CouchProcess.java
@@ -17,7 +17,7 @@
import android.util.Log;
-import com.couchone.libcouch.HTTPRequest;
+import com.couchone.libcouch.AndCouch;
import com.google.ase.Exec;
public class CouchProcess {
@@ -74,7 +74,7 @@ private void ensureAdmin() throws JSONException {
// TODO: only works because I cant overwrite, check if exists in future
String url = url() + "_config/admins/" + adminUser;
try {
- HTTPRequest.put(url, "\"" + adminPass + "\"");
+ AndCouch.put(url, "\"" + adminPass + "\"");
} catch (JSONException e) {
// Config PUTS will return a string which causes HTTPRequest to throw
}
View
13 src/com/couchone/couchdb/CouchService.java
@@ -10,7 +10,7 @@
import com.couchone.libcouch.AeSimpleSHA1;
import com.couchone.libcouch.Base64Coder;
-import com.couchone.libcouch.HTTPRequest;
+import com.couchone.libcouch.AndCouch;
import com.couchone.libcouch.ICouchClient;
import com.couchone.libcouch.ICouchService;
@@ -99,6 +99,8 @@ public void initDatabase(ICouchClient callback, String tag, String pass, boolean
// clients can request a command database that proxies replication
// requests as they dont have admin permissions to post directly
+ // Command databases are currently unused
+ /*
if (cmdDb) {
createIfNotExists(dbName + "-ctrl", userName, pass);
@@ -116,6 +118,7 @@ public void run() {
}
}).start();
}
+ */
// Notify the client that their database is ready
callback.databaseCreated(dbName, userName, pass, tag);
@@ -157,7 +160,7 @@ private void createUser(String user, String pass) {
+ "\"type\":\"user\"," + "\"name\":\"" + user + "\","
+ "\"roles\":[]," + "\"password_sha\":\"" + hashed + "\", "
+ "\"salt\":\"" + salt + "\"}";
- HTTPRequest.post(couch.url() + "_users", json, adminHeaders());
+ AndCouch.post(couch.url() + "_users", json, adminHeaders());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
@@ -174,13 +177,13 @@ private void createUser(String user, String pass) {
private void createIfNotExists(String dbName, String user, String pass) {
try {
String url = couch.url() + dbName;
- HTTPRequest res = HTTPRequest.get(couch.url() + dbName, adminHeaders());
+ AndCouch res = AndCouch.get(couch.url() + dbName, adminHeaders());
if (res.status == 404) {
createUser(user, pass);
- HTTPRequest.put(url, null, adminHeaders());
+ AndCouch.put(url, null, adminHeaders());
String sec = "{\"admins\":{\"names\":[\"" + user
+ "\"],\"roles\":[]},\"readers\":{\"names\":[],\"roles\":[]}}";
- HTTPRequest.put(url + "/_security", sec, adminHeaders());
+ AndCouch.put(url + "/_security", sec, adminHeaders());
}
} catch (JSONException e) {
e.printStackTrace();

0 comments on commit e878806

Please sign in to comment.
Something went wrong with that request. Please try again.