Use Windows.pkg Use cJsonObject.pkg Use cJsonHttpTransfer.pkg Use cApplication.pkg Use cConnection.pkg Use cCryptographer.pkg Object oApplication is a cApplication Object oConnection is a cConnection Use LoginEncryption.pkg Use DatabaseLoginDialog.dg End_Object End_Object Object oJsonHttp is a cJsonHttpTransfer Set piRemotePort to rpHttpSSL Set peTransferFlags to ifSecure Set psContentTypeExpected to "" Set pbClearHeaders to False // this can be useful when debugging Procedure OnDataReceived String sContentType String sData Forward Send OnDataReceived sContentType sData End_Procedure End_Object // courtesy of Clive Richmond Class cMD5_Hasher is a cCryptographer Function Calc_MD5_Hash String sData Returns String Boolean bRetval String sHashSum Handle ohHash ohProvider // Get AcquireContext to ohProvider Get CreateHash ohProvider to ohHash If (ohHash > 0) Begin Get HashData ohHash sData to bRetval If (bRetval) Begin Get HashValue ohHash to sHashSum Get String_To_Hex sHashSum to sHashSum Move (Lowercase(sHashSum)) to sHashSum End Get DestroyHash ohHash to bRetval End // Function_Return sHashSum End_Function Function String_To_Hex String sData Returns String Integer iPos iLen String sChar sHex // Move (Length(sData)) to iLen For iPos from 1 to iLen Get Char_To_Hex (Ascii(Mid(sData, 1, iPos))) to sChar Move (sHex+sChar) to sHex Loop // Function_Return sHex End_Function Function Char_To_Hex Integer iChar Returns String String sHex // Move (Mid("0123456789ABCDEF", 1, ((iChar / 16) + 1))) to sHex Move (sHex+(Mid("0123456789ABCDEF", 1, ((iChar iand 15) + 1)))) to sHex // Function_Return sHex End_Function End_Class // This what the user object (struct) looks like in JSON //{ // "id": "632eb48ea2771e4fdf97c3e39abcd342", // "email_address": "danwalsh46@gmail.com", // "status": "subscribed", // "merge_fields": { // "FNAME": "Dan", // "LNAME": "Walsh" // } //} // not used in this implementation, I found a simpler approach //Struct tMergeFields // String FNAME // String LNAME //End_Struct // //Struct tNewMember // String id // String email_address // String status // tMergeFields merge_fields //End_Struct Object oMailChimpTest is a cObject // this was lifted from the DAW docs Function Base64EncodeString String sText Returns String Address pBase64 String sResult Integer iVoid // Move (Base64Encode(AddressOf(sText), Length(sText))) to pBase64 Move pBase64 to sResult Move (Free(pBase64)) to iVoid // Function_Return sResult End_Function Procedure AddMember String sEmail String sFirst String sLast Boolean bOk Integer iOk String sId sJson sHost sFilePath sApiKey Handle hoMd5Hash hoMember hoFields hoResponse // Move "us14.api.mailchimp.com" to sHost Move "3.0/lists/04d*61f586/members/" to sFilePath // Get Create (RefClass(cMD5_Hasher)) to hoMd5Hash If hoMd5Hash Begin Get Calc_MD5_Hash of hoMd5Hash sEmail to sId // Send Destroy of hoMd5Hash // Get Create (RefClass(cJsonObject)) to hoMember Send InitializeJsonType of hoMember jsonTypeObject // Get Create (RefClass(cJsonObject)) to hoFields Send InitializeJsonType of hoFields jsonTypeObject // Send SetMemberValue of hoFields "FNAME" jsonTypeString sFirst Send SetMemberValue of hoFields "LNAME" jsonTypeString sLast // Send SetMemberValue of hoMember "id" jsonTypeString sId Send SetMemberValue of hoMember "email_address" jsonTypeString sEmail Send SetMemberValue of hoMember "status" jsonTypeString "subscribed" Send SetMember of hoMember "merge_fields" hoFields // Send Destroy of hoFields // // useful in the debugging phase // Set peWhiteSpace of hoMember to jpWhitespace_Pretty // Get Stringify of hoMember to sJson // Send Info_Box sJson Move (sFilePath + sId) to sFilePath // Move "anystring:5d8a11a2c*fb782efa3b7027f*c3c4a0-us14" to sApiKey Get Base64EncodeString sApiKey to sApiKey Move ("Basic" * sApiKey) to sApiKey // Send ClearHeaders of oJsonHttp Get AddHeader of oJsonHttp "Authorization" sApiKey to iOk Get HttpPutJson of oJsonHttp sHost sFilePath hoMember (&bOk) to hoResponse If bOk Begin If (hoResponse) Begin Set peWhiteSpace of hoResponse to jpWhitespace_Pretty Get Stringify of hoResponse to sJson Send Info_Box sJson Send Destroy of hoResponse End End Else Begin String sErr Get TransferErrorDescription of oJsonHttp to sErr Send Info_Box sErr End Send Destroy of hoMember End End_Procedure End_Object Send AddMember of oMailChimpTest "danwalsh46@gmail.com" "Dan" "Walsh"