Xojo Paw Extensions

If any of you are interested, I threw together two code generation extensions for Paw for old and new framework http/https requests. They’re available here:

Old Framework
New Framework

To install, go to the Paw menu, select Extensions->Open Extensions Directory and extract the zip files into that directory. You may need to restart Paw, but from then on whenever you create a request, you’ll have a code sample available.

Yes! Thank you very much, Greg! :slight_smile:

Greg, that is freaking cool.

Didn’t know about Paw!
Thanks @Greg O’Lone :slight_smile:

Just FYI – I’ve uploaded new versions which create different code for each of the body types. For instance, if the body type is set to JSON, you get code for a JSONItem on the old framework and for a Xojo.Core.Dictionary converted to Text and then to a Xojo.Core.MemoryBlock on the new framework.

Old Framework

[code]// My API

// Set up the socket
dim h as new HTTPSocket
h.setRequestHeader(“myHeader”,“Header Value”)
h.setRequestHeader(“Content-Type”,“application/json”)

// JSON
Dim js As New JSONItem
js.Value(“age”) = 105
js.Value(“registered”) = true
js.Value(“favorite”) = nil
js.Value(“name”) = “Mickey Mouse”

// Convert Dictionary to JSON Text
Dim data As String = js.toString()

// Assign to the Request’s Content
h.SetRequestContent(data,“application/json”)

// Set the URL
dim url as string = “http://echo.luckymarmot.com

// Send Synchronous Request
dim s as string = h.SendRequest(“GET”,url,30)[/code]

New Framework

[code]// My API

// Set up the socket
// “mySocket” should be a property stored elsewhere so it will not go out of scope
mySocket = new Xojo.Net.HTTPSocket
mySocket.RequestHeader(“myHeader”) = “Header Value”
mySocket.RequestHeader(“Content-Type”) = “application/json”

// JSON
Dim d As New Dictionary
d.Value(“age”) = 105
d.Value(“registered”) = true
d.Value(“favorite”) = nil
d.Value(“name”) = “Mickey Mouse”

// Convert Dictionary to JSON Text
Dim json As Text = Xojo.Data.GenerateJSON(d)

// Convert Text to Memoryblock
Dim data As Xojo.Core.MemoryBlock = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(json)

// Assign to the Request’s Content
mySocket.SetRequestContent(data,“application/json”)

// Set the URL
dim url as Text = “http://echo.luckymarmot.com

// Send Asynchronous Request
mySocket.Send(“GET”,url)[/code]

@Greg O’Lone

Thankyou for this. you have made my life so much easier. i think you have saved me at least a days time this morning alone!!

[quote=231070:@Russ Lunn]@Greg O’Lone

Thankyou for this. you have made my life so much easier. i think you have saved me at least a days time this morning alone!![/quote]
I’ll take small bags of 10’s and 20’s. :stuck_out_tongue:

@Greg O’Lone

I just tried to install the plugin and it’s not showing. I went to manage extensions and it;s not there.

I moved the js file into the extensions directory. I used the New Framework.

Any ideas?

@Greg O’Lone

I hit the show console and it says:

Event Ignoring file xojoHTTPCodeGenerator.js in extensions directory
Event Ignoring file xojoNewHTTPCodeGenerator.js in extensions directory

That happens when I hit reload extensions.

Paw>preferences>open directory and click on the file

Paw>preferences>Extensions>Open Extensions Directory

It shows the files there.

Paw>extensions>manage extensions.
Without click anywhere click the button “open extensions directory”.
Unzip the file and drop the folder to extensions directory.

I did that. I opened the zip, and copied the files into that directory:

/Volumes/Macintosh HD/Users/Rich/Library/Containers/com.luckymarmot.Paw/Data/Library/Application Support/com.luckymarmot.Paw/Extensions/xojoNewHTTPCodeGenerator.js

Restarted it too.

Read my post again :wink:
“open extensions directory”,and copy the >Folder.

Got it! Thanks for be patient with an old man! :slight_smile:

I am old man don’t worry :slight_smile:

63?

No 45 :wink:

That’s not old! :slight_smile:

1 Like