// GET: http://www.qcue.me/api/incoming_sms?to=447860033153&from=441234567890&content=Hello+World&msg_id=AB_12345
        public HttpResponseMessage Get([FromUri]IncomingSmsMessage message)
        {
            Trace.TraceInformation("Message: {0}", message);

            /*
            if (this.ModelState.IsValid)
            {
                Trace.TraceInformation("Message: {0}", message);
                return Request.CreateResponse(HttpStatusCode.BadRequest, this.ModelState);
            }
            */

            var qbase = new QBase("https://qcue-live.firebaseio.com");
            var user = qbase.GetUserByMobile(message.From);

            // this.EnsureUserIsKnown(message, user);

            if (this.IsUpdateUserMessage(message))
            {
                this.UpdateUser(message, qbase, user);
            }
            else
            {
                this.QueueUser(message, qbase, user);
            }

            var response = this.Request.CreateResponse(HttpStatusCode.OK);

            return response;
        }
        public Q Get(string id)
        {
            var qbase = new QBase("https://qcue-live.firebaseio.com");
            var queue = qbase.GetQueueByShortCode(id);

            return queue;
        }
Ejemplo n.º 3
0
        public User Get(string id)
        {
            var qbase = new QBase("https://qcue-live.firebaseio.com");

            var user = qbase.GetUserByMobile(id);

            return user;
        }
        private void QueueUser(IncomingSmsMessage message, QBase qbase, User user)
        {
            var q = qbase.GetQueueByShortCode(message.Content);

            this.EnsureQueueIsKnown(message, q);

            string status = null;

            if (user == null)
            {
                user = qbase.AddAnonymousUser(message.From);
                // TODO: status = "registering";
                status = "joined";
            }
            else
            {
                /*
                var usersInQueue = qbase.GetUsersInQueue(q.queueId);

                if (usersInQueue.Count(each => each.userId == user.userId) != 0)
                {
                    string warningMessage = String.Format(
                        "User \"{0}\" is already in queue \"{1}\". User will not be added again.",
                        user.userId,
                        q.queueId);

                    Trace.TraceWarning(warningMessage);
                    return;
                }
                */

                status = "joined";
            }

            qbase.AddUserToQueue(q.queueId, new QUser
            {
                userId = user.userId,
                status = status
            });
        }
        private void UpdateUser(IncomingSmsMessage message, QBase qbase, User user)
        {
            string fullName = message.Content.Substring(NameTag.Length).Trim();

            user.fullName = fullName;
            user.status = "registered";

            qbase.UpdateUser(user);

            Trace.TraceInformation(
                "Updated user.fulName for \"{0}\" to \"{1}\"", user.userId, user.fullName);
        }