Beispiel #1
0
		/// <summary>
		/// Registers the device.
		/// </summary>
		/// <returns>The device.</returns>
		/// <param name="newObject">New object.</param>
		async public Task<MParseInstallationObjectAnswer> RegisterDevice (MParseInstallationObject newObject)
		{
			HttpClient client = new HttpClient ();
			HttpRequestMessage requests = new HttpRequestMessage (HttpMethod.Post, new Uri ("https://api.parse.com/1/installations"));

			foreach (var header in RestHeaders()) {
				requests.Headers.Add (header.Name, header.Value);
			}
			//REMOVE THIS PART!!!!
			if (newObject.Channels [0] == "MEK/SVETS") {
				newObject.Channels [0] = "MEK";
			}
			string jSon = await Task.Run (() => JsonConvert.SerializeObject (newObject));

			HttpContent content = new StringContent (jSon);
			content.Headers.ContentType = new MediaTypeHeaderValue ("application/json");
			requests.Content = content;

			HttpResponseMessage response	= await client.SendAsync (requests);
		
			response.EnsureSuccessStatusCode ();


			//HttpHeaders headers = response.Headers;

		

			//string location = null;

			//if (headers.TryGetValues ("Location", out values)) {
			//	location = values.First ();
			//}

			string answer = await response.Content.ReadAsStringAsync ();
		
			MParseInstallationObjectAnswer a = await Task.Run (() => JsonConvert.DeserializeObject<MParseInstallationObjectAnswer> (answer)); 
			a.StatusText = response.StatusCode.ToString ();
			a.LocationUrl = "https://api.parse.com/1/installations/" + a.ObjectId;
			return a;
		}
Beispiel #2
0
		public async Task<bool> UpdateInstallationObject (MParseInstallationObject installationObject)
		{
			if (string.IsNullOrEmpty (installationObject.ObjectId)) {
				throw new Exception ("MParseInstallationObject: ObjectId is null");
			}
			string objectId = installationObject.ObjectId;

			HttpClient client = new HttpClient ();
			HttpRequestMessage request = new HttpRequestMessage (HttpMethod.Put, new Uri ("https://api.parse.com/1/installations/" + objectId));
			foreach (var header in RestHeaders()) {
				request.Headers.Add (header.Name, header.Value);

			}
			installationObject.ObjectId = null;

			//REMOVE THIS PART Remove wrong type of characters before...
			if (installationObject.Channels [0] == "MEK/SVETS") {
				installationObject.Channels [0] = "MEK";
			}

			string jSon = await Task.Run (() => JsonConvert.SerializeObject (installationObject));


			HttpContent content = new StringContent (jSon);
			content.Headers.ContentType = new MediaTypeHeaderValue ("application/json");
			request.Content = content;

			HttpResponseMessage response	= await client.SendAsync (request);

			response.EnsureSuccessStatusCode ();

			return true;
		
		}