summaryrefslogtreecommitdiffstats
path: root/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/WindowsLive/WindowsLiveGraph.cs
blob: 8b4e1f82b8a6cdace74a2b0cc7f3edea7516933e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//-----------------------------------------------------------------------
// <copyright file="WindowsLiveGraph.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.ApplicationBlock {
	using System;
	using System.Collections.Generic;
	using System.IO;
	using System.Linq;
	using System.Runtime.Serialization;
	using System.Runtime.Serialization.Json;
	using System.Text;

	//// Documentation: http://msdn.microsoft.com/en-us/library/live/hh243648.aspx#user

	[DataContract]
	public class WindowsLiveGraph : IOAuth2Graph {
		private static DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(WindowsLiveGraph));

		/// <summary>
		/// Gets or sets the user's ID.
		/// </summary>
		[DataMember(Name = "id", IsRequired = true)]
		public string Id { get; set; }

		/// <summary>
		/// Gets or sets the user's full name.
		/// </summary>
		[DataMember(Name = "name", IsRequired = true)]
		public string Name { get; set; }

		/// <summary>
		/// Gets or sets the user's first name.
		/// </summary>
		[DataMember(Name = "first_name")]
		public string FirstName { get; set; }

		/// <summary>
		/// Gets or sets the user's last name.
		/// </summary>
		[DataMember(Name = "last_name")]
		public string LastName { get; set; }

		/// <summary>
		/// Gets or sets the URL of the user's profile page.
		/// </summary>
		[DataMember(Name = "link")]
		public Uri Link { get; set; }

		/// <summary>
		/// Gets or sets the day of the user's birth date, or null if no birth date is specified.
		/// </summary>
		[DataMember(Name = "birth_day")]
		public int? BirthDay { get; set; }

		/// <summary>
		/// Gets or sets the month of the user's birth date, or null if no birth date is specified.
		/// </summary>
		[DataMember(Name = "birth_month")]
		public int? BirthMonth { get; set; }

		/// <summary>
		/// Gets or sets the year of the user's birth date, or null if no birth date is specified.
		/// </summary>
		[DataMember(Name = "birth_year")]
		public int? BirthYear { get; set; }

		/// <summary>
		/// Gets or sets an array that contains the user's work info.
		/// </summary>
		[DataMember(Name = "work")]
		public WindowsLiveWorkProfile[] Work { get; set; }

		/// <summary>
		/// Gets or sets the user's gender. Valid values are "male", "female", or null if the user's gender is not specified.
		/// </summary>
		[DataMember(Name = "gender")]
		public string Gender { get; set; }

		/// <summary>
		/// Gets or sets the user's email addresses.
		/// </summary>
		[DataMember(Name = "emails")]
		public WindowsLiveEmails Emails { get; set; }

		/// <summary>
		/// Gets or sets the user's postal addresses.
		/// </summary>
		[DataMember(Name = "addresses")]
		public WindowsLiveAddresses Addresses { get; set; }

		/// <summary>
		/// Gets or sets the user's phone numbers.
		/// </summary>
		[DataMember(Name = "phones")]
		public WindowsLivePhones Phones { get; set; }

		/// <summary>
		/// Gets or sets the user's locale code.
		/// </summary>
		[DataMember(Name = "locale", IsRequired = true)]
		public string Locale { get; set; }

		/// <summary>
		/// Gets or sets the time, in ISO 8601 format, at which the user last updated the object.
		/// </summary>
		[DataMember(Name = "updated_time")]
		public string UpdatedTime { get; set; }

		public string Email {
			get {
				return this.Emails.Account;
			}
		}

		public Uri AvatarUrl { get; set; }

		public DateTime? BirthdayDT {
			get {
				if (this.BirthYear.HasValue && this.BirthMonth.HasValue && this.BirthDay.HasValue) {
					return new DateTime(this.BirthYear.Value, this.BirthMonth.Value, this.BirthDay.Value);
				}

				return null;
			}
		}

		public HumanGender GenderEnum {
			get {
				if (this.Gender == "male") {
					return HumanGender.Male;
				} else if (this.Gender == "female") {
					return HumanGender.Female;
				}

				return HumanGender.Unknown;
			}
		}

		public static WindowsLiveGraph Deserialize(string json) {
			if (string.IsNullOrEmpty(json)) {
				throw new ArgumentNullException("json");
			}

			return Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(json)));
		}

		public static WindowsLiveGraph Deserialize(Stream jsonStream) {
			if (jsonStream == null) {
				throw new ArgumentNullException("jsonStream");
			}

			return (WindowsLiveGraph)jsonSerializer.ReadObject(jsonStream);
		}

		[DataContract]
		public class WindowsLiveEmails {
			/// <summary>
			/// Gets or sets the user's preferred email address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "preferred")]
			public string Preferred { get; set; }

			/// <summary>
			/// Gets or sets the email address that is associated with the account.
			/// </summary>
			[DataMember(Name = "account", IsRequired = true)]
			public string Account { get; set; }

			/// <summary>
			/// Gets or sets the user's personal email address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "personal")]
			public string Personal { get; set; }

			/// <summary>
			/// Gets or sets the user's business email address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "business")]
			public string Business { get; set; }

			/// <summary>
			/// Gets or sets the user's "alternate" email address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "other")]
			public string Other { get; set; }
		}

		[DataContract]
		public class WindowsLivePhones {
			/// <summary>
			/// Gets or sets the user's personal phone number, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "personal")]
			public string Personal { get; set; }

			/// <summary>
			/// Gets or sets the user's business phone number, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "business")]
			public string Business { get; set; }

			/// <summary>
			/// Gets or sets the user's mobile phone number, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "mobile")]
			public string Mobile { get; set; }
		}

		[DataContract]
		public class WindowsLiveAddress {
			/// <summary>
			/// Gets or sets the street address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "street")]
			public string Street { get; set; }

			/// <summary>
			/// Gets or sets the second line of the street address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "street_2")]
			public string Street2 { get; set; }

			/// <summary>
			/// Gets or sets the city of the address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "city")]
			public string City { get; set; }

			/// <summary>
			/// Gets or sets the state of the address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "state")]
			public string State { get; set; }

			/// <summary>
			/// Gets or sets the postal code of the address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "postal_code")]
			public string PostalCode { get; set; }

			/// <summary>
			/// Gets or sets the region of the address, or null if one is not specified.
			/// </summary>
			[DataMember(Name = "region")]
			public string Region { get; set; }
		}

		[DataContract]
		public class WindowsLiveAddresses {
			/// <summary>
			/// Gets or sets the user's personal postal address.
			/// </summary>
			[DataMember(Name = "personal")]
			public WindowsLiveAddress Personal { get; set; }

			/// <summary>
			/// Gets or sets the user's business postal address.
			/// </summary>
			[DataMember(Name = "business")]
			public WindowsLiveAddress Business { get; set; }
		}

		[DataContract]
		public class WindowsLiveWorkProfile {
			/// <summary>
			/// Gets or sets info about the user's employer.
			/// </summary>
			[DataMember(Name = "employer")]
			public WindowsLiveEmployer Employer { get; set; }

			/// <summary>
			/// Gets or sets info about the user's employer.
			/// </summary>
			[DataMember(Name = "position")]
			public WindowsLivePosition Position { get; set; }
		}

		[DataContract]
		public class WindowsLiveEmployer {
			/// <summary>
			/// Gets or sets the name of the user's employer, or null if the employer's name is not specified.
			/// </summary>
			[DataMember(Name = "name")]
			public string Name { get; set; }
		}

		[DataContract]
		public class WindowsLivePosition {
			/// <summary>
			/// Gets or sets the name of the user's work position, or null if the name of the work position is not specified.
			/// </summary>
			[DataMember(Name = "name")]
			public string Name { get; set; }
		}
	}
}