﻿$(document).ready(function () {

    GetTweets();

});

function GetTweets() {
    $.ajax({
        async: true,
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/pt-br/Twitter/GetRecentTweets",
        dataType: "json",
        success: function (data) {
            var html = "";

            if (data.length == 0)
                html = "Não foram encontrados tweets.";
            else
                html = GetHomeHtml(data);

            $("#tweets").html(html);

        }
    });
}

function GetHomeHtml(data) {
    var tweets = "";

    for (t in data) {
        var tweet = data[t];

        tweets += '<div class="horario">' + tweet.CreateInterval + '</div>';
        tweets += '<div></div>';
        tweets += '<p>' + tweet.Text + '</p>';
    }

    return tweets;
}
