Example #1
0
        public static void Main(string[] args)
        {
            var apiKey = File.ReadAllText(@"C:\hipchatapikey.txt");

            IRoomService core = new RoomService(apiKey);
            IEmoticonService emo = new EmoticonService(apiKey);

            var single = emo.GetEmoticon("un");

            var emoticons = emo.GetEmoticons();

            foreach (var emote in emoticons)
            {
                System.Console.WriteLine("{0}: ({1}) {2}, {3}", emote.Id, emote.Shortcut, emote.Url, emote.Links.Self);
            }

            var rooms = core.GetRooms();

            foreach (var room in rooms)
            {
                System.Console.WriteLine("{0}: {1} ({2})", room.Id, room.Name, room.Links.Self);
            }

            System.Console.WriteLine("Done");
            System.Console.Read();
        }
        public ActionResult Index(string apiKey)
        {
            if (string.IsNullOrWhiteSpace(apiKey))
            {
                return View("NoApiKey");
            }

            // Yup, I'm new()ing things up.
            var roomService = new RoomService(apiKey);
            var rooms = roomService.GetRooms();

            var userService = new UserService(apiKey);
            var users = userService.GetUsers().Where(a => !a.IsDeleted);

            var emoticonService = new EmoticonService(apiKey);
            var emoticons = emoticonService.GetEmoticons();

            var model = new MessageModel
            {
                ApiKey = apiKey,
                Color = "random",
                SuchAnnoy = false,
                IsHtml = false,
                Rooms = rooms.Select(a => new RoomItem
                {
                    Id = a.Id,
                    IsSelected = false,
                    Name = a.Name
                }).ToList(),
                Emoticons = emoticons.Select(a => new EmoticonItem
                {
                    Code = a.Shortcut,
                    IsGlobal = a.Source == EmoticonSource.Global,
                    Url = a.Url
                }).ToList(),
                Users = users.Select(a => new UserItem
                    {
                        Id = a.UserId,
                        Name = a.Name,
                        MentionName = a.Mention_Name
                    }).ToList()
            };

            return View(model);
        }
        public ActionResult Index(MessageModel model)
        {
            var roomService = new RoomService(model.ApiKey);
            var roomId = model.Rooms.Where(a => a.IsSelected).Select(a => (int?)a.Id).FirstOrDefault();
            if (roomId == null)
            {
                return new EmptyResult();
            }

            var message = new Message
            {
                Color = model.Color,
                MessageFormat = model.IsHtml ? MessageFormatEnum.Html : MessageFormatEnum.Text,
                Notify = model.SuchAnnoy,
                Text = model.Message
            };
            roomService.SendMessage(roomId.Value, message);

            return new EmptyResult();
        }