public Campaign SetCampaignDefaultReplyTextAction(ulong campaignId, string message) { string resource = "/campaigns/" + campaignId + "/actions/default_reply"; if (message.IsEmpty()) { throw new HttpRequestException(new Exception("Parameter 'message' cannot be empty ")); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("message", message); HttpResponse response = RestClient.Post(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Campaign(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Campaign SetCampaignForwardToSmppAction(ulong campaignId, string smppApiId) { string resource = "/campaigns/" + campaignId + "/actions/smpp"; if (smppApiId.IsEmpty()) { throw new HttpRequestException(new Exception("Parameter 'smppApiId' must not be empty")); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("api_id", smppApiId); HttpResponse response = RestClient.Post(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Campaign(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Campaign SetCampaignDynamicUrlAction(ulong campaignId, string url, string sendResponse) { string resource = "/campaigns/" + campaignId + "/actions/dynamic_url"; if (url.IsValidUrl()) { throw new HttpRequestException(new Exception("Parameter 'url' must be a valid url")); } if (sendResponse.IsEmpty()) { throw new HttpRequestException(new Exception("Parameter 'sendResponse' cannot be null")); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("url", url).Set("send_response", sendResponse); HttpResponse response = RestClient.Post(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Campaign(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Sender UpdateSenderId(ulong senderId, string address) { string resource = "/senders/"; if (string.IsNullOrEmpty(address)) { throw new Exception("Parameter 'address' cannot be null"); } resource += senderId; ParameterMap parameter = RestClient.NewParams(); parameter.Set("Address", address); HttpResponse response = RestClient.Put(resource, parameter); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Sender(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Sender AddSenderId(Sender sender) { const string resource = "/senders/"; const string contentType = "application/json"; if (sender == null) { throw new Exception("Parameter 'sender' cannot be null"); } var stringWriter = new StringWriter(); new JsonSerializer().Serialize(stringWriter, sender); HttpResponse response = RestClient.Post(resource, contentType, Encoding.UTF8.GetBytes(stringWriter.ToString())); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Sender(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Campaign UpdateCampaign(Campaign campaign) { string resource = "/campaigns/"; const string contentType = "application/json"; if (campaign == null) { throw new HttpRequestException(new Exception("Parameter 'campaign' cannot be null")); } var stringWriter = new StringWriter(); new JsonSerializer().Serialize(stringWriter, campaign); resource += campaign.CampaignId; HttpResponse response = RestClient.Put(resource, contentType, Encoding.UTF8.GetBytes(stringWriter.ToString())); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Campaign(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public MoKeyWord UpdateMoKeyword(MoKeyWord keyword) { string resource = "/keywords/"; const string contentType = "application/json"; if (keyword == null) { throw new Exception("Parameter 'keyword' cannot be null"); } resource += keyword.Id; var stringWriter = new StringWriter(); new JsonSerializer().Serialize(stringWriter, keyword); HttpResponse response = RestClient.Put(resource, contentType, Encoding.UTF8.GetBytes(stringWriter.ToString())); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new MoKeyWord(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Gets the five nearest TopUpLocations based upon the longitude and latitude /// </summary> /// <param name="longitude"></param> /// <param name="latitude"></param> /// <returns>List of TopupLocation object</returns> /// <exception cref="Exception"></exception> public List <TopupLocation> GetTopupLocations(double longitude, double latitude) { const string resource = "/topup/voucher/vendors/"; var locations = new List <TopupLocation>(); ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("Longitude", Convert.ToString(longitude)).Set("Latitude", Convert.ToString(latitude)); HttpResponse response = RestClient.Get(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } string errorMessage; if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { var rst = JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()); if (!rst.ContainsKey("Locations")) { errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Malformed Server Response : " + errorMessage); } var apiArray = rst["Locations"] as IEnumerable; if (apiArray != null) { locations.AddRange(from JObject o in apiArray select(TopupLocation) Convert.ChangeType(new TopupLocation(o.ToObject <ApiDictionary>()), typeof(TopupLocation))); } return(locations); } errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Ticket UpdateSupportTicket(ulong ticketId, TicketResponse reply) { string resource = "/tickets/" + ticketId; const string contentType = "application/json"; if (reply == null) { throw new Exception("Parameter 'reply' cannot be null"); } var stringWriter = new StringWriter(); new JsonSerializer().Serialize(stringWriter, reply); HttpResponse response = RestClient.Put(resource, contentType, Encoding.UTF8.GetBytes(stringWriter.ToString())); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Ticket(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Campaign SetCampaignEmailAddressAction(ulong campaignId, string address) { string resource = "/campaigns/" + campaignId + "/actions/email"; if (address.IsEmail()) { throw new HttpRequestException(new Exception("Parameter 'address' must be a valid email ")); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("address", address); HttpResponse response = RestClient.Post(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Campaign(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Log Http Response /// </summary> /// <param name="response">Http Response</param> public void LogResponse(HttpResponse response) { if (response != null) { Log("=== HTTP Response ==="); Log("Receive url: " + response.Url); Log("Status: " + response.Status); LogHeaders(response.Headers); Log("Content:\n" + response.GetBodyAsString()); } }
public void LogResponse(HttpResponse response) { if (response != null) { Log("=== HTTP Response ==="); Log("Receive url: " + response.Url); Log("Status: " + response.Status); LogHeaders(response.Headers); Log("Content:\n" + response.GetBodyAsString()); } }
public Campaign DeleteCampaignAction(ulong campaignId, ulong actionId) { string resource = "/campaigns/" + campaignId + "/actions/" + actionId; HttpResponse response = RestClient.Delete(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Campaign(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Gets the Account Settings or Preference /// </summary> /// <returns>Settings object</returns> /// <exception cref="Exception"></exception> public Settings GetSettings() { const string resource = "/account/settings/"; HttpResponse response = RestClient.Get(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Settings(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public MoKeyWord GetMoKeyword(ulong keywordId) { string resource = "/keywords/" + keywordId; HttpResponse response = RestClient.Get(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new MoKeyWord(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Message GetMessage(Guid messageId) { string resource = "/messages/"; resource += messageId.ToString().Replace("-", ""); HttpResponse response = RestClient.Get(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Message(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Get the Account Contacts List /// </summary> /// <returns>List of AccountContact Object</returns> /// <exception cref="Exception"></exception> public List <AccountContact> GetContacts() { const string resource = "/account/contacts/"; var contacts = new List <AccountContact>(); HttpResponse response = RestClient.Get(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { var list = JsonConvert.DeserializeObject <List <ApiDictionary> >(response.GetBodyAsString()); contacts.AddRange(list.Select(jso => new AccountContact(jso))); return(contacts); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Contact AddContact(ParameterMap data) { const string resource = "/contacts/"; if (data == null) { throw new HttpRequestException(new Exception("Parameter 'data' cannot be null")); } HttpResponse response = RestClient.Post(resource, data); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) { return(new Contact(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public Sender UpdateSenderId(ulong senderId, ParameterMap data) { string resource = "/senders/"; if (data == null) { throw new Exception("Parameter 'data' cannot be null"); } resource += senderId; HttpResponse response = RestClient.Put(resource, data); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Sender(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Credit account with voucher /// </summary> /// <param name="voucherNumber">Voucher Number</param> /// <returns>Topup object</returns> /// <exception cref="Exception"></exception> public Topup GetVoucher(string voucherNumber) { string resource = "/topup/voucher/"; if (voucherNumber.IsEmpty()) { throw new HttpRequestException(new Exception("Voucher number is required")); } resource += voucherNumber.Trim(); HttpResponse response = RestClient.Get(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new Topup(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } var errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public ContentMedia UpdateContentMedia(string contentMediaId, MediaInfo mediaInfo) { string resource = "/media/"; if (!contentMediaId.IsGuid()) { throw new HttpRequestException(new Exception("contentMediaId must not be null and be a valid UUID")); } resource += contentMediaId.Replace("-", ""); ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("ContentName", mediaInfo.ContentName) .Set("LibraryId", mediaInfo.LibraryId.ToString()) .Set("DestinationFolder", mediaInfo.DestinationFolder ?? string.Empty) .Set("Preference", mediaInfo.Preference) .Set("ContentText", mediaInfo.ContentText ?? string.Empty) .Set("DisplayText", mediaInfo.DisplayText ?? string.Empty) .Set("DrmProtect", mediaInfo.DrmProtect ? "true" : "false") .Set("Tags", mediaInfo.Tags != null && mediaInfo.Tags.Count > 0 ? JsonConvert.SerializeObject(mediaInfo.Tags) : string.Empty); HttpResponse response = RestClient.Put(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new ContentMedia(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public bool DeleteMoKeyword(ulong keywordId) { string resource = "/keywords/" + keywordId; HttpResponse response = RestClient.Delete(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.NoContent)) { return(true); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public ContentMedia AddContentMedia(MediaInfo mediaInfo) { const string resource = "/media/"; if (mediaInfo == null) { throw new Exception("Parameter 'mediaRequest' cannot be null."); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("ContentName", mediaInfo.ContentName) .Set("LibraryId", mediaInfo.LibraryId.ToString()) .Set("DestinationFolder", mediaInfo.DestinationFolder ?? string.Empty) .Set("Preference", mediaInfo.Preference) .Set("ContentText", mediaInfo.ContentText ?? string.Empty) .Set("DisplayText", mediaInfo.DisplayText ?? string.Empty) .Set("Tags", mediaInfo.Tags != null && mediaInfo.Tags.Count > 0 ? JsonConvert.SerializeObject(mediaInfo.Tags) : string.Empty); HttpResponse response = RestClient.Post(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) { return(new ContentMedia(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Upload a new content media file with content media metadata /// </summary> /// <param name="filePath">Content Media file</param> /// <param name="mediaInfo">Content Media Info</param> /// <returns>ContentMedia</returns> /// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception> public ContentMedia AddContentMedia(string filePath, MediaInfo mediaInfo) { const string resource = "/media/"; if (mediaInfo == null) { throw new Exception("Parameter 'mediaInfo' cannot be null."); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("ContentName", mediaInfo.ContentName) .Set("LibraryId", mediaInfo.LibraryId.ToString()) .Set("DestinationFolder", mediaInfo.DestinationFolder ?? string.Empty) .Set("Preference", mediaInfo.Preference) .Set("Width", Convert.ToString(mediaInfo.Width)) .Set("Height", Convert.ToString(mediaInfo.Height)) .Set("DrmProtect", mediaInfo.DrmProtect ? "true" : "false") .Set("Streamable", mediaInfo.Streamable ? "true" : "false") .Set("DisplayText", mediaInfo.DisplayText ?? string.Empty) .Set("ContentText", mediaInfo.ContentText ?? string.Empty) .Set("Tags", mediaInfo.Tags != null && mediaInfo.Tags.Count > 0 ? JsonConvert.SerializeObject(mediaInfo.Tags) : string.Empty); // Let us build the upload file var mediaFile = new UploadFile(filePath, "MediaFile", FileExtensionMimeTypeMapping.GetMimeType(Path.GetExtension(filePath))); UploadFile[] files = { mediaFile }; HttpResponse response = RestClient.PostFiles(resource, files, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) { return(new ContentMedia(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public ApiList <MoKeyWord> GetMoKeywords(uint page, uint pageSize) { const string resource = "/keywords/"; ParameterMap parameterMap = RestClient.NewParams(); if (page > 0) { parameterMap.Set("Page", Convert.ToString(page)); } if (pageSize > 0) { parameterMap.Set("PageSize", Convert.ToString(pageSize)); } if (page == 0 && pageSize == 0) { parameterMap = null; } HttpResponse response = RestClient.Get(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new ApiList <MoKeyWord>(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public ApiList <Message> GetMessages(DateTime?start, DateTime?end, uint index, uint limit, bool pending, string direction) { const string resource = "/messages/"; ParameterMap parameterMap = RestClient.NewParams(); if (start != null) { parameterMap.Set("start", HttpUtility.UrlEncode(start.GetValueOrDefault().ToString("yyyy-MM-dd HH:mm:ss"))); } if (end != null) { parameterMap.Set("end", HttpUtility.UrlEncode(end.GetValueOrDefault().ToString("yyyy-MM-dd HH:mm:ss"))); } if (index > 0) { parameterMap.Set("index", Convert.ToString(index)); } if (limit > 0) { parameterMap.Set("limit", Convert.ToString(limit)); } parameterMap.Set("pending", pending ? "true" : "false"); if (!direction.IsEmpty()) { parameterMap.Set("direction", direction.Trim()); } HttpResponse response = RestClient.Get(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new ApiList <Message>(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public MessageResponse ScheduleMessage(string messageId, DateTime time) { string resource = "/messages/"; if (!messageId.IsGuid()) { throw new Exception("messageId must not be null and be a valid UUID"); } const string contentType = "application/json"; resource += messageId.Replace("-", ""); HttpResponse response = RestClient.Post(resource, contentType, Encoding.UTF8.GetBytes(String.Format("{{\"Time\":\"{0}\"}}", time.ToString("yyyy-MM-dd HH:mm:ss")))); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) { return(new MessageResponse(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Updates a content folder /// </summary> /// <param name="folderId">The content folder id</param> /// <param name="folderName">Folder name</param> /// <param name="libraryId">Library Id</param> /// <param name="parentFolder">Parent folder Id or Name</param> /// <returns>ContentFolder</returns> /// <exception cref="Exception"></exception> public ContentFolder UpdateContentFolder(ulong folderId, string folderName = null, Guid?libraryId = null, string parentFolder = null) { string resource = "/folders/" + folderId; if (folderName != null && folderName.IsEmpty()) { throw new Exception("Parameter 'folderName' cannot be null."); } if (folderName != null && !folderName.IsValidFileName(true)) { throw new Exception("Parameter 'folderName' must be valid folder name."); } if (parentFolder != null && !parentFolder.IsEmpty()) { if (!parentFolder.IsNumeric() && !parentFolder.IsValidFileName(true)) { throw new Exception("Parameter 'parentFolder' must be valid folder name."); } } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("FolderName", folderName).Set("LibraryId", libraryId.ToString()).Set("Parent", parentFolder); HttpResponse response = RestClient.Put(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new ContentFolder(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public bool DeleteContentMedia(string contentMediaId) { string resource = "/media/"; if (!contentMediaId.IsGuid()) { throw new Exception("contentMediaId must not be null and be a valid UUID"); } resource += contentMediaId.Replace("-", ""); HttpResponse response = RestClient.Delete(resource); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.NoContent)) { return(true); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
/// <summary> /// Fetches a paginated list of content medias /// </summary> /// <param name="page">The page number</param> /// <param name="pageSize">The number of items on a page</param> /// <param name="filters">Query filters</param> /// <returns>ApiList of ContentMedia</returns> /// <exception cref="HttpRequestException"></exception> public ApiList <ContentMedia> GetContentMedias(uint page, uint pageSize, Dictionary <string, string> filters = null) { const string resource = "/media/"; ParameterMap parameterMap = RestClient.NewParams(); if (page > 0) { parameterMap.Set("Page", Convert.ToString(page)); } if (pageSize > 0) { parameterMap.Set("PageSize", Convert.ToString(pageSize)); } if (filters != null && filters.Count > 0) { foreach (var filter in filters) { parameterMap.Set(filter.Key, filter.Value); } } if (page == 0 && pageSize == 0 && filters == null) { parameterMap = null; } HttpResponse response = RestClient.Get(resource, parameterMap); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.OK)) { return(new ApiList <ContentMedia>(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public MessageResponse SendMessage(Message mesg) { if (mesg == null) { throw new Exception("Parameter 'mesg' cannot be null"); } const string resource = "/messages/"; var stringWriter = new StringWriter(); new JsonSerializer().Serialize(stringWriter, mesg); const string contentType = "application/json"; HttpResponse response = RestClient.Post(resource, contentType, Encoding.UTF8.GetBytes(stringWriter.ToString())); if (response == null) { throw new Exception("Request Failed. Unable to get server response"); } if (response.Status == Convert.ToInt32(HttpStatusCode.Created)) { return(new MessageResponse(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }