Skip to content

Apricot Notification Protocol

Masaaki Kawata edited this page Jan 25, 2020 · 9 revisions

Examples

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Net;

namespace ApricotNotify
{
    class Program
    {
        static void Main(string[] args)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Entry[]));
            List<Entry> list = new List<Entry>();

            list.Add(new Entry() { Resource = "http://www.apricotan.net/", Title = "APRICOTAN.NET" });
            list.Add(new Entry() { Title = "Test" });
            
            using (MemoryStream ms = new MemoryStream())
            {
                serializer.WriteObject(ms, list.ToArray());

                WebClient webClient = new WebClient();

                webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                webClient.UploadData("http://localhost:47806/alert", ms.GetBuffer());
            }
        }
    }

    [DataContract]
    public class Entry
    {
        [DataMember(Name = "resource")]
        public string Resource { get; set; }
        [DataMember(Name = "title")]
        public string Title { get; set; }
        [DataMember(Name = "description")]
        public string Description { get; set; }
        public string Author { get; set; }
        public DateTime Created { get; set; }
        public DateTime Modified { get; set; }
        public Uri Image { get; set; }
    }
}
Clone this wiki locally