1 module office365; 2 3 import vibe.d; 4 5 /// 6 struct Events 7 { 8 /// 9 Event[] value; 10 } 11 12 /// 13 enum DefaultFolder 14 { 15 Inbox = "inbox", 16 SentItems = "sentitems", 17 Drafts = "drafts", 18 } 19 20 /// 21 struct Messages 22 { 23 /// 24 Message[] value; 25 /// 26 @optional 27 @name("@odata.count") 28 int count; 29 } 30 31 /// 32 struct EventDate 33 { 34 /// 35 @name("DateTime") 36 string _DateTime; 37 /// 38 string TimeZone; 39 } 40 41 /// 42 struct EventLocation 43 { 44 /// 45 string DisplayName; 46 } 47 48 /++ 49 + Microsoft.OutlookServices.Event 50 + see https://msdn.microsoft.com/en-us/office/office365/api/complex-types-for-mail-contacts-calendar#EventResource 51 +/ 52 struct Event 53 { 54 /// 55 string[] Categories; 56 /// 57 bool IsReminderOn; 58 /// 59 bool HasAttachments; 60 /// 61 string Subject; 62 /// 63 bool IsAllDay; 64 /// 65 EventDate Start; 66 /// 67 EventDate End; 68 /// 69 EventLocation Location; 70 } 71 72 /// 73 struct MessageBody 74 { 75 /// 76 string ContentType; 77 /// 78 string Content; 79 } 80 81 /// 82 enum Select 83 { 84 Subject, 85 BodyPreview, 86 SentDateTime, 87 Body, 88 Sender, 89 From, 90 } 91 92 /// 93 struct SelectBuilder 94 { 95 private string content; 96 97 /// 98 auto add(Select selector) 99 { 100 import std.conv:to; 101 102 if(content.length!=0) 103 content ~= ","; 104 105 content ~= to!string(selector); 106 107 return this; 108 } 109 110 /// 111 string toString() const 112 { 113 return content; 114 } 115 } 116 117 /// 118 struct EmailAddress 119 { 120 /// 121 struct NameAdressTuple 122 { 123 /// 124 string Name; 125 /// 126 string Address; 127 } 128 129 /// 130 NameAdressTuple EmailAddress; 131 } 132 133 /// 134 struct Message 135 { 136 /// 137 string Id; 138 /// 139 @optional 140 string Subject; 141 /// 142 @optional 143 MessageBody Body; 144 /// 145 @optional 146 string BodyPreview; 147 /// 148 @optional 149 string SentDateTime; 150 /// 151 @optional 152 EmailAddress Sender; 153 /// 154 @optional 155 EmailAddress From; 156 /// 157 @optional 158 bool IsRead; 159 } 160 161 /// 162 @path("/api/v2.0/me") 163 interface Office365Api 164 { 165 /// uses https://outlook.office.com/api/v2.0/me/calendarview 166 @method(HTTPMethod.GET) 167 Events calendarview(DateTime startdatetime, DateTime enddatetime); 168 169 @queryParam("_filter", "$filter") 170 @queryParam("_top", "$top") 171 @queryParam("_select", "$select") 172 @path("/mailfolders/:folder/messages") 173 @method(HTTPMethod.GET) 174 { 175 @queryParam("_count", "$count") 176 Messages messages(string _folder, bool _count, string _filter, string _select="", int _top=10); 177 Messages messages(string _folder, string _filter="", string _select="", int _top=10); 178 } 179 180 @path("/messages/:id") 181 @method(HTTPMethod.DELETE) 182 void deleteMessage(string _id); 183 184 @path("/messages/:id") 185 @method(HTTPMethod.PATCH) 186 { 187 Message updateRead(string _id, bool IsRead); 188 Message updateCategories(string _id, string[] Categories); 189 } 190 } 191 192 /// 193 static Office365Api createOfficeApi(string access_token) 194 { 195 import vibe.web.rest:RestInterfaceClient; 196 import vibe.http.client:HTTPClientRequest; 197 auto res = new RestInterfaceClient!Office365Api("https://outlook.office.com"); 198 199 res.requestFilter = (HTTPClientRequest req){ 200 req.headers["Authorization"] = "Bearer "~access_token; 201 }; 202 203 return res; 204 }