360Works WebAssistant/Documentation

From 360Works Product Documentation Wiki
(Difference between revisions)
Jump to: navigation, search
m (Auto-upload documentation)
m (Auto-upload documentation)
Line 61: Line 61:
 
=Function Summary=
 
=Function Summary=
 
<div id="toc">
 
<div id="toc">
*[[#WAConfigure|WAConfigure]] ( optionName ; value ) &mdash; Set a WebAssistant-related configuration optionName.
+
*[[#WAGetResponseCode|WAGetResponseCode]] &mdash;  
 
*[[#WAGetResponseHeader|WAGetResponseHeader]] ( headerName ) &mdash; After executing a request with the {@link #WAGetURL} method, you can use this function to examine the HTTP headers in the response.
 
*[[#WAGetResponseHeader|WAGetResponseHeader]] ( headerName ) &mdash; After executing a request with the {@link #WAGetURL} method, you can use this function to examine the HTTP headers in the response.
 
*[[#WAGetResponseHeaders|WAGetResponseHeaders]] &mdash; This gets a return-separated list of all HTTP header names from the last response.
 
*[[#WAGetResponseHeaders|WAGetResponseHeaders]] &mdash; This gets a return-separated list of all HTTP header names from the last response.
*[[#WAGetURL|WAGetURL]] ( url { ; key1=value1 ; key2=value2 ; ... ) &mdash; Get the contents of a URL, as either TEXT or a CONTAINER object.
+
*[[#WAGetURL|WAGetURL]] ( url { ; key1=value1 ; key2=value2 ; ... } ) &mdash; Get the contents of a URL, as either TEXT or a CONTAINER object.
 
*[[#WALastError|WALastError]] &mdash; Returns defailed information about the last error generated by this plugin.
 
*[[#WALastError|WALastError]] &mdash; Returns defailed information about the last error generated by this plugin.
 
*[[#WALicenseInfo|WALicenseInfo]] &mdash; Retrieve information about the WebAssistant plugin licensing and version.
 
*[[#WALicenseInfo|WALicenseInfo]] &mdash; Retrieve information about the WebAssistant plugin licensing and version.
*[[#WALoadForm|WALoadForm]] ( html { ; whichForm } ) &mdash; Use an HTML form as a starting point for form values.
 
*[[#WARegister|WARegister]] ( licenseKey ; registeredTo ) &mdash; Registers the Plugin.
 
*[[#WAReset|WAReset]] &mdash; Clears all request parameters, file uploads, and post data.
 
 
*[[#WAReturnSavedPageURL|WAReturnSavedPageURL]] &mdash; returns the name file URL thats stored
 
*[[#WAReturnSavedPageURL|WAReturnSavedPageURL]] &mdash; returns the name file URL thats stored
*[[#WASetCharacterSet|WASetCharacterSet]] ( charset ) &mdash; Set the character encoding used for sending form values and for decoding fetched URL contents into text.
 
 
*[[#WASetErrorCapture|WASetErrorCapture]] ( errorCapture ) &mdash; Toggles error dialogs on or off.
 
*[[#WASetErrorCapture|WASetErrorCapture]] ( errorCapture ) &mdash; Toggles error dialogs on or off.
*[[#WASetInputValue|WASetInputValue]] ( inputName ; value ) &mdash; Sets a parameter to pass in the POST argument during the next call to {@link #WAGetURL}.
 
*[[#WASetRawPostData|WASetRawPostData]] ( dataToPost ) &mdash; Set raw POST data to send during the next call to {@link #WAGetURL}.
 
*[[#WASetRequestHeader|WASetRequestHeader]] ( headerName ; value ) &mdash; Set manual HTTP headers to be sent with the request.
 
 
*[[#WAStripTags|WAStripTags]] ( html ) &mdash; Strip any HTML tags from a block of text.
 
*[[#WAStripTags|WAStripTags]] ( html ) &mdash; Strip any HTML tags from a block of text.
*[[#WAUploadFileAtURL|WAUploadFileAtURL]] ( inputName ; url ) &mdash; Upload a file during the next call to {@link #WAGetURL}.
 
 
*[[#WAVersion|WAVersion]] &mdash; Returns the version number of the WebAssistant plugin.
 
*[[#WAVersion|WAVersion]] &mdash; Returns the version number of the WebAssistant plugin.
 
</div>
 
</div>
 
=Function Detail=
 
=Function Detail=
<div id="WAConfigure"></div>
+
<div id="WAGetResponseCode"></div>
==WAConfigure ( optionName ; value ) ==
+
==WAGetResponseCode==
Set a WebAssistant-related configuration optionName.
+
Valid options are:
+
<dl>
+
<dt>easySSL
+
<dd>A 1 or 0 indicating whether or not to use lax SSL certificate checking.  This is useful for testing using self-signed certificates, or if you are getting certificate-related errors while connecting to <code>https</code> urls.
+
  
<dt>connectionTimeout
 
<dd>The timeout in milliseconds until a connection is etablished. A value of zero means the timeout is not used. The default value is zero.
 
  
<dt>socketTimeout
 
<dd>The default socket timeout (<code>SO_TIMEOUT</code>) in milliseconds which is the timeout for waiting for data. A timeout value of zero (the default value) is interpreted as an infinite timeout.
 
  
<dt>userAgent
 
<dd>Defines the content of the User-Agent header used by HTTP methods.
 
 
<dt>proxyHost
 
<dd>The proxy server host address or hostname.
 
 
<dt>proxyPort
 
<dd>The proxy server port number, defaults to 8080.
 
 
<dt>proxyUsername
 
<dd>The proxy server username.
 
<dt>proxyPassword
 
<dd>The proxy server password.
 
 
</dl>
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>optionName</code> <dd>the optionName to set.
 
<dt><code>value</code> <dd>the value of the optionName.
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 if an optionName is successfully set, or ERROR if an error occurs.
 
</div>
 
  
 
<div id="WAGetResponseHeader"></div>
 
<div id="WAGetResponseHeader"></div>
Line 137: Line 98:
  
 
<div id="WAGetURL"></div>
 
<div id="WAGetURL"></div>
==WAGetURL ( url { ; key1=value1 ; key2=value2 ; ... ) ==
+
==WAGetURL ( url { ; key1=value1 ; key2=value2 ; ... } ) ==
 
Get the contents of a URL, as either TEXT or a CONTAINER object.  If there are any input values or file uploads set, they are sent as part of a <code>POST</code> request.
 
Get the contents of a URL, as either TEXT or a CONTAINER object.  If there are any input values or file uploads set, they are sent as part of a <code>POST</code> request.
 
Otherwise, a <code>GET</code> request is used to get the contents of the URL.
 
Otherwise, a <code>GET</code> request is used to get the contents of the URL.
Line 186: Line 147:
  
  
 
<div id="WALoadForm"></div>
 
==WALoadForm ( html { ; whichForm } ) ==
 
Use an HTML form as a starting point for form values.  This can be useful if you're simulating a form submission from a page which has many hidden or pre-populated fields.
 
This can often happen on multi-step form submissions.
 
 
Calling this function will scan the <code>HTML</code> parameter text for the form identified by the <code>whichForm</code> parameter.
 
For every input element in the specified <code>form</code>, [[#WASetInputValue|WASetInputValue]] will be called with the corresponding inputName and value.
 
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>html</code> <dd>block of HTML code containing one or more <code>&lt;form&gt;</code>s
 
<dt><code>whichForm</code> <dd>the optional id, name, or index of the form to use.  If omitted, the first <code>&lt;form&gt;</code> will be used.
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 on success, <code>ERROR</code> on failure.
 
</div>
 
 
<div id="WARegister"></div>
 
==WARegister ( licenseKey ; registeredTo ) ==
 
Registers the Plugin.
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>licenseKey</code> <dd>a valid license key string, or the literal string "DEMO" to run in demo mode.
 
<dt><code>registeredTo</code> <dd>the company name for the license key used.
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 on success, or &quot;ERROR&quot; on failure.
 
</div>
 
 
<div id="WAReset"></div>
 
==WAReset==
 
Clears all request parameters, file uploads, and post data.
 
This should be called before constructing a new request or getting a URL, in case there are some parameters lingering from a previous call that did not complete.
 
 
<div class="see"><strong>Returns:</strong> 1
 
</div>
 
  
 
<div id="WAReturnSavedPageURL"></div>
 
<div id="WAReturnSavedPageURL"></div>
Line 227: Line 153:
  
 
<div class="see"><strong>Returns:</strong> Filename
 
<div class="see"><strong>Returns:</strong> Filename
</div>
 
 
<div id="WASetCharacterSet"></div>
 
==WASetCharacterSet ( charset ) ==
 
Set the character encoding used for sending form values and for decoding fetched URL contents into text.
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>charset</code> <dd>a character set name, for example <code>US-ASCII</code>, <code>ISO-8859-1</code>, <code>UTF-8</code>, <code>UTF-16</code>.
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 on success, or &quot;ERROR&quot; on failure (if an unsupported character set is passed)
 
 
</div>
 
</div>
  
Line 247: Line 163:
 
</dl></div>
 
</dl></div>
  
 
<div id="WASetInputValue"></div>
 
==WASetInputValue ( inputName ; value ) ==
 
Sets a parameter to pass in the POST argument during the next call to [[#WAGetURL|WAGetURL]].  If you want to simulate submitting an email signup form, you might call this with the values:
 
 
WASetInputValue( &quot;email&quot; ; Contacts::emailAddress )
 
 
 
To send a container field as an attachment, pass the container field as the <code>value</code>.
 
 
WASetInputValue( &quot;photo&quot; ; Contacts::portrait )
 
 
 
If you want to upload the contents of a local file or URL instead of a container, use the [[#WAUploadFileAtURL|WAUploadFileAtURL]] function instead.
 
 
You can call this function multiple times before sending a form.
 
If called twice with the same inputName, this will _not_ overwrite the previous value, but will send both values.
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>inputName</code> <dd>the unencoded name of the form input
 
<dt><code>value</code> <dd>the unencoded value text, or a container to send as an upload.
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 on success, or &quot;ERROR&quot; on failure.
 
</div>
 
 
<div id="WASetRawPostData"></div>
 
==WASetRawPostData ( dataToPost ) ==
 
Set raw POST data to send during the next call to [[#WAGetURL|WAGetURL]].  If used in conjunction with [[#WASetInputValue|WASetInputValue]],
 
any parameters set in that method will be passed as <code>GET</code> arguments instead of <code>POST</code> arguments.
 
 
You cannot combine this with calls to [[#WAUploadFileAtURL|WAUploadFileAtURL]] in the same request.
 
You can call this function multiple times before sending a form.
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>dataToPost</code> <dd>raw encoded POST data to send in the next request.
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 on success, or &quot;ERROR&quot; on failure.
 
</div>
 
 
<div id="WASetRequestHeader"></div>
 
==WASetRequestHeader ( headerName ; value ) ==
 
Set manual HTTP headers to be sent with the request.  The most common case you would use this would be to set cookies in the request.
 
<h4>Setting Cookies</h4>
 
To send cookies along with your request, call with with &quot;cookie&quot; as the <code>headerName</code>, and the cookie data as the <code>value</code>.
 
 
WASetRequestHeader("Cookie", "sessionID=123456789;style=basic")
 
 
<h4>Other Uses</h4>
 
You can also use this to set the Content-Type of your request, or to pass in any other arbitrary headers you wish.
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>headerName</code> <dd>the name of the HTTP header to set
 
<dt><code>value</code> <dd>the value of the HTTP header
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 on success
 
</div>
 
  
 
<div id="WAStripTags"></div>
 
<div id="WAStripTags"></div>
Line 312: Line 172:
 
</dl></div>
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> the input HTML with all tags removed.
 
<div class="see"><strong>Returns:</strong> the input HTML with all tags removed.
</div>
 
 
<div id="WAUploadFileAtURL"></div>
 
==WAUploadFileAtURL ( inputName ; url ) ==
 
Upload a file during the next call to [[#WAGetURL|WAGetURL]].
 
If one or more files are specified to upload, the data is sent as <code>multipart/form-data</code>.
 
 
If you want to upload the contents of a container field instead of a URL, use the [[#WASetInputValue|WASetInputValue]] function instead, passing the container as the <code>value</code> parameter.
 
 
<div class="parameters"><strong>Parameters:</strong>
 
<dl><dt><code>inputName</code> <dd>the input name to associate with this file.
 
<dt><code>url</code> <dd>URL pointing to a file to upload.  This can be a local file (<code>file:///path/to/file</code>) as well as a remote URL  (<code>http://example.com/logo.jpg</code>).
 
</dl></div>
 
<div class="see"><strong>Returns:</strong> 1 on success, or &quot;ERROR&quot; on failure.
 
 
</div>
 
</div>
  

Revision as of 21:05, 9 May 2017

Contents

360Works WebAssistant User Guide

WebAssistant allows you to submit forms from FileMaker, and to get the contents of any URL as text or a container.

Getting URL Contents

In its simplest form, you can use the WAGetURL function to get the contents of a URL. If the mime-type of the URL is text, the raw text of the webpage or file is returned. Otherwise, a container is returned containing the image or other data located at the URL.

Submitting Forms

The WebAssistant can simulate a browser submitting a web form. For each "field" you wish to send to a form, call the WASetInputValue function. Note that the paramName corresponds to the name of an input in the HTML form, which may differ from the label for the field as it appears on-screen. The paramName should match the name attribute on the <input type="text" name="my_input"> input element in the HTML source code.

In addition to field inputs, you can specify files to upload to a form using the WAUploadFileAtURL function. Again, the inputName should match the name attribute on the <input type="file" name="my_upload"> in the HTML source code.

You can specify multiple parameters or file uploads. They will all be sent the next time the WAGetURL function is called.

For more advanced users, there is the option of setting the content of the request manually, using the WASetRawPostData function. This will be sent as-is in the request, which is useful if (for example) the POST data should contain an XML document instead of key/value pairs. You are responsible for encoding this information correctly, as it will be sent as-is to the URL.

Example Usage

To add a user to a web-based signup form, you might use something like the following:

Let ( setup = WAReset &
    WASetInputValue( "first_name" ; "Sam" ) &
    WASetInputValue( "last_name" ; "Barnum" ) &
    WASetInputValue( "email" ; "sam@example.com" )
;
    WAGetURL( "http://example.com/test/signup.php" )
)


To get an image from a password-protected website, just use the following calculation:

Let ( setup = WAReset ;
    WAGetURL( "logo.jpg" ; "username=bob123", "password=secretpass" ; "type=container" )
)


To upload files to a web form, pass container data to the WASetInputValue function, or a URL to the WAUploadFileAtURL function:

Let ( setup = WAReset ;
    WASetInputValue( "upload1" ; Products::picture_container ) &
    WAUploadFileAtURL( "upload2" ; "file:///Users/sam/Pictures/header.jpg" )
;
    WAGetURL( "http://example.com/upload.php" )
)

Proxy Support

If you are behind a proxy server, you will need to tell the WebAssistant plugin information about the proxy host, as follows:

WAConfigure("proxyHost", settings::proxyHost) and
WAConfigure("proxyPort", settings::proxyPort)

Do this in your startup script, and any further connections will go through your proxy host.


360Works Plugin Setup Guides

See Plugins_101 for Error reporting, installation, registration, and more.

Function Summary

  • WAGetResponseCode
  • WAGetResponseHeader ( headerName ) — After executing a request with the {@link #WAGetURL} method, you can use this function to examine the HTTP headers in the response.
  • WAGetResponseHeaders — This gets a return-separated list of all HTTP header names from the last response.
  • WAGetURL ( url { ; key1=value1 ; key2=value2 ; ... } ) — Get the contents of a URL, as either TEXT or a CONTAINER object.
  • WALastError — Returns defailed information about the last error generated by this plugin.
  • WALicenseInfo — Retrieve information about the WebAssistant plugin licensing and version.
  • WAReturnSavedPageURL — returns the name file URL thats stored
  • WASetErrorCapture ( errorCapture ) — Toggles error dialogs on or off.
  • WAStripTags ( html ) — Strip any HTML tags from a block of text.
  • WAVersion — Returns the version number of the WebAssistant plugin.

Function Detail

WAGetResponseCode

WAGetResponseHeader ( headerName )

After executing a request with the WAGetURL method, you can use this function to examine the HTTP headers in the response. This can be useful for seeing cookie data which the server is setting. You can use the WAGetResponseHeaders function to get a list of all headers.

Parameters:

headerName
the name of the HTTP header to fetch

Returns: the value of the first HTTP header named name, or null if no such header was found.

WAGetResponseHeaders

This gets a return-separated list of all HTTP header names from the last response.

Returns: all headers from the last request

WAGetURL ( url { ; key1=value1 ; key2=value2 ; ... } )

Get the contents of a URL, as either TEXT or a CONTAINER object. If there are any input values or file uploads set, they are sent as part of a POST request. Otherwise, a GET request is used to get the contents of the URL.

You can also use this to get the contents of files on your local machine, using the following syntax: file:///path/to/file.txt.

If the content type of the returned data is text, this function returns the text. Otherwise, a container is returned. Alternatley, you can specify a type to return the URL content as, using the type parameter (see Optional Parameters below).

Authentication

You can optionally supply a username and password, for accessing password-protected content. This must be passed in with each request, as the values are cleared out after doing the request.

Optional Parameters

The following optional parameters are supported:

username
The username to be used for authentication
password
The password to be used for authentication
type
"text" to fetch the result as a text object, "container" to fetch the result as a container. If no type is specified, the content-type of the URL contents are examined to automatically determine the best type (images, etc. will be returned as containers, text & html will be returned as text)
encoding The default is application/x-www-form-urlencoded. You can also specify multipart/form-data to force that encoding instead.

Example Usage

To fetch data from a password-protected XML web service as text, you could use the following calcuation:

Set Variable [ $xml = WAGetURL(
    "http://myservice.com" ;
    "username=bob" ;
    "password=secret" ;
    "type=text" ) ]


Parameters:

url
the location of the file to get.
optionalParameters
optional parameters

Returns: The contents of the URL, as text or a container.

WALastError

Returns defailed information about the last error generated by this plugin. If another plugin function returns the text "ERROR", call this function to get a user-presentable description of what went wrong.

Returns: Error text, or null if there was no error.

WALicenseInfo

Retrieve information about the WebAssistant plugin licensing and version.


WAReturnSavedPageURL

returns the name file URL thats stored

Returns: Filename

WASetErrorCapture ( errorCapture )

Toggles error dialogs on or off. When something unexpected happens, the plug-in will pop up a dialog displaying the error message. This makes it easy to see what went wrong. However, in some cases, you (the developer) may prefer to show your own message to the user, or possibly not show a message at all. In that case, you can call WASetErrorCapture with a parameter of true. That will suppress the error dialog from appearing to the user.

Parameters:

errorCapture
set to true to suppress the default popups.


WAStripTags ( html )

Strip any HTML tags from a block of text.

Parameters:

html
some HTML.

Returns: the input HTML with all tags removed.

WAVersion

Returns the version number of the WebAssistant plugin.

Returns: a text version number
Personal tools
Namespaces

Variants
Actions
Plug-in Products
Other Products
Navigation
Toolbox