Direct Results Upload API (HTTP Post Extension):
The results files can be uploaded through the web site, but for software developers it is possible to use an HTTP post directive to post the files directly rather than use FTP.
An HTTP post basically does what a user would do by going to a web page and clicking submit with the fields filled in.
The reply can be read to see what happened and parse "message = xxxxx" to find the status.
Your Software
It will be necessary to provide an option for the user to enter the Club Code instead of "myclub" and their Bridgewebs club "password" in the software Options/Configuration file somewhere.
Then provide suitable buttons [Upload to BridgeWebs] etc. somewhere on the Results page to execute the transfer
See below for VB or Perl example..
Results Upload API
To upload the results with attachments, the parameters are:
club = myclub
password = secret
type = upload
filename = xxxxxxxx.csv
event_id = N (if known, see Calendar below)
data = a string of all the lines of the xxxxxxxx.csv file
dealname = xxxxxxxx.dlm (can be dlm, bri, pbn, dup)
dealdata = a string of all the lines of the xxxxxxxx.dlm file
dealXname = xxxxxxxx.dlm (can be dlm, bri, pbn, dup) } Where X is 2-9 for extra sessions.
dealXdata = a string of all the lines of the xxxxxx.dlm file }
infoname = info.pdf (PDF supporting Info file)
infodata = a string of all the lines of the info.pdf file
// for ACBL Uploads
acblname = ACBL file name 140709.ACA (as necessary)
acbldata = a string of all the lines of the ACBL file
bwsname = BWS file name 140709.ACA (as necessary)
bwsdata = a string of all the lines of the BWS file
The data of the files can be strung together from the file and put it in one field "data" or "handdata" as appropriate. It is as if you cut and paste the file into a web text box. In this case, the filename specified is not actually accessed but is used as the file name when writing the data on the bridgewebs server for consistency with the manual technique.
The reply can be parsed to see what happened.
Parse "message = xxxxx" to find the status.
Player Download API
To download the player file, the parameters are:
club = myclub
password = secret
type = download
filename = player.txt
The reply will contain the player file in a separate line.
message = Dowload Successful
data = ..............., then split the content of that line replacing ~ (tilde) with \n.
Direct Document Upload API
To just upload a document to the club directory, the parameters are:
club = myclub
password = secret
type = upload
transfer = doc
filename = bw.csv
data = a string of all the lines of the bw.csv file
Hand Upload API
To upload a .pbn deal file and attach to an event, the parameters are:
club = myclub
password = secret
type = upload
transfer = deal
event = YYYYMMDD_X e.g. 20140709_1,
X is the unique Id of the event for that date, usually 1.
dealname = xxxxxxxx.pbn
dealdata = an encoded string of all the lines of the xxxxxxxx.pbn file
As a safety feature, will fail if the event does not exist. So the club will need to create Calendar entries in advance.
Calendar Download API
To download the club calendar, the parameters are:
club = myclub
password = secret
type = upload
year = 2014
transfer = cal
This will return a JSON argument of the calendar entries for the YEAR as a pair, id = title, file (if uploaded)
json = {"events":{"201407091":{"file":"2014Jul09!!.dat","title":"Duplicate Pairs"},.....}}
Event Download API
Similar to the Calendar, but just the events for a particular day, the parameters are:
club = myclub
password = secret
type = upload
transfer = events
date - 20140709 (yyyymmdd)
This will return a JSON argument of the calendar entries for the day as a pair, id = title, file (if uploaded)
json = {"events":{"1":{"file":"2014Jul09!!.dat","title":"Duplicate Pairs"},"2":{"title":"Create New Event"}}}
and a list of events for the day, Title~File uploaded
event_id_1 = Duplicate Pairs~10022_res_2014Aug19!!.dat~
event_id_2 = Create New Event~~
VB API Code
A suitable VB example for doing this can be found at http://www.example-code.com/vb/http_post_form.asp, or just search Google, so that the code would look something like:
Dim h As HTTPClass
Set h = New HTTPClass
Set clubcode = "myclub"
h.Fields("club") = clubcode
h.Fields("password") = "secret"
..........
If h.OpenHTTP("www.bridgewebs.com") Then
Debug.Print h.SendRequest("cgi-bin/bwx/api.cgi?club=" & clubcode, "POST")
End If
VB Net Code
A suitable VB class for doing this can be found at http://www.bridgewebs.com/guide/HTTPclass.txt, or just search Google, so that the code would look something like:
Public Function GetFromWebSite() As Boolean
' Get the player database from BridgeWebs
Cursor.Current = Cursors.WaitCursor
Dim h As HttpClass
h = New HttpClass
Dim x As Integer = 0
Dim strPost As String = ""
h.Fields("club") = "my_club"
h.Fields("type") = "download"
h.Fields("password") = "password"
h.Fields("filename") = "players.txt"
If h.OpenHTTP("www.bridgewebs.com") Then
strPost = h.SendRequest("cgi-bin/bwx/api.cgi?club=" & "my_club", "POST")
Else
' Provide the error returned from the open call
MsgBox("Error on HTTP Open " & strPost, vbInformation, "Get from Web")
Cursor.Current = Cursors.Arrow
Return False
End If
x = InStr(strPost, "Download Successful")
If x = 0 Then
' Provide the error returned from the open call
MsgBox("HTTP Post operation failed while retrieving Player Database " & vbCrLf & strPost, vbCritical, "Post error")
Cursor.Current = Cursors.Arrow
Return False
End If
' The string returned is in the format Data = "......." Message = "Download....."
' strip of the text we dont want
' Store the text in our global field
a1.PlayerDownload = Mid(strPost, 8, x - 17)
Cursor.Current = Cursors.Arrow
Return True
End Function
PHP API Code
Code for PHP will look something like, but not been tested.
$reply = "";
$clubcode = "myclub";
$data = "club=".urlencode(clubcode);
$data .= "&password=".urlencode("secret");
............
$header = "POST /mailer/send HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($data) . "\r\n\r\n";
$fp = fsockopen('http://www.bridgewebs.com/cgi-bin/bwx/api.cgi?club=' . $clubcode, 443, $errno, $errstr, 30);
if(!$fp)
return "ERROR. Could not open connection";
else {
fputs ($fp, $header.$data);
while (!feof($fp)) {
$reply .= fread ($fp, 1024);
}
fclose($fp);
}
print $reply;
Linux Perl API Code
Code for Perl will look something like, but not been tested.
my $clubcode = 'myclub";
my $url = 'http://www.bridgewebs.com/cgi-bin/bwx/api.cgi?club=' . $clubcode;
my $object = LWP::UserAgent->new;
my $request = $object->post ( $url,
{ 'club' =>$clubcode,
'password' => 'secret',
'type' => 'download',
.........
} );
my $reply = $request->as_string ();
print $reply;
'C' API Code (C# .NET 4.5)
Code for 'C' will look something like, but not been tested.
async private void cmdUpload_Click(object sender, EventArgs e)