Created
June 14, 2010 12:00
-
-
Save marcheiligers/437594 to your computer and use it in GitHub Desktop.
Classic ASP VBScript Mad Mimi Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<% | |
' Mad Mimi api details | |
Const MAD_MIMI_USERNAME = "" | |
Const MAD_MIMI_API_KEY = "" | |
Const MAD_MIMI_API_URL = "http://api.madmimi.com" | |
' A mini Mimi API lib | |
' ------------------------------------------------------------------------------------------------ | |
Function AddToList(list_name, email) | |
Dim url, params | |
url = AddToListUrl(list_name) | |
Set params = CreateObject("Scripting.Dictionary") | |
params.Add "email", email | |
AddToList = SendPostRequest(url, params) | |
End Function | |
Function AddToListUrl(list_name) | |
' /audience_lists/{name_of_list}/add | |
Dim target | |
target = "/audience_lists/" & list_name & "/add" | |
AddToListUrl = PreparePostUrl(target) | |
End Function | |
Function PrepareGetUrl(target) | |
Dim url, joinchar | |
url = MAD_MIMI_API_URL & target | |
joinchar = "?" | |
If InStr(url, "?") > 0 Then | |
joinchar = "&" | |
End If | |
url = url & joinchar & "username=" & MAD_MIMI_USER_NAME & "&api_key=" & MAD_MIMI_API_KEY | |
PrepareGetUrl = url | |
End Function | |
Function PreparePostUrl(target) | |
Dim url | |
url = MAD_MIMI_API_URL & target | |
PreparePostUrl = url | |
End Function | |
Function SendGetRequest(url) | |
Dim xml | |
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") | |
xml.Open "GET", url, False | |
xml.Send() | |
SendGetRequest = xml.ResponseText | |
End Function | |
Function SendPostRequest(url, params) | |
Dim xml, pkeys, i, body | |
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") | |
xml.Open "POST", url, False | |
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" | |
params.Add "username", MAD_MIMI_USERNAME | |
params.Add "api_key", MAD_MIMI_API_KEY | |
pkeys = params.Keys | |
body = "" | |
For i = 0 To params.Count - 1 | |
If i > 0 Then | |
body = body & "&" | |
End If | |
body = body & Server.URLEncode(pkeys(i)) & "=" & params.Item(pkeys(i)) | |
Next | |
Response.Write(body) | |
xml.Send(body) | |
SendPostRequest = xml.ResponseText | |
End Function | |
' ------------------------------------------------------------------------------------------------ | |
' Now actually add someone :) | |
Response.Write("<p>Adding someone</p>") | |
Response.Write("<p>POST Request URL is:</p>") | |
Response.Write("<pre>" & AddToListUrl("My Awesome List") & "</pre>") | |
Response.Write("<p>Mimi's response is:</p>") | |
Response.Write("<pre>" & AddToList("My Awesome List", "[email protected]") & "</pre>") | |
Response.Write("<p>Done!</p>") | |
%> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment