Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ''(C) 2011 - VIALAT Mickaël
- ''
- '' Boutique en ligne de produit domotique : http://www.planete-domotique.com
- ''
- '' This code is free software; you can redistribute it and/or
- '' modify it under the terms of the GNU Lesser General Public
- '' License as published by the Free Software Foundation; either
- '' version 2.1 of the License, or (at your option) any later version.
- ''
- '' This code is distributed in the hope that it will be useful,
- '' but WITHOUT ANY WARRANTY; without even the implied warranty of
- '' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- '' GNU Lesser General Public License for more details.
- ''
- '' You should have received a copy of the GNU Lesser General Public
- '' License along with this program; if not, write to the Free
- '' Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- ''
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- Imports System.Web
- Imports System.Security.Cryptography
- Imports System.Net
- Imports System.IO
- Imports System.Xml
- Public Class Karotz
- Private _InteractiveID As String
- Public Sub New()
- _InteractiveID = ""
- End Sub
- Private Function getSHA1Hash(ByVal strToHash As String, ByVal strKey As String) As Byte()
- Dim bytesKey() As Byte = System.Text.Encoding.ASCII.GetBytes(strKey)
- Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)
- Dim hmacsha1 As New HMACSHA1(bytesKey)
- bytesToHash = hmacsha1.ComputeHash((bytesToHash))
- Return bytesToHash
- End Function
- Private Function getTimeStamp() As Long
- Return CType(DateTime.UtcNow.Subtract(#1/1/1970#).TotalSeconds, Long)
- End Function
- Private Function URLEncode(ByVal StringToEncode As String) As String
- Dim TempAns As String
- Dim CurChr As Integer
- CurChr = 1
- TempAns = ""
- Do Until CurChr - 1 = Len(StringToEncode)
- Select Case Asc(Mid(StringToEncode, CurChr, 1))
- Case 48 To 57, 65 To 90, 97 To 122
- TempAns = TempAns & Mid(StringToEncode, CurChr, 1)
- Case 32
- TempAns = TempAns & "%" & Hex(32)
- Case Else
- TempAns = TempAns & "%" & Format(Asc(Mid(StringToEncode, CurChr, 1)), "X2")
- End Select
- CurChr = CurChr + 1
- Loop
- URLEncode = TempAns
- End Function
- Sub LoadURL(ByVal url As String)
- Dim client As WebClient = New WebClient()
- Dim data As Stream = client.OpenRead(url)
- End Sub
- Public Sub StartKarotz(ByVal apikey As String, ByVal installid As String, ByVal secret As String)
- Dim url As String
- Dim query As String
- Dim r As New Random(System.DateTime.Now.Millisecond)
- Dim urlkarotz As String
- urlkarotz = "http://api.karotz.com/api/karotz/start"
- query = "apikey=" & apikey & "&installid=" & installid & "&once=" & r.Next(0, 999999999) & "×tamp=" & getTimeStamp()
- url = urlkarotz & "?" & query & "&signature=" & URLEncode(Convert.ToBase64String(getSHA1Hash(query, secret)))
- Dim client As WebClient = New WebClient()
- Dim data As Stream = client.OpenRead(url)
- Dim sr As New StreamReader(data)
- Dim Xml As String
- Dim line As String
- Xml = ""
- Do
- line = sr.ReadLine()
- Xml = Xml & line
- Loop While line IsNot Nothing
- Dim xDoc As XmlDocument = New XmlDocument()
- Dim xNodeList As XmlNodeList
- xDoc.LoadXml(Xml)
- xNodeList = xDoc.GetElementsByTagName("interactiveId")
- _InteractiveID = xNodeList(0).InnerText
- End Sub
- '' http://api.karotz.com/api/karotz/interactivemode?action=stop&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub StopKarotz()
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/interactivemode?action=stop&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/ears?left=20&right=-30&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzEars(ByVal left As Integer, ByVal rigth As Integer)
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/ears?left=" & left & "&right=" & rigth & "&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/led?action=pulse&color=77FF44&period=3000&pulse=500&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzLedPulse(ByVal color As String, ByVal period As Integer, ByVal pulse As Integer)
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/led?action=pulse&color=" & color & "&period=" & period & "&pulse=" & pulse & "&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/led?action=fade&color=77FF44&period=3000&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzLedFade(ByVal color As String, ByVal period As Integer)
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/led?action=fade&color=" & color & "&period=" & period & "&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/led?action=light&color=77FF44&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzLedLight(ByVal color As String)
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/led?action=light&color=" & color & "&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/tts?action=speak&lang=EN&text=hello%20world&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzTTSSpeak(ByVal txt As String, Optional ByVal lang As String = "FR")
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/tts?action=speak&lang=" & lang & "&text=" & txt & "&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/tts?action=stop&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzTTSStop()
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/tts?action=stop&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/multimedia?action=play&url=http%3A%2F%2Fgoogle.com%2Ftest.mp3&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzMultimediaPlay(ByVal url As String)
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/multimedia?action=play&url=" & url & "&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/multimedia?action=pause&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzMultimediaPause(ByVal url As String)
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/multimedia?action=pause&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/multimedia?action=resume&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzMultimediaResume()
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/multimedia?action=resume&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/multimedia?action=stop&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzMultimediaStop()
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/multimedia?action=stop&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/multimedia?action=previous&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzMultimediaPrevious()
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/multimedia?action=previous&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/multimedia?action=next&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzMultimediaNext()
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/multimedia?action=next&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- '' http://api.karotz.com/api/karotz/webcam?action=photo&url=http://blah&interactiveid=3e910454-a6e4-48b0-bd16-4483360947fc
- Public Sub actionKarotzWebcam(ByVal urlPost As String)
- Dim sUrl As String
- If (_InteractiveID <> "") Then
- sUrl = "http://api.karotz.com/api/karotz/webcam?action=photo&url=" & urlPost & "&interactiveid=" & _InteractiveID
- LoadURL(sUrl)
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement