Example #1
0
        public HipchatGetEmoticonResponse GetEmoticon(string shortcut = "")
        {
            using (JsonSerializerConfigScope())
            {
                try
                {
                    return(HipchatEndpoints.GetEmoticonEndpoint
                           .Fmt(shortcut)
                           .AddHipchatAuthentication(_authToken)
                           .GetJsonFromUrl()
                           .FromJson <HipchatGetEmoticonResponse>());
                }
                catch (Exception exception)
                {
                    if (exception is WebException)
                    {
                        throw ExceptionHelpers.WebExceptionHelper(exception as WebException, "view_group");
                    }

                    throw ExceptionHelpers.GeneralExceptionHelper(exception, "GetEmoticon");
                }
            }
        }
Example #2
0
        public HipchatGetUserInfoResponse GetUserInfo(string emailOrMentionName)
        {
            using (JsonSerializerConfigScope())
            {
                try
                {
                    return(HipchatEndpoints.GetUserInfoEndpoint
                           .Fmt(emailOrMentionName)
                           .AddHipchatAuthentication(_authToken)
                           .GetJsonFromUrl()
                           .FromJson <HipchatGetUserInfoResponse>());
                }
                catch (Exception exception)
                {
                    if (exception is WebException)
                    {
                        throw ExceptionHelpers.WebExceptionHelper(exception as WebException, "view_group");
                    }

                    throw ExceptionHelpers.GeneralExceptionHelper(exception, "GetUserInfo");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Gets all webhooks for this room
        /// </summary>
        /// <param name="roomName">The name of the room</param>
        /// <param name="startIndex">The start index for the result set</param>
        /// <param name="maxResults">The maximum number of results</param>
        /// <returns>A GetAllWebhooks Response</returns>
        /// <remarks>
        /// Auth required, with scope 'admin_room'. https://www.hipchat.com/docs/apiv2/method/get_all_webhooks
        /// </remarks>
        public HipchatGetAllWebhooksResponse GetAllWebhooks(string roomName, int startIndex = 0, int maxResults = 0)
        {
            using (JsonSerializerConfigScope())
            {
                try
                {
                    return(HipchatEndpoints.GetAllWebhooksEndpointFormat.Fmt(roomName)
                           .AddQueryParam("start-index", startIndex)
                           .AddQueryParam("max-results", maxResults)
                           .AddHipchatAuthentication()
                           .GetJsonFromUrl()
                           .FromJson <HipchatGetAllWebhooksResponse>());
                }
                catch (Exception exception)
                {
                    if (exception is WebException)
                    {
                        throw ExceptionHelpers.WebExceptionHelper(exception as WebException, "admin_room");
                    }

                    throw ExceptionHelpers.GeneralExceptionHelper(exception, "GetAllWebhooks");
                }
            }
        }
Example #4
0
        /// <summary>
        /// Send a message to a room
        /// </summary>
        /// <param name="roomName">The id of the room</param>
        /// <param name="request">The request containing the info about the notification to send</param>
        /// <returns>true if the message successfully sent</returns>
        /// <remarks>
        /// Auth required with scope 'view_group'. https://www.hipchat.com/docs/apiv2/method/send_room_notification
        /// </remarks>
        public bool SendNotification(string roomName, SendRoomNotificationRequest request)
        {
            using (JsonSerializerConfigScope())
            {
                if (request.Message.IsEmpty() || request.Message.Length > 10000)
                {
                    throw new ArgumentOutOfRangeException("request",
                                                          "message length must be between 0 and 10k characters");
                }

                var result = false;
                try
                {
                    HipchatEndpoints.SendNotificationEndpointFormat
                    .Fmt(roomName)
                    .AddHipchatAuthentication()
                    .PostJsonToUrl(request, null, x =>
                    {
                        if (x.StatusCode == HttpStatusCode.NoContent)
                        {
                            result = true;
                        }
                    });
                }
                catch (Exception exception)
                {
                    if (exception is WebException)
                    {
                        throw ExceptionHelpers.WebExceptionHelper(exception as WebException, "send_notification");
                    }

                    throw ExceptionHelpers.GeneralExceptionHelper(exception, "SendNotification");
                }
                return(result);
            }
        }