Permalink
Browse files

Improve readability of CouchDatabase.cs by using string.Format() wher…

…e applicable.
  • Loading branch information...
1 parent 31ae025 commit 487ce7f76b8db5fc327931a697dc44642ca4c991 Johan van der Geest committed Jan 30, 2013
Showing with 11 additions and 11 deletions.
  1. +11 −11 LoveSeat/CouchDatabase.cs
View
@@ -206,7 +206,7 @@ public CouchResponse AddAttachment(string id, byte[] attachment, string filename
public CouchResponse AddAttachment(string id, string rev, byte[] attachment, string filename, string contentType)
{
return
- GetRequest(databaseBaseUri + "/" + id + "/" + filename + "?rev=" + rev).Put().ContentType(contentType).Data(attachment).GetResponse().GetJObject();
+ GetRequest(string.Format("{0}/{1}/{2}?rev={3}", databaseBaseUri, id, filename, rev)).Put().ContentType(contentType).Data(attachment).GetResponse().GetJObject();
}
/// <summary>
/// Adds an attachment to a document. If revision is not specified then the most recent will be fetched and used. Warning: if you need document update conflicts to occur please use the method that specifies the revision
@@ -231,7 +231,7 @@ public CouchResponse AddAttachment(string id, Stream attachmentStream, string fi
public CouchResponse AddAttachment(string id, string rev, Stream attachmentStream, string filename, string contentType)
{
return
- GetRequest(databaseBaseUri + "/" + id + "/" + filename + "?rev=" + rev).Put().ContentType(contentType).Data(attachmentStream).GetResponse().GetJObject();
+ GetRequest(string.Format("{0}/{1}/{2}?rev={3}", databaseBaseUri, id, filename, rev)).Put().ContentType(contentType).Data(attachmentStream).GetResponse().GetJObject();
}
public Stream GetAttachmentStream(Document doc, string attachmentName)
@@ -240,7 +240,7 @@ public Stream GetAttachmentStream(Document doc, string attachmentName)
}
public Stream GetAttachmentStream(string docId, string rev, string attachmentName)
{
- return GetRequest(databaseBaseUri + "/" + docId + "/" + HttpUtility.UrlEncode(attachmentName)).Get().GetResponse().GetResponseStream();
+ return GetRequest(string.Format("{0}/{1}/{2}", databaseBaseUri, docId, HttpUtility.UrlEncode(attachmentName))).Get().GetResponse().GetResponseStream();
}
public Stream GetAttachmentStream(string docId, string attachmentName)
{
@@ -250,7 +250,7 @@ public Stream GetAttachmentStream(string docId, string attachmentName)
}
public CouchResponse DeleteAttachment(string id, string rev, string attachmentName)
{
- return GetRequest(databaseBaseUri + "/" + id + "/" + attachmentName + "?rev=" + rev).Json().Delete().GetResponse().GetJObject();
+ return GetRequest(string.Format("{0}/{1}/{2}?rev={3}", databaseBaseUri, id, attachmentName, rev)).Json().Delete().GetResponse().GetJObject();
}
public CouchResponse DeleteAttachment(string id, string attachmentName)
{
@@ -263,7 +263,7 @@ public CouchResponse SaveDocument(Document document)
if (document.Rev == null)
return CreateDocument(document);
- var resp = GetRequest(databaseBaseUri + "/" + document.Id + "?rev=" + document.Rev).Put().Form().Data(document).GetResponse();
+ var resp = GetRequest(string.Format("{0}/{1}?rev={2}", databaseBaseUri, document.Id, document.Rev)).Put().Form().Data(document).GetResponse();
return resp.GetJObject();
}
@@ -331,7 +331,7 @@ private static JObject CheckAccepted(HttpWebResponse resp)
}
if (resp.StatusCode != HttpStatusCode.Accepted) {
- throw new System.Exception("Response return with a HTTP Code of " + resp.StatusCode + " - " + resp.StatusDescription);
+ throw new System.Exception(string.Format("Response return with a HTTP Code of {0} - {1}", resp.StatusCode, resp.StatusDescription));
}
return resp.GetJObject();
@@ -354,13 +354,13 @@ private void ThrowDesignDocException()
public string Show(string showName, string docId, string designDoc)
{
//TODO: add in Etag support for Shows
- var uri = databaseBaseUri + "/_design/" + designDoc + "/_show/" + showName + "/" + docId;
+ var uri = string.Format("{0}/_design/{1}/_show/{2}/{3}", databaseBaseUri, designDoc, showName, docId);
var req = GetRequest(uri);
return req.GetResponse().GetResponseString();
}
public IListResult List(string listName, string viewName, ViewOptions options, string designDoc)
{
- var uri = databaseBaseUri + "/_design/" + designDoc + "/_list/" + listName + "/" + viewName + options.ToString();
+ var uri = string.Format("{0}/_design/{1}/_list/{2}/{3}{4}", databaseBaseUri, designDoc, listName, viewName, options.ToString());
var req = GetRequest(uri);
return new ListResult(req.GetRequest(), req.GetResponse());
}
@@ -400,7 +400,7 @@ public void SetDefaultDesignDoc(string designDoc)
/// <returns></returns>
public ViewResult<T> View<T>(string viewName, ViewOptions options, string designDoc)
{
- var uri = databaseBaseUri + "/_design/" + designDoc + "/_view/" + viewName;
+ var uri = string.Format("{0}/_design/{1}/_view/{2}", databaseBaseUri, designDoc, viewName);
return ProcessGenericResults<T>(uri, options);
}
/// <summary>
@@ -418,14 +418,14 @@ public ViewResult<T> View<T>(string viewName, ViewOptions options)
public ViewResult View(string viewName, ViewOptions options, string designDoc)
{
- var uri = databaseBaseUri + "/_design/" + designDoc + "/_view/" + viewName;
+ var uri = string.Format("{0}/_design/{1}/_view/{2}", databaseBaseUri, designDoc, viewName);
return ProcessResults(uri, options);
}
public ViewResult View(string viewName, ViewOptions options)
{
ThrowDesignDocException();
- var uri = databaseBaseUri + "/_design/" + this.defaultDesignDoc + "/_view/" + viewName;
+ var uri = string.Format("{0}/_design/{1}/_view/{2}", databaseBaseUri, this.defaultDesignDoc, viewName);
return ProcessResults(uri, options);
}
private ViewResult ProcessResults(string uri, ViewOptions options)

0 comments on commit 487ce7f

Please sign in to comment.