Skip to content

Instantly share code, notes, and snippets.

@jmarmolejos
Last active September 13, 2015 15:30
Show Gist options
  • Save jmarmolejos/3b4fc55f7a6b1c5fedac to your computer and use it in GitHub Desktop.
Save jmarmolejos/3b4fc55f7a6b1c5fedac to your computer and use it in GitHub Desktop.
function (doc) {
emit(doc._id, doc);
}
public async Task<List<Notification>> Get()
{
var uriBuilder = GetCouchUrl();
using (var client = new MyCouchClient(uriBuilder.Build()))
{
var notifications = await client.Views.QueryAsync<Notification>(new QueryViewRequest("notifications-doc", "all-notifications"));
return notifications.Rows.Select(r => r.Value).ToList();
}
}
private MyCouchUriBuilder GetCouchUrl()
{
// assuming you're using cloudant
return new MyCouchUriBuilder("https://[username].cloudant.com/")
.SetDbName("notifications")
.SetBasicCredentials("[usename]", "[password]");
}
namespace CouchWebApi.Models
{
public class Notification
{
public string Alert { get; set; }
public int Count { get; set; }
}
}
public async Task<Notification> Post(Notification notification)
{
var uriBuilder = GetCouchUrl();
using (var client = new MyCouchClient(uriBuilder.Build()))
{
var response = await client.Entities.PostAsync(notification);
return response.Content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment