Mostrar mensagens com a etiqueta json. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta json. Mostrar todas as mensagens

quarta-feira, 5 de junho de 2013

Send sms using NEXMO Api




'Create a new class SmsSender or another name
-----------------------------------------
Imports System.Collections.Generic
Imports  System.Net
Imports System.Web
Imports  System.Web.Script
Imports System.Web.Script.Serialization

Namespace API

    Class SmsSender

        Public Function SendSMS(ByVal _numberPara As String, ByVal _fromLab As String, ByVal _smsText As String, ByVal _apiKey As String, ByVal _apiCode As String) As SmsResponse

            Dim uri As String = String.Format("http://rest.nexmo.com/sms/json?api_key={0}&api_secret={1}&from={2}&to={3}&type=unicode&text={4}", _apiKey, _apiCode, _fromLab, _numberPara, _smsText)

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

            Dim json = New WebClient().DownloadString(uri)

            Return ParseSmsResponseJson(json)

        End Function

'Function to format the Json Response 

        Private Function ParseSmsResponseJson(ByVal json As String) As SmsResponse
            ' hyphens are not allowed in in .NET var names
            json = json.Replace("message-count", "MessageCount")
            json = json.Replace("message-price", "MessagePrice")
            json = json.Replace("message-id", "MessageId")
            json = json.Replace("remaining-balance", "RemainingBalance")
            json = json.Replace("error-text", "ErrorText") 'Adicionei
            Return New JavaScriptSerializer().Deserialize(Of SmsResponse)(json)

        End Function

    End Class

'-------------------------------------------
'Create a new class Message
'Property for each message
'-------------------------------------------

    Public Class Message

        Private m_To As String
        Public Property [To]() As String
            Get
                Return m_To
            End Get
            Set(ByVal value As String)
                m_To = value
            End Set
        End Property

        Private m_Messageprice As String
        Public Property Messageprice() As String
            Get
                Return m_Messageprice
            End Get
            Set(ByVal value As String)
                m_Messageprice = value
            End Set
        End Property

        Private m_Status As String
        Public Property Status() As String
            Get
                Return m_Status
            End Get
            Set(ByVal value As String)
                m_Status = value
            End Set
        End Property

        'Adicionei esta variavel + Propriedade
        Private m_StatusError As String
        Public Property StatusError() As String
            Get
                Return m_StatusError
            End Get
            Set(ByVal value As String)
                m_StatusError = value
            End Set
        End Property

        Private m_MessageId As String
        Public Property MessageId() As String
            Get
                Return m_MessageId
            End Get
            Set(ByVal value As String)
                m_MessageId = value
            End Set
        End Property

        Private m_RemainingBalance As String
        Public Property RemainingBalance() As String
            Get
                Return m_RemainingBalance
            End Get
            Set(ByVal value As String)
                m_RemainingBalance = value
            End Set
        End Property

    End Class

'-------------------------------------------
'Create a new class SmsResponse
'Here we get the response from Nexmo
'with number of message sent and 
'a list for each message with Status
'-------------------------------------------

    Public Class SmsResponse

        Private m_Messagecount As String
        Public Property Messagecount() As String
            Get
                Return m_Messagecount
            End Get
            Set(ByVal value As String)
                m_Messagecount = value
            End Set
        End Property

        Private m_Messages As List(Of Message)
        Public Property Messages() As List(Of Message)
            Get
                Return m_Messages
            End Get
            Set(ByVal value As List(Of Message))
                m_Messages = value
            End Set
        End Property


    End Class

End Namespace

'-----------------------------
'How to use:
'Create a Windows Form 
'Or a WebPage in Asp.Net
'-----------------------------

Imports System.Net
Imports System.IO
Imports SMS.API

 Dim _api As New _cClass_LSettings

    Dim _apiKey, _apiCode, _apiRemetente, _apiDestinatario, _apiSMStext As String

    Dim _smsNexmo As New SmsSender

    Dim _resposta As New SmsResponse

Private Sub _smsAPI()


        _resposta = _smsNexmo.SendSMS("Country Code" & txt_destinatario.Text, _api.remetente,                     txt_msg.Text, _api.apiKey, _api.apiCode)

'Get sms status If was or Not Send 
        If _resposta.Messagecount > 1 Then ' if more then 1 message

            For Each item In _resposta.Messages
               
                    'Save the response
                _lblStatus.Visible = True

                'Save a big message(2 or more parts) in the same row in database
                _messagem = _messagem + txt_msg.Text '''''

                _mostrarStatusSMS(item.Status.ToString)

                Exit For

            Next

        Else 'if only 1 messagem

            For Each item In _resposta.Messages

                _lblStatus.Visible = True

                _mostrarStatusSMS(item.Status.ToString)

         Next

   End If

End Sub

--------------------------

A DEMO Project - NexmoSMS_SourceCode





segunda-feira, 3 de setembro de 2012

Get Images with Flickr API and JSON + JQuery



Get images with Flickr API for your webpage

First : create a .js file  (EX: JQflirck.js)

//Second : Put the bellow code

$(document).ready(function () {
buscarimagens();
setInterval("slideSwitch_info()", 3000);
imagens();
});

//images with animation
function buscarimagens() {
$.getJSON(
"http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",{

tags:
"dog",tagmode:
"any",format:
"json",},

function (dados, status) {$.each(dados.items,
function (i, item) {
$("<img/>").attr("src", item.media.m).appendTo("#flickr_img");
if (i == 4) return false;
});

// using animation
$('#flickr_img img:first').addClass('active'); //atribuir class:active a primeira imagem});

}

//simple images

 function imagens() {
$.getJSON(
"http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",{

tags:
"cat",tagmode:
"any",format:
"json",},

function (dados, status) {
$.each(dados.items,
function (i, item)
 {
$("<img/>").attr("src", item.media.m).appendTo("#imagens");
if (i == 10) return false; //Limitar o retorno de nr de items 0,1,...,10});
});
}


//JQuery animation function
function slideSwitch_info() {

var $active = $('#flickr_img IMG.active');
if ($active.length == 0) $active = $('#flickr_img IMG:last');
var $next = $active.next().length ? $active.next(): $(
'#flickr_img IMG:first');$active.addClass(
'last-active');$next.css({ opacity: 0.0 })
.addClass('active').animate({ opacity: 1.0 }, 1000,
function () {$active.removeClass('active last-active');
});
}

//Create a html page( or use in your web page)

<html ><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<!-- FLICKR file function-->
<script type="text/javascript" src="jq/JQflirck.js"></script>
<!--end FLICKR -->

<style type="text/css" >

#page{ margin:0 auto; width:900px; height:600px;}

#flickr { float:left; position:relative;}


/* flickr_img Animation*/#flickr_img IMG {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
width: 400px;
height: 300px}#flickr_img IMG.active { z-index:10; opacity:1.0; }
#flickr_img IMG.last-active { z-index:9; }
/*END flickr_img Animation*/
#splt{float:right;width:450px;height:300px; padding-left:20px;}
#Fimg{ padding-top:20px; margin:20px; float:left; position :relative;}


</style>  

<title>FlickrJQuery</title></
head>
<body >
 <div id="page">  
 <div id="flickr">  
    <div id="flickr_img"> 
   <!-- Div where the images will apear and animated with jquery-->      </div>  
 </div>
<div id="splt">
<p>
On the left we have images from <br /><br />
Flickr API<br /><br />
animated with JQuery Function
</p>
<hr />
<p>
On bottom we have images from<br /><br />
Flickr API<br /><br />
Simple Way
</p>
</div>
<div id="Fimg">   
   
   <div id="imagens">   
  <!-- Div where the images will apear -->

   </div>  <!---->
</div>
</div>

</body></
html>
Demo1

Demo2 - all the images came from flickr with API


sábado, 9 de junho de 2012

RSS post's convert into HTML page


-function that get the rss link and pass thru the Google AJAX Api and transform into json format, then is treated like a JSON file.


First : create a JQuery file (EX: configRSS.js) and put the below code
$(document).ready(function () {
        RssFeed();
});

function RssFeed(){
    var url = "http://your_blog_name/feeds/posts/default?alt=rss";
    $.ajax({
        url: 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
        dataType: 'json',
        success: function (data) {
            var rssDestino = $("#divRSS");    //  div of destination
            var feedEntrys = data.responseData.feed.entries;  //  post of blog
            var blogTitle = data.responseData.feed.title; // name of blog
            var blogUrl = data.responseData.feed.link; // link post
            rssDestino.empty(); //empty the div before
            rssDestino.append('<h2><a href="' + blogUrl + '">' + blogTitle + '</a></h2>'); // title
//now for each post....
            for (var i = 0; i < feedEntrys.length; i++) {
                var pubdate = new Date(feedEntrys[i].publishedDate);
                var dataPost = pubdate.toLocaleDateString();
                rssDestino.append('<p><i> <u>Data de Publicação:</u> ' + dataPost + '</i>  <a href="' + feedEntrys[i].link +
                 '"><b>Url Post</b></a></p>');
                rssDestino.append('<p>' + feedEntrys[i].content + '</p>');
                rssDestino.append('<hr />');
            }
        }
    });
}

Second : create the  HTML page

<html>
<head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

 <script  type="text/javascript" src="jq/configRSS.js"></script>

</head>
<body>

<div id="divRSS">
       here will appear the rss feeds
</div>

</body>
</html>

Example: See Demo