Skip to content

Commit 1b186c4

Browse files
author
Jonathan Cone
committed
Add tcl examples
FAPI-1070
1 parent fa62bb3 commit 1b186c4

File tree

9 files changed

+194
-2
lines changed

9 files changed

+194
-2
lines changed

dotnet/rest/dotnetcore/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Program
1313
{
1414
static void Main(string[] args)
1515
{
16-
string fxmlUrl = "http://jonathan.flightaware.com/json/FlightXML3";
16+
string fxmlUrl = "http://flightxml.flightaware.com/json/FlightXML3";
1717
string username = "YOUR_USERNAME";
1818
string apiKey = "YOUR_APIKEY";
1919

dotnet/soap/console_app/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Requirements
2+
------------
3+
4+
* Visual Studio (created with VS2017)
5+
* .NET
6+
7+
What to change
8+
-------------
9+
10+
Substitute your actual username and API key in Program.cs.
11+
12+
Running the example
13+
-------------------
14+
Open the app in Visual Studio and run it.
15+
16+
To update or reimport the wsdl, right click on FlightXML3 under Connected Services and select Update Service Reference.

javascript/rest/jquery/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Notes
2+
------
3+
It is not suggested that you embed the FlightXML API call into your page's script. Not only does this expose your username and apiKey to anyone inspecting your source, but it also creates issues with making cross-origin requests. Look at the node or php examples to see how you can make the requests from your backend and then supply that data to the frontend.
4+
5+
In this example the username and apiKey are appended to the URL. That may stop working in the future as browsers block those requests.
6+
7+
Requirements
8+
------------
9+
10+
* browser
11+
12+
What to change
13+
-------------
14+
15+
Substitute your actual username and API key in index.html.
16+
17+
Running the example
18+
-------------------
19+
Open the index.html file in your browser of choice.

php/rest/guzzle/flightxml_query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
// Create the base client - add whatever defauls you need here.
2828
$client = new Client([
29-
'base_uri' => 'http://jonathan.flightaware.com/json/FlightXML3/',
29+
'base_uri' => 'http://flightxml.flightaware.com/json/FlightXML3/',
3030
'auth' => $auth_info
3131
]);
3232

python/rest/requests/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Requirements
2+
------------
3+
4+
* python
5+
* requests (pip install requests)
6+
7+
What to change
8+
-------------
9+
10+
Substitute your actual username and API key in the get_flights_enroute.py file.
11+
12+
Running the example
13+
-------------------
14+
./get_flights_enroute.py
15+
16+
OR
17+
18+
python fget_flights_enroute.py

tcl/rest/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Requirements
2+
------------
3+
4+
* tcl >= 8.5
5+
* yajltcl (https://github.com/flightaware/yajl-tcl)
6+
7+
What to change
8+
-------------
9+
10+
Substitute your actual username and API key in the flightxml_example.tcl file.
11+
12+
Running the example
13+
-------------------
14+
./flightxml_example.tcl
15+
16+
OR
17+
18+
tclsh flightxml_example.tcl

tcl/rest/flightxml_example.tcl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env tclsh
2+
3+
package require tls
4+
package require rest
5+
package require yajltcl
6+
7+
http::register https 443 ::tls::socket
8+
9+
set username "sampleUser"
10+
set apiKey "abcdefghijklmnopqrstuvwxyz"
11+
set baseUri "https://flightxml.flightaware.com/json/FlightXML3"
12+
13+
proc get_weather {airport} {
14+
global username apiKey baseUri
15+
if {[catch {set res [rest::simple "${baseUri}/WeatherConditions" [list airport_code $airport] \
16+
[list method get auth [list basic $username $apiKey]]]} err]} {
17+
puts "Error retrieving weather: $err"
18+
return
19+
}
20+
21+
puts "Weather for $airport"
22+
set jsonkv [::yajl::json2dict $res]
23+
puts [lindex [lindex [lindex $jsonkv 1] 3] 0]
24+
}
25+
26+
proc get_enroute {airport} {
27+
global username apiKey baseUri
28+
if {[catch {set res [rest::simple "${baseUri}/AirportBoards" [list airport_code $airport include_ex_data 0 type enroute howMany 10] \
29+
[list method get auth [list basic $username $apiKey]]]} err]} {
30+
puts "Error retrieving flights: $err"
31+
return
32+
}
33+
34+
puts "Aircraft enroute to $airport:"
35+
set jsonkv [::yajl::json2dict $res]
36+
array set boardData [lindex $jsonkv 1]
37+
array set enroute $boardData(enroute)
38+
foreach flight $enroute(flights) {
39+
array unset flightArr
40+
array set flightArr $flight
41+
array unset origin
42+
array set origin $flightArr(origin)
43+
foreach key {ident aircrafttype} {
44+
if {![info exists flightArr($key)]} {
45+
set flightArr($key) {}
46+
}
47+
}
48+
puts "$flightArr(ident) ($flightArr(aircrafttype))\t$origin(airport_name) ($origin(code))"
49+
}
50+
}
51+
52+
get_weather "KHOU"
53+
get_enroute "KHOU"

tcl/soap/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Requirements
2+
------------
3+
4+
* tcl >= 8.5
5+
* TCLws >= 2.4 (https://core.tcl.tk/tclws/index)
6+
7+
What to change
8+
-------------
9+
10+
Substitute your actual username and API key in the flightxml_example.tcl file.
11+
12+
Running the example
13+
-------------------
14+
./flightxml_example.tcl
15+
16+
OR
17+
18+
tclsh flightxml_example.tcl

tcl/soap/flightxml_example.tcl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env tclsh
2+
3+
package require WS::Client 2.4
4+
package require base64
5+
6+
set username "sampleUser"
7+
set apiKey "abcdefghijklmnopqrstuvwxyz"
8+
set baseUri "https://flightxml.flightaware.com/soap/FlightXML3"
9+
10+
set wsdl [::WS::Client::GetAndParseWsdl "$baseUri/wsdl"]
11+
set apiname [::WS::Client::LoadParsedWsdl $wsdl]
12+
set authheader [list Authorization "Basic [::base64::encode $username:$apiKey]"]
13+
14+
proc get_weather {airport} {
15+
global apiname authheader
16+
if {[catch {array set result [::WS::Client::DoCall $apiname WeatherConditions [list airport_code $airport] $authheader]} err]} {
17+
puts "Error retrieving the weather: $err"
18+
return
19+
}
20+
21+
puts "Weather for $airport"
22+
puts [lindex [lindex $result(WeatherConditionsResult) 3] 0]
23+
}
24+
25+
proc get_enroute {airport} {
26+
global apiname authheader
27+
if {[catch {array set result [::WS::Client::DoCall $apiname AirportBoards [list airport_code $airport include_ex_data 0 type enroute howMany 10] $authheader]} err]} {
28+
puts "Error retrieving flights: $err"
29+
return
30+
}
31+
32+
puts "Aircraft enroute to $airport:"
33+
array set boardData $result(AirportBoardsResult)
34+
array set enroute $boardData(enroute)
35+
foreach flight $enroute(flights) {
36+
array unset flightArr
37+
array set flightArr $flight
38+
array unset origin
39+
array set origin $flightArr(origin)
40+
foreach key {ident aircrafttype} {
41+
if {![info exists flightArr($key)]} {
42+
set flightArr($key) {}
43+
}
44+
}
45+
puts "$flightArr(ident) ($flightArr(aircrafttype))\t$origin(airport_name) ($origin(code))"
46+
}
47+
}
48+
49+
get_weather "KSMO"
50+
get_enroute "KSMO"

0 commit comments

Comments
 (0)