getting a deadDrop handle from VBA

Once you've followed Getting started with deadDrop, here's how to get a handle and start writing messages from VBA for ScriptDB as a dead drop. You should familiarize yourself with A VBA API for scriptDB, since we'll need to use that API.

In our example, enhancing Integrating Excel with Maps and Earth, we want to be able to retrieve data that a user has entered into a web app and update the original Excel file with the enriched data. 

The deadDrop class and handle

A deaddrop message is centered around the concept of a deadDrop class. Since you may have any number of different message conversations happening at the same time, this is how you identify and group them. Each conversation has a unique instance of that class and a key. It is this key that scriptDB uses to silo conversations from each other. You must have the key before you can access the conversation. It is also possible to provide different levels of permission to different scriptDB entries, but for now we'll just use one entry - 'messages' as set up in Getting started with deadDrop

You get a deaddrop handle with this function. This ties a key to a scriptDBEntry. The entry knows how to access scriptDb, what permissions are allowed and which physical scriptDb to use. Since all this is stored in the registry, there is no need for excel applications to know anything other than the scriptDb entry name. 

Public Function getdeaddrop(yourClass As String, _
            Optional yourScriptDbEntry As String = vbNullString, _
            Optional initial As Boolean = False, _
            Optional specificKey As String = vbNullString) As cDeadDrop
    Dim c As cDeadDrop
    Set c = New cDeadDrop
    Set getdeaddrop = c.init(yourClass, yourScriptDbEntry, initial, specificKey)
End Function

You can specify a specific key for a particular class instance, or just the class name (in which case you'll get the latest key for that class). Note however though that keys have a strict lifetime of 24 hours. All keys and data associated with that conversation will be destroyed 24 hours after the key was created , so using the latest class instance should be used with caution.

creating a new instance of a particular class
With getdeaddrop("webpagexyz", "messages", True)

.... do something

end with

get all the data for a particular class - optionally specifiying the specific key
Public Sub testConversation(yourClass As String, Optional specific As String = vbNullString)
    Dim c As cDeadDrop
    ' create a conversation conection
    With getdeaddrop("webpagexyz", "messages", , specific)
        ' now we have a scriptDb we can use to read/write stuff to this unique conversation
        With .scriptDb
            Debug.Print .scriptDbClass, .getObjectsByQuery().jObject.stringify
        End With
    End With
End Sub

Creating a message to pass to another app
Public Function addDeadDrop(subject As String, Optional yourClass As String = "googleMapping") As String
    ' Example showing how outstanding requests might be logged
    Dim job As cJobject, ds As cDataSet
    With getdeaddrop(yourClass, "messages", True)
        ' write a message for information
        With .scriptDb
            Set job = JSONParse("{'subject':'" & subject & "','info':'xliberation public data for testing'}")
        End With
        addDeadDrop = .key
    End With
End Function

That's really all there is to it. The combination of scriptDB API, silo and deadDrop key management make passing messages between co-operating apps pretty straightforward. You can use any API operation described in A VBA API for scriptDB to read and write data to the deaddrop.

You can get me on Google plus, Twitter or this forum. See ScriptDB as a dead drop for more on this
For help and more information join our forumfollow the blogfollow me on twitter