Example #1
0
        /// <summary>
        ///     Get a paginated list of support tickets
        /// </summary>
        /// <param name="page">The page index</param>
        /// <param name="pageSize">The number of items on a page</param>
        /// <returns>
        ///     <see cref="Ticket" /> <seealso cref="ApiList{T}" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message</exception>
        public ApiList <Ticket> GetSupportTickets(uint page, uint pageSize)
        {
            const string resource     = "/tickets/";
            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 <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);
        }
Example #2
0
        /// <summary>
        ///     Add a contact group using the contact group name
        /// </summary>
        /// <param name="groupName">The contact group name</param>
        /// <returns>A <see cref="ContactGroup" /> object.</returns>
        /// <exception cref="Exception">Exception with the appropriate message</exception>
        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);
        }
Example #3
0
        /// <summary>
        ///     Update a contact group using the contact group name
        /// </summary>
        /// <param name="groupId">The contact group Id</param>
        /// <param name="groupName">The contact group name</param>
        /// <returns>true when successful.</returns>
        /// <exception cref="Exception">Exception with the appropriate message</exception>
        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);
        }
Example #4
0
        /// <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 <see cref="TopupLocation" /></returns>
        /// <exception cref="Exception">Exception with the appropriate message</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);
        }
Example #5
0
        /// <summary>
        ///     Add a content media
        /// </summary>
        /// <param name="mediaInfo">The content media data <see cref="MediaInfo" /></param>
        /// <returns>
        ///     <see cref="ContentMedia" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message</exception>
        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);
        }
Example #6
0
        /// <summary>
        ///     Updates an existing content media and returns the updated content media
        /// </summary>
        /// <param name="contentMediaId">The Content Media ID</param>
        /// <param name="mediaInfo">Content Media Info <see cref="MediaInfo" /></param>
        /// <returns>
        ///     <see cref="ContentMedia" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message.</exception>
        public ContentMedia UpdateContentMedia(Guid contentMediaId, MediaInfo mediaInfo)
        {
            string resource = "/media/";

            resource += contentMediaId.ToString().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);
        }
Example #7
0
        /// <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>
        ///     <see cref="ContentLibrary" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message.</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);
        }
Example #8
0
        /// <summary>
        ///     Get the list of contacts. It can be done by certain filters.
        /// </summary>
        /// <param name="page">The page index</param>
        /// <param name="pageSize">The number of the items on a page.</param>
        /// <param name="groupId">The group id.</param>
        /// <param name="filter">The search filter.</param>
        /// <returns>Custom List of <see cref="Contact" /> object. <seealso cref="ApiList{T}" /></returns>
        /// <exception cref="Exception">Exception with the appropriate message</exception>
        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;
            }
            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 <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);
        }
Example #9
0
        /// <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>Custom List of <see cref="ContentMedia" /> <seealso cref="ApiList{T}" /></returns>
        /// <exception cref="Exception">Exception with the appropriate nessage.</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);
        }
Example #10
0
        /// <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>
        ///     <see cref="ContentLibrary" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message.</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);
        }
Example #11
0
        /// <summary>
        ///     Create a new content folder.
        /// </summary>
        /// <param name="folderName">The folder name</param>
        /// <param name="libraryId">The content library Id</param>
        /// <param name="parentFolder">The parent folder name</param>
        /// <returns>
        ///     <see cref="ContentFolder" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message.</exception>
        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);
        }
Example #12
0
        /// <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>
        ///     <see cref="ContentMedia" />
        /// </returns>
        /// <exception cref="Exception">Exception with the appropriate message.</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);
        }