public T Invoke <T>(HttpMethod httpMethod, string requestUriSuffix, Dictionary <string, string> headers, string body) where T : BaseDto { var result = Invoke(httpMethod, requestUriSuffix, headers, body); return(BaseDto.DeserializeObject <T>(result)); }
public ICollection <Group> GetGroups() { var response = Invoke(HttpMethod.Get, Constants.ApiOperation.GROUPS, null, null); Contract.Assert(!string.IsNullOrWhiteSpace(response)); return(BaseDto.DeserializeObject <ICollection <Group> >(response)); }
public Group GetGroup(long id) { var suffix = string.Format("{0}/{1}", Constants.ApiOperation.GROUPS, id); var response = Invoke(HttpMethod.Get, suffix, null, null); Contract.Assert(!string.IsNullOrWhiteSpace(response)); return(BaseDto.DeserializeObject <Group>(response)); }
public ICollection <Device> GetDevices() { Contract.Ensures(null != Contract.Result <ICollection <Device> >()); var requestUri = string.Format("{0}", Constants.ApiOperation.DEVICES); try { var json = Invoke(HttpMethod.Get, requestUri, null, null); var result = BaseDto.DeserializeObject <List <Device> >(json); return(result); } catch (Exception ex) { return(default(ICollection <Device>)); } }
public Device GetDevice(long id) { Contract.Requires(0 < id); var requestUri = string.Format("{0}/{1}", Constants.ApiOperation.DEVICES, id); try { var json = Invoke(HttpMethod.Get, requestUri, null, null); var result = BaseDto.DeserializeObject <Device>(json); Contract.Assert(id == result.DeviceId); return(result); } catch (Exception ex) { return(default(Device)); } }
public string GetToken(Uri baseUri, string username, string password, string serialNumber) { Contract.Requires(null != baseUri); Contract.Requires(baseUri.IsAbsoluteUri); Contract.Requires(!string.IsNullOrWhiteSpace(username)); Contract.Requires(!string.IsNullOrWhiteSpace(password)); Contract.Requires(!string.IsNullOrWhiteSpace(serialNumber)); Contract.Ensures(!string.IsNullOrWhiteSpace(Contract.Result <string>())); this.BaseUri = baseUri; var sut = new SessionRequest { Username = username, Password = password, SerialNumber = serialNumber }; var body = sut.SerializeObject(); var client = new RestCallExecutor(); var requestUri = new Uri(baseUri, Constants.ApiOperation.SESSION); var result = client.Invoke(HttpMethod.Post, requestUri.AbsoluteUri, null, body); Contract.Assert(!string.IsNullOrWhiteSpace(result)); var response = BaseDto.DeserializeObject <SessionResponse>(result); UserInformation = new UserInformation() { UserId = response.UserId, Username = username, Password = password, SerialNumber = serialNumber, SecurityToken = response.SecurityToken }; return(response.SecurityToken); }