Exemplo n.º 1
0
        public override HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse response  = new HTTPResponse(200);
            string       user      = request.getRequestByKey("user");
            string       password  = request.getRequestByKey("password");
            string       following = request.getRequestByKey("follow");
            string       message   = request.getRequestByKey("message");

            string[] path = request.Filename.Split("?");
            if (path[0] == "users")
            {
                if (request.Method == "GET")
                {
                    string json = JsonConvert.SerializeObject(GetAllUsers());
                    response.body = Encoding.UTF8.GetBytes(json);
                }
                else if (request.Method == "POST")
                {
                    try
                    {
                        Twitter.AddUser(user, password);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 403;
                        response.body   = Encoding.UTF8.GetBytes("403 User already exists");
                    }
                }
                else if (request.Method == "DELETE")
                {
                    try
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.DeleteUser(user);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
            }
            else if (path[0] == "following")
            {
                if (request.Method == "GET")
                {
                    string json = JsonConvert.SerializeObject(GetFollowing(user));
                    response.body = Encoding.UTF8.GetBytes(json);
                }
                else if (request.Method == "POST")
                {
                    if (Twitter.CheckUser(following))
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.AddFollowing(following);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    else
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
                else if (request.Method == "DELETE")
                {
                    try
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.RemoveFollowing(following);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
            }
            else if (path[0] == "tweets")
            {
                if (request.Method == "GET")
                {
                    try
                    {
                        string timeline = request.getRequestByKey("timeline");
                        if (timeline == "following")
                        {
                            Twitter twitter = new Twitter(user);
                            string  json    = JsonConvert.SerializeObject(twitter.GetFollowingTimeline());
                            response.body = Encoding.UTF8.GetBytes(json);
                        }
                        else
                        {
                            Twitter twitter = new Twitter(user);
                            string  json    = JsonConvert.SerializeObject(twitter.GetUserTimeline());
                            response.body = Encoding.UTF8.GetBytes(json);
                        }
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not found");
                    }
                }
                else if (request.Method == "POST")
                {
                    try
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.PostTweet(message);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not found");
                    }
                }
            }
            response.type = "application/json";
            return(response);
        }
Exemplo n.º 2
0
        public override HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse response = new HTTPResponse(200);

            string u        = request.getRequestByKey("user");
            string p        = request.getRequestByKey("password");
            string f        = request.getRequestByKey("following");
            string text     = request.getRequestByKey("text");
            string timeline = request.getRequestByKey("timeline");

            string [] path = request.Filename.Split("?");
            if (path[0] == "user")
            {
                if (request.Method == "GET")
                {
                    string temp = JsonConvert.SerializeObject(GetUser());
                    response.body = Encoding.UTF8.GetBytes(temp);
                }
                if (request.Method == "POST")
                {
                    Twitter.AddUser(u, p);
                    response.body = Encoding.UTF8.GetBytes("ADD Success");
                }
                if (request.Method == "DELETE")
                {
                    Twitter.DeleteUser(u);
                    response.body = Encoding.UTF8.GetBytes("Delete Success");
                }
            }
            if (path[0] == "follow")
            {
                Twitter twitter = new Twitter(u);
                if (request.Method == "GET")
                {
                    string temp = JsonConvert.SerializeObject(GetFollow(u));
                    response.body = Encoding.UTF8.GetBytes(temp);
                }
                if (request.Method == "POST")
                {
                    Twitter follow = new Twitter(u);
                    follow.AddFollowing(f);
                    response.body = Encoding.UTF8.GetBytes("Success Following");
                }
            }
            if (path[0] == "Tweet")
            {
                Twitter twitter = new Twitter(u);
                if (request.Method == "GET")
                {
                    if (timeline == "user")
                    {
                        string temp = JsonConvert.SerializeObject(twitter.GetUserTimeline());
                        response.body = Encoding.UTF8.GetBytes(temp);
                    }
                    if (timeline == "follow")
                    {
                        string temp = JsonConvert.SerializeObject(twitter.GetFollowingTimeline());
                        response.body = Encoding.UTF8.GetBytes(temp);
                    }
                }
                if (request.Method == "POST")
                {
                    twitter.PostTweet(text);
                    response.body = Encoding.UTF8.GetBytes("Post Success");
                }
            }
            return(response);
        }
Exemplo n.º 3
0
        public override HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse response  = new HTTPResponse(200);
            string       user      = request.getRequestByKey("user");
            string       password  = request.getRequestByKey("password");
            string       following = request.getRequestByKey("following");
            string       message   = request.getRequestByKey("message");

            string[] u = request.Filename.Split("?");
            if (u[0] == "users")
            {
                if (request.Method == "GET")
                {
                    string x = JsonConvert.SerializeObject(GetUser());
                    response.body = Encoding.UTF8.GetBytes(x);
                }
                if (request.Method == "POST")
                {
                    Twitter.AddUser(user, password);
                    response.body = Encoding.UTF8.GetBytes("Susceed");
                }
                if (request.Method == "DELETE")
                {
                    Twitter.DeleteUser(user);
                    response.body = Encoding.UTF8.GetBytes("Susceed");
                }
            }
            if (u[0] == "follow")
            {
                if (request.Method == "GET")
                {
                    string x = JsonConvert.SerializeObject(Twitter.GetfollowUser(user));
                    response.body = Encoding.UTF8.GetBytes(x);
                }
                if (request.Method == "POST")
                {
                    Twitter ntwitter = new Twitter(user);
                    ntwitter.AddFollowing(following);
                    response.body = Encoding.UTF8.GetBytes("Following Susceed");
                }

                /*if (request.Method == "DELETE")
                 * {
                 *  Twitter.DeleteUser(following);
                 *  response.body = Encoding.UTF8.GetBytes("Susceed");
                 * }*/
            }
            if (u[0] == "tweet")
            {
                Twitter ntweet = new Twitter(user);
                if (request.Method == "GET")
                {
                    string timeline = request.getRequestByKey("timeline");
                    if (timeline == "follow")
                    {
                        string x = JsonConvert.SerializeObject(ntweet.GetFollowingTimeline());
                        response.body = Encoding.UTF8.GetBytes(x);
                    }
                    else
                    {
                        string x = JsonConvert.SerializeObject(ntweet.GetUserTimeline());
                        response.body = Encoding.UTF8.GetBytes(x);
                    }
                }
                if (request.Method == "POST")
                {
                    ntweet.PostTweet(message);
                    response.body = Encoding.UTF8.GetBytes("Post Susceed");
                }
            }

            return(response);
        }
Exemplo n.º 4
0
        public override HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse response = new HTTPResponse(200);

            string user      = request.getRequestByKey("user");
            string password  = request.getRequestByKey("password");
            string following = request.getRequestByKey("follow");
            string timeline  = request.getRequestByKey("timeline");
            string message   = request.getRequestByKey("message");

            string[] at = request.Filename.Split("?");
            if (at[0] == "users")
            {
                if (request.Method == "GET")
                {
                    string j = JsonConvert.SerializeObject(ListUser());
                    response.body = Encoding.UTF8.GetBytes(j);
                }
                else if (request.Method == "POST")
                {
                    if (user != null && password != null)
                    {
                        Twitter.AddUser(user, password);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    else
                    {
                        response.status = 403;
                        response.body   = Encoding.UTF8.GetBytes("403 User invalid");
                    }
                }
                else if (request.Method == "DELETE")
                {
                    try
                    {
                        Twitter.DeleteUser(user);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
            }
            else if (at[0] == "following")
            {
                if (request.Method == "GET")
                {
                    Twitter follow = new Twitter(user);
                    string  temp   = JsonConvert.SerializeObject(GetFollow(user));
                    response.body = Encoding.UTF8.GetBytes(temp);
                }
                else if (request.Method == "POST")
                {
                    if (user != null && following != null)
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.AddFollowing(following);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    else
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
                else if (request.Method == "DELETE")
                {
                    try
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.RemoveFollowing(following);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
            }
            if (at[0] == "tweets")
            {
                Twitter twitter = new Twitter(user);
                if (request.Method == "GET")
                {
                    {
                        if (timeline == "users")
                        {
                            string temp = JsonConvert.SerializeObject(twitter.GetUserTimeline());
                            response.body = Encoding.UTF8.GetBytes(temp);
                        }
                        if (timeline == "follow")
                        {
                            string temp = JsonConvert.SerializeObject(twitter.GetFollowingTimeline());
                            response.body = Encoding.UTF8.GetBytes(temp);
                        }
                    }
                    if (request.Method == "POST")
                    {
                        twitter.PostTweet(message);
                        response.body = Encoding.UTF8.GetBytes("202 OK");
                    }
                }
                return(response);
            }

            return(response);
        }
Exemplo n.º 5
0
        public override HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse response = new HTTPResponse(200);

            string user           = request.getRequestByKey("user");
            string password       = request.getRequestByKey("password");
            string Follow         = request.getRequestByKey("following");
            string followtimeline = request.getRequestByKey("timeline");
            string message        = request.getRequestByKey("message");

            string[] path = request.Filename.Split("?"); //teach dy 600611030

            if (path[0] == "User")
            {
                if (request.Method == "GET")
                {
                    string y = JsonConvert.SerializeObject(GetUser());
                    response.body = Encoding.UTF8.GetBytes(y);
                }
                if (request.Method == "POST")
                {
                    Twitter.AddUser(user, password);
                    response.body = Encoding.UTF8.GetBytes("Add user success");
                }
                if (request.Method == "DELETE")
                {
                    Twitter.DeleteUser(user, password);
                    response.body = Encoding.UTF8.GetBytes("Delete user success");
                }
            }
            else if (path[0] == "following")
            {
                //Twitter twitter = new Twitter(user);
                if (request.Method == "GET")
                {
                    Twitter twitters = new Twitter(user);
                    string  js       = JsonConvert.SerializeObject(twitters.GetFollowing());
                    response.body = Encoding.UTF8.GetBytes(js);
                }
                else if (request.Method == "POST")
                {
                    if (Twitter.Check_User(Follow))
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.AddFollowing(Follow);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    else
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
                else if (request.Method == "DELETE")
                {
                    try
                    {
                        Twitter twitter = new Twitter(user);
                        twitter.RemoveFollowing(Follow);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
            }

            else if (request.Method == "DELETE")
            {
                try
                {
                    Twitter twitter = new Twitter(user);
                    twitter.RemoveFollowing(Follow);
                    response.body = Encoding.UTF8.GetBytes("200 OK");
                }
                catch (Exception)
                {
                    response.status = 404;
                    response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                }
            }

            else if (path[0] == "Tweett")
            {
                Twitter twitter = new Twitter(user);
                if (request.Method == "GET")
                {
                    try
                    {
                        string timeline = request.getRequestByKey("timeline");
                        if (timeline == "following")
                        {
                            string json = JsonConvert.SerializeObject(twitter.GetFollowingTimeline());
                            response.body = Encoding.UTF8.GetBytes(json);
                        }
                        else
                        {
                            string json = JsonConvert.SerializeObject(twitter.GetUserTimeline());
                            response.body = Encoding.UTF8.GetBytes(json);
                        }
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not found");
                    }
                }
                else if (request.Method == "POST")
                {
                    try
                    {
                        twitter.PostTweet(message);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch (Exception)
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not found");
                    }
                }
            }

            return(response);
        }
Exemplo n.º 6
0
        public new HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse  response  = new HTTPResponse(200);
            string        user      = request.getRequestByKey("user");
            string        password  = request.getRequestByKey("Password");
            string        following = request.getRequestByKey("follow");
            string        message   = request.getRequestByKey("message");
            StringBuilder sb        = new StringBuilder();

            string[] url = request.Filename.Split("?");
            if (url[0] == "user")
            {
                if (request.Method == "GET")//get list's user
                {
                    string Json = JsonConvert.SerializeObject(GetUsers());
                    response.body = Encoding.UTF8.GetBytes(Json);
                }
                else if (request.Method == "POST") //create new user
                {
                    try {
                        Twitter.AddUser(user, password);
                    }
                    catch (Exception)
                    {
                        sb.Append("<h1>Error</h1>");
                    }
                }
                else if (request.Method == "Delete") //remove user
                {
                    try
                    {
                        Twitter.DeleteUser(user, password);
                    }
                    catch (Exception)
                    {
                        sb.Append("<h1>Error</h1>");
                    }
                }
            }
            else if (url[0] == "Follow")
            {
                Twitter twitter = new Twitter(user);
                if (request.Method == "GET")//list following
                {
                    string Json = JsonConvert.SerializeObject(GetFollowings(user));
                    response.body = Encoding.UTF8.GetBytes(Json);
                }
                else if (request.Method == "POST")//add new following
                {
                    try
                    {
                        twitter.AddFollowing(following);
                    }
                    catch (Exception)
                    {
                        sb.Append("<h1>Error</h1>");
                    }
                }
                else if (request.Method == "DELETE")//delete following
                {
                    try
                    {
                        twitter.RemoveFollowing(following);
                    }
                    catch (Exception)
                    {
                        sb.Append("<h1>Error</h1>");
                    }
                }
            }
            else if (url[0] == "tweet")
            {
                Twitter twitter = new Twitter(user);
                if (request.Method == "GET")//get usr's and following's timeline
                {
                    try
                    {
                        string timeline = request.getRequestByKey("timeline");
                        if (timeline == "follow")
                        {
                            string Json = JsonConvert.SerializeObject(twitter.GetFollowingTimeline());
                            response.body = Encoding.UTF8.GetBytes(Json);
                        }
                        else
                        {
                            string Json = JsonConvert.SerializeObject(twitter.GetUserTimeline());
                            response.body = Encoding.UTF8.GetBytes(Json);
                        }
                    }
                    catch (Exception)
                    {
                        sb.Append("<h1>Error</h1>");
                    }
                }
                else if (request.Method == "POST")//add new tweet
                {
                    try
                    {
                        twitter.PostTweet(message);
                    }
                    catch (Exception)
                    {
                        sb.Append("<h1>Error</h1>");
                    }
                }
            }


            response.type = "application/json";
            return(response);
        }
Exemplo n.º 7
0
        public override HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse response  = new HTTPResponse(200);
            string       user      = request.getRequestByKey("user");
            string       password  = request.getRequestByKey("password");
            string       following = request.getRequestByKey("follow");
            string       message   = request.getRequestByKey("message");

            string[] link = request.Filename.Split("?");
            if (link[0] == "user")
            {
                if (request.Method == "GET")
                {
                    string json = JsonConvert.SerializeObject(GetUsers());
                    response.body = Encoding.UTF8.GetBytes(json);
                }
                else if (request.Method == "POST")
                {//create new user require new username and newpassword
                    if (user != null && password != null)
                    {
                        Twitter.AddUser(user, password);
                        response.body = Encoding.UTF8.GetBytes("user added");
                    }
                }
                else if (request.Method == "DELETE")
                {   //delete user require username and password
                    Twitter twitter = new Twitter(user);
                    if (user != null && password != null)
                    {
                        twitter.DeleteUser(user);
                        response.body = Encoding.UTF8.GetBytes("deleted");
                    }
                }
            }
            else if (link[0] == "follow")
            {
                Twitter twitter = new Twitter(user);
                if (request.Method == "GET")
                {
                    string json = JsonConvert.SerializeObject(GetFollowing(user));
                    response.body = Encoding.UTF8.GetBytes(json);
                }
                else if (request.Method == "POST")
                {
                    if (Twitter.CheckUser(following))
                    {
                        twitter.AddFollowing(following);
                    }
                    else
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
                else if (request.Method == "DELETE")
                {
                    try
                    {
                        twitter.RemoveFollowing(following);
                        response.body = Encoding.UTF8.GetBytes("deleted");
                    }
                    catch
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not exists");
                    }
                }
            }
            else if (link[0] == "tweet")
            {
                Twitter twitter = new Twitter(user);
                if (request.Method == "GET")
                {
                    try
                    {
                        string timeline = request.getRequestByKey("timeline");
                        if (timeline == "follow")
                        {
                            string json = JsonConvert.SerializeObject(twitter.GetFollowingTimeline());
                            response.body = Encoding.UTF8.GetBytes(json);
                        }
                        else
                        {
                            string json = JsonConvert.SerializeObject(twitter.GetUserTimeline());
                            response.body = Encoding.UTF8.GetBytes(json);
                        }
                    }
                    catch
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not found");
                    }
                }
                else if (request.Method == "POST")
                {
                    try
                    {
                        twitter.PostTweet(message);
                        response.body = Encoding.UTF8.GetBytes("200 OK");
                    }
                    catch
                    {
                        response.status = 404;
                        response.body   = Encoding.UTF8.GetBytes("404 User not found");
                    }
                }
            }
            response.type = "application/json";
            return(response);
        }
Exemplo n.º 8
0
        public override HTTPResponse GetResponse(HTTPRequest request)
        {
            HTTPResponse  response = null;
            StringBuilder sb       = new StringBuilder();

            string[] path = request.Filename.Split("?");
            if (path[0].ToLower() == "user")
            {
                if (request.Status == 200)
                {
                    if (request.Method.ToLower() == "get")//GET
                    {
                        try{
                            response      = new HTTPResponse(200);
                            response.type = "json";
                            response.body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GetListUser())); //get list user
                        }catch (Exception) {
                            response = new HTTPResponse(400);
                        }
                    }
                    else if (request.Method.ToLower() == "post") //POST
                    {
                        try{
                            Twitter.AddUser(request.getRequestByKey("user").ToLower(), request.getRequestByKey("password").ToLower());//add user
                            sb.Append("<html><head><title>TwitterAPI</title></head><body>");
                            sb.Append("Added User : "******"user").ToLower() + " Complete!");
                            sb.Append("</body></html");
                            response      = new HTTPResponse(200);
                            response.body = Encoding.UTF8.GetBytes(sb.ToString());
                        }catch (Exception) {
                            response = new HTTPResponse(400);
                        }
                    }
                    else if (request.Method.ToLower() == "delete") //DELETE
                    {
                        try{
                            Twitter t = new Twitter(request.getRequestByKey("user"));
                            t.DeleteUser(request.getRequestByKey("user"));
                            sb.Append("<html><head><title>TwitterAPI</title></head><body>");
                            sb.Append("Delete User : "******"user").ToLower() + " Complete!");
                            sb.Append("</body></html");
                            response      = new HTTPResponse(200);
                            response.body = Encoding.UTF8.GetBytes(sb.ToString());
                        }catch (Exception) {
                            response = new HTTPResponse(400);
                        }
                    }
                    else  //OTHER ELSE
                    {
                        response = new HTTPResponse(400);
                    }
                }
                else
                {
                    response = new HTTPResponse(400);
                }
            }
            else if (path[0].ToLower() == "following")
            {
                if (request.Status == 200)
                {
                    if (request.Method.ToLower() == "get")
                    {
                        try{
                            response      = new HTTPResponse(200);
                            response.type = "json";
                            response.body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GetListFollowing(request.getRequestByKey("user")))); //get following user
                        }catch (Exception) {
                            response = new HTTPResponse(400);
                        }
                    }
                    else if (request.Method.ToLower() == "post")
                    {
                        try
                        {
                            Twitter t = new Twitter(request.getRequestByKey("user"));
                            t.AddFollowing(request.getRequestByKey("follow"));
                            sb.Append("<html><head><title>TwitterAPI</title></head><body>");
                            sb.Append("User : "******"user").ToLower() + " Start Following : " + request.getRequestByKey("follow") + " Complete!");
                            sb.Append("</body></html");
                            response      = new HTTPResponse(200);
                            response.body = Encoding.UTF8.GetBytes(sb.ToString());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            response = new HTTPResponse(400);
                        }
                    }
                    else if (request.Method.ToLower() == "delete")
                    {
                        try
                        {
                            Twitter t = new Twitter(request.getRequestByKey("user"));
                            t.RemoveFollowing(request.getRequestByKey("follow"));
                            sb.Append("<html><head><title>TwitterAPI</title></head><body>");
                            sb.Append("User : "******"user").ToLower() + " Unfollowing : " + request.getRequestByKey("follow") + " Complete!");
                            sb.Append("</body></html");
                            response      = new HTTPResponse(200);
                            response.body = Encoding.UTF8.GetBytes(sb.ToString());
                        }
                        catch (Exception)
                        {
                            response = new HTTPResponse(400);
                        }
                    }
                    else
                    {
                        response = new HTTPResponse(400);
                    }
                }
                else
                {
                    response = new HTTPResponse(400);
                }
            }
            else if (path[0].ToLower() == "tweet")
            {
                if (request.Status == 200)
                {
                    if (request.Method.ToLower() == "get")
                    {
                        if (request.getRequestByKey("getlist").ToLower() == "user")
                        {
                            try
                            {
                                Twitter t = new Twitter(request.getRequestByKey("user"));
                                response      = new HTTPResponse(200);
                                response.type = "json";
                                response.body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(t.GetUserTimeline()));
                            }
                            catch (Exception)
                            {
                                response = new HTTPResponse(400);
                            }
                        }
                        else if (request.getRequestByKey("getlist").ToLower() == "following")
                        {
                            try
                            {
                                Twitter t = new Twitter(request.getRequestByKey("user"));
                                response      = new HTTPResponse(200);
                                response.type = "json";
                                response.body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(t.GetFollowingTimeline()));
                            }
                            catch (Exception ex)
                            {
                                Console.Write(ex.ToString());
                                response = new HTTPResponse(400);
                            }
                        }
                        else
                        {
                            response = new HTTPResponse(400);
                        }
                    }
                    else if (request.Method.ToLower() == "post")
                    {
                        try
                        {
                            Twitter t = new Twitter(request.getRequestByKey("user"));
                            t.PostTweet(request.getRequestByKey("tweet"));
                            sb.Append("<html><head><title>TwitterAPI</title></head><body>");
                            sb.Append("User : "******"user").ToLower() + " Tweet : " + request.getRequestByKey("tweet"));
                            sb.Append("</body></html");
                            response      = new HTTPResponse(200);
                            response.body = Encoding.UTF8.GetBytes(sb.ToString());
                        }
                        catch (Exception)
                        {
                            response = new HTTPResponse(400);
                        }
                    }
                    else
                    {
                        response = new HTTPResponse(400);
                    }
                }
                else
                {
                    response = new HTTPResponse(400);
                }
            }
            else
            {
                sb.Append("<html><head><title>TwitterAPI</title></head><body>");
                sb.Append("<h1>TwitterAPI</h1>");
                sb.Append("</body></html");
                response      = new HTTPResponse(200);
                response.body = Encoding.UTF8.GetBytes(sb.ToString());
            }
            return(response);
        }