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 bool UpdateContactGroup(ulong groupId, string groupName) { string resource = "/contacts/groups/"; if (groupName.IsEmpty()) { throw new Exception("Parameter 'groupName' cannot be null"); } resource += groupId; ParameterMap parameter = RestClient.NewParams(); parameter.Set("Name", groupName); 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(true); } string errorMessage = String.Format("Status Code={0}, Message={1}", response.Status, response.GetBodyAsString()); throw new Exception("Request Failed : " + errorMessage); }
public ContactGroup AddContactGroup(string groupName) { const string resource = "/contacts/groups/"; if (groupName.IsEmpty()) { throw new HttpRequestException(new Exception("Parameter 'groupName' cannot be null")); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("Name", groupName); 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 ContactGroup(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> /// Creates a new content library and returns the created content metadata. /// </summary> /// <param name="name">Content Library Name</param> /// <param name="shortName">Content Library ShortName</param> /// <returns>ContentLibrary</returns> /// <exception cref="Exception"></exception> public ContentLibrary AddContentLibrary(string name, string shortName) { const string resource = "/libraries/"; if (name == null || name.IsEmpty() || shortName == null || shortName.IsEmpty()) { throw new Exception("Parameter 'name' and 'shortName' cannot be null."); } if (!name.IsValidFileName(true) || !shortName.IsValidFileName(true)) { throw new Exception("Parameter 'name' and 'shortName' must be valid folder name."); } ParameterMap parameterMap = RestClient.NewParams(); parameterMap.Set("Name", name).Set("ShortName", shortName); 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 ContentLibrary(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 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); }
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); }
/// <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 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 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); }
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 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 ApiList <Contact> GetContacts(uint page, uint pageSize, ulong groupId, string filter) { const string resource = "/contacts/"; ParameterMap parameterMap = RestClient.NewParams(); if (page > 0) { parameterMap.Set("Page", Convert.ToString(page)); } if (pageSize > 0) { parameterMap.Set("PageSize", Convert.ToString(pageSize)); } if (groupId > 0) { parameterMap.Set("GroupId", Convert.ToString(groupId)); } if (!filter.IsEmpty()) { parameterMap.Set("Search", filter.Trim()); } if (page == 0 && pageSize == 0 && groupId == 0 && filter.IsEmpty()) { parameterMap = null; } var 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 <Contact>(JsonConvert.DeserializeObject <ApiDictionary>(response.GetBodyAsString()))); } var 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); }
/// <summary> /// Updates the metadata of a given library and returns the updated library. /// </summary> /// <param name="libraryId">The Content Library Id</param> /// <param name="name">The Library Name</param> /// <param name="shortName">The Library ShortName</param> /// <returns>ContentLibrary</returns> /// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception> public ContentLibrary UpdateContentLibrary(Guid libraryId, string name = null, string shortName = null) { string resource = "/libraries/"; ParameterMap parameterMap = RestClient.NewParams(); if (name != null && !name.IsEmpty()) { if (!name.IsValidFileName(true)) { throw new Exception("Parameter 'name' and 'shortName' must be valid folder name."); } parameterMap.Set("Name", name); } if (shortName != null && !shortName.IsEmpty()) { if (!shortName.IsValidFileName(true)) { throw new Exception("Parameter 'name' and 'shortName' must be valid folder name."); } parameterMap.Set("ShortName", shortName); } resource += libraryId.ToString().Replace("-", ""); 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 ContentLibrary(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 ContentFolder AddContentFolder(string folderName, String libraryId, string parentFolder = null) { const string resource = "/folders/"; if (folderName == null) { 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 (libraryId == null) { throw new Exception("Parameter 'libaryId' cannot be null."); } if (!libraryId.IsGuid()) { throw new Exception("Parameter 'libaryId' must be a valid UUID."); } 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).Set("Parent", parentFolder); 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 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); }
/// <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 <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); }