vatbook 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/CONTRIBUTING.md +8 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +143 -0
- data/Rakefile +7 -0
- data/lib/vatbook.rb +119 -0
- data/lib/vatbook/version.rb +3 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/vatbook_spec.rb +99 -0
- data/spec/xml2.xml +2104 -0
- data/vatbook.gemspec +26 -0
- metadata +161 -0
data/.gitignore
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Contributing to vatbook
|
2
|
+
|
3
|
+
1. Fork it
|
4
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
5
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
6
|
+
4. Make sure all tests are passing!
|
7
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
8
|
+
6. Create new Pull Request
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Svilen Vassilev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
# Vatbook
|
2
|
+
|
3
|
+
Ruby API to the Vatbook service for reading and parsing Vatsim pilot and ATC bookings.
|
4
|
+
Booking query requests are made by FIR and individual bookings are returned as
|
5
|
+
objects, exposing a rich set of attributes. Supports excluding enroute pilot bookings.
|
6
|
+
Supports pulling pilot and atc bookings separately or as a combined hash.
|
7
|
+
|
8
|
+
[](http://travis-ci.org/tarakanbg/vatbook)
|
9
|
+
[](https://codeclimate.com/github/tarakanbg/vatbook)
|
10
|
+
<!-- [](https://gemnasium.com/tarakanbg/vatbook) -->
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'vatbook'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install vatbook
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
This gem provides one public method: `vatbook`, which can be applied to
|
30
|
+
any string (or variable containing a string) representing a full or partial FIR
|
31
|
+
ICAO code.
|
32
|
+
|
33
|
+
For example if you want to retrieve all active stations (ATC positions and pilots)
|
34
|
+
for Bosnia-Herzegovina FIR (ICAO: LQSB), then you can use:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# Attaching the method directly to a string:
|
38
|
+
"LQSB".vatbook
|
39
|
+
|
40
|
+
# Attaching the method to a variable containing a string:
|
41
|
+
fir = "LQSB"
|
42
|
+
fir.vatbook
|
43
|
+
```
|
44
|
+
|
45
|
+
### Anatomy of method returns
|
46
|
+
|
47
|
+
The `vatbook` method returns a **hash** of 2 elements: 1) the matching *atc*
|
48
|
+
bookings, 2) all matching *pilots* bookings. Each of those is an **array**, cosnsisting of
|
49
|
+
station **objects**. Each of these objects includes a number of **attributes**:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
fir.vatbook # => {:atc => [a1, a2, a3 ...], :pilots => [p1, p2, p3, p4 ...]}
|
53
|
+
|
54
|
+
fir.vatbook[:atc] #=> [a1, a2, a3 ...]
|
55
|
+
fir.vatbook[:pilots] #=> [p1, p2, p3 ...]
|
56
|
+
|
57
|
+
fir.vatbook[:atc].first #=> a1
|
58
|
+
fir.vatbook[:pilots].first #=> p1
|
59
|
+
|
60
|
+
a1.callsign #=> "LQSA_APP"
|
61
|
+
a1.name #=> "Svilen Vassilev"
|
62
|
+
a1.cid #=> "1175035"
|
63
|
+
a1.start #=> "2012-10-08 08:00:00"
|
64
|
+
a1.end #=> "2012-10-08 10:00:00"
|
65
|
+
|
66
|
+
...
|
67
|
+
|
68
|
+
p1.callsign #=> "ACH217S"
|
69
|
+
p1.name #=> "Dragomir Andonovic"
|
70
|
+
p1.cid #=> "931960"
|
71
|
+
p1.dep #=> "LQSA"
|
72
|
+
p1.arr #=> "LDSP"
|
73
|
+
p1.route #=> "VRANA L5 KENEM"
|
74
|
+
p1.aircraft #=> "AT72"
|
75
|
+
...
|
76
|
+
```
|
77
|
+
|
78
|
+
### Station attributes
|
79
|
+
|
80
|
+
Here's a complete list of the station object attributes that can be accessed:
|
81
|
+
|
82
|
+
#### Common attributes for atc and pilots:
|
83
|
+
|
84
|
+
* `cid` (VATSIM ID)
|
85
|
+
* `callsign`
|
86
|
+
* `name`
|
87
|
+
* `role` (atc or pilot)
|
88
|
+
* `fir` (the FIR ICAO used in the request)
|
89
|
+
* `start` (planned start time)
|
90
|
+
* `end` (planned end time)
|
91
|
+
|
92
|
+
#### Pilot specific attributes
|
93
|
+
|
94
|
+
* `dep` (planned departure airport)
|
95
|
+
* `arr` (planned destination airport)
|
96
|
+
* `route` (planned route)
|
97
|
+
* `aircraft` (planned aircraft type)
|
98
|
+
* `enroute` (boolean, whether or not the flight is enroute for the FIR)
|
99
|
+
|
100
|
+
### Customizing the request
|
101
|
+
|
102
|
+
The `vatbook` method can be customized by passing in a hash-style collection
|
103
|
+
of arguments. The currently supported arguments and their defaults are:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
:enroute => true # Possible values: true, false. Default: true
|
107
|
+
```
|
108
|
+
The `:enroute => false` option can be used to exclude all booked flights that
|
109
|
+
are enroute for the selected FIR, i.e. don't originate or end on one of the FIR's
|
110
|
+
airports. Example:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
# Lets exclude all enroute pilot bookings for LQSB FIR and only display bookings
|
114
|
+
# that are outbound/inbound one of Bosnia-Herzegovina airports:
|
115
|
+
|
116
|
+
"LQSB".vatbook(:enroute => false) #=> [pilot1, pilot2, pilot3...]
|
117
|
+
```
|
118
|
+
|
119
|
+
## Changelog
|
120
|
+
|
121
|
+
### v. 0.1 - 22 October 2012
|
122
|
+
|
123
|
+
* Initial release
|
124
|
+
|
125
|
+
## Contributing
|
126
|
+
|
127
|
+
1. Fork it
|
128
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
129
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
130
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
131
|
+
5. Make sure all tests pass
|
132
|
+
6. Create new Pull Request
|
133
|
+
|
134
|
+
## Credits
|
135
|
+
|
136
|
+
Copyright © 2012 [Svilen Vassilev](http://about.me/svilen)
|
137
|
+
|
138
|
+
*If you find my work useful or time-saving, you can endorse it or buy me a beer:*
|
139
|
+
|
140
|
+
[](http://coderwall.com/svilenv)
|
141
|
+
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5FR7AQA4PLD8A)
|
142
|
+
|
143
|
+
Released under the [MIT LICENSE](https://github.com/tarakanbg/vatbook/blob/master/LICENSE.txt)
|
data/Rakefile
ADDED
data/lib/vatbook.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require "vatbook/version"
|
2
|
+
|
3
|
+
class String
|
4
|
+
def vatbook(args={})
|
5
|
+
Vatbook.bookings(self, args)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Vatbook
|
10
|
+
def self.bookings(fir, args)
|
11
|
+
BookFetcher.new(fir, args).fetch
|
12
|
+
end
|
13
|
+
|
14
|
+
class BookFetcher
|
15
|
+
require 'nokogiri'
|
16
|
+
require 'open-uri'
|
17
|
+
|
18
|
+
attr_accessor :fir, :atc_bookings, :pilot_bookings, :enroute, :doc
|
19
|
+
|
20
|
+
def initialize(fir, args = nil)
|
21
|
+
@fir = fir.upcase
|
22
|
+
@enroute = true
|
23
|
+
process_arguments(args) if args.class == Hash
|
24
|
+
@atc_bookings = []; @pilot_bookings = [];
|
25
|
+
@doc = raw_list
|
26
|
+
atcs
|
27
|
+
pilots
|
28
|
+
end
|
29
|
+
|
30
|
+
def raw_list
|
31
|
+
Nokogiri::XML(open("http://vatbook.euroutepro.com/xml2.php?fir=#{@fir}"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch
|
35
|
+
{:atc => atc_bookings, :pilots => pilot_bookings}
|
36
|
+
end
|
37
|
+
|
38
|
+
def atc_bookings
|
39
|
+
@atc_bookings
|
40
|
+
end
|
41
|
+
|
42
|
+
def pilot_bookings
|
43
|
+
@pilot_bookings
|
44
|
+
end
|
45
|
+
|
46
|
+
def atcs_count
|
47
|
+
@doc.css("atcs booking").count
|
48
|
+
end
|
49
|
+
|
50
|
+
def pilots_count
|
51
|
+
@doc.css("pilots booking").count
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def atcs
|
57
|
+
@doc.css("atcs booking").each do |booking|
|
58
|
+
@atc_bookings << Booking.new(booking, role = "atc", @fir)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def pilots
|
63
|
+
@doc.css("pilots booking").each do |booking|
|
64
|
+
if @enroute == false
|
65
|
+
bk = Booking.new(booking, role = "pilot", @fir)
|
66
|
+
if bk.enroute == false
|
67
|
+
@pilot_bookings << bk
|
68
|
+
end
|
69
|
+
else
|
70
|
+
@pilot_bookings << Booking.new(booking, role = "pilot", @fir)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def process_arguments(args)
|
76
|
+
args[:enroute] == false ? @enroute = false : @enroute = true
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
class Booking
|
82
|
+
require 'nokogiri'
|
83
|
+
|
84
|
+
attr_accessor :role, :callsign, :name, :cid, :start, :end, :dep, :arr
|
85
|
+
attr_accessor :aircraft, :route, :enroute, :fir
|
86
|
+
|
87
|
+
|
88
|
+
def initialize(booking, role, fir)
|
89
|
+
@fir = fir
|
90
|
+
@role = role
|
91
|
+
@callsign = booking.children.css("callsign").first.children.to_s
|
92
|
+
@name = booking.children.css("name").first.children.to_s
|
93
|
+
@role == "atc" ? @cid = booking.children.css("cid").first.children.to_s : @cid = booking.children.css("pid").first.children.to_s
|
94
|
+
if @role == "atc"
|
95
|
+
@start = booking.children.css("time_start").first.children.to_s
|
96
|
+
@end = booking.children.css("time_end").first.children.to_s
|
97
|
+
elsif @role == "pilot"
|
98
|
+
@dep = booking.children.css("dep").first.children.to_s
|
99
|
+
@arr = booking.children.css("arr").first.children.to_s
|
100
|
+
@route = booking.children.css("route").first.children.to_s.gsub(/[\n]/, ' ').strip
|
101
|
+
@start = booking.children.css("from").first.children.to_s
|
102
|
+
@end = booking.children.css("to").first.children.to_s
|
103
|
+
@aircraft = booking.children.css("actype").first.children.to_s
|
104
|
+
check_enroute
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
def check_enroute
|
110
|
+
if @fir[0..1] == @dep[0..1] or @fir[0..1] == @arr[0..1]
|
111
|
+
@enroute = false
|
112
|
+
else
|
113
|
+
@enroute = true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
describe "fir" do
|
6
|
+
it "should work :)" do
|
7
|
+
"LQSB".vatbook.count.should eq(2)
|
8
|
+
"LQSB".vatbook[:atc].count.should eq(207)
|
9
|
+
"LQSB".vatbook[:pilots].count.should eq(2)
|
10
|
+
"lqsb".vatbook[:atc].count.should eq(207)
|
11
|
+
"lqsb".vatbook[:pilots].count.should eq(2)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should contain attributes" do
|
15
|
+
"LQSB".vatbook[:atc].first.role.should eq("atc")
|
16
|
+
"LQSB".vatbook[:atc].first.callsign.should eq("LFMN_TWR")
|
17
|
+
"LQSB".vatbook[:atc].first.name.should eq("Tomba Quentin")
|
18
|
+
"LQSB".vatbook[:atc].first.cid.should eq("1227003")
|
19
|
+
"LQSB".vatbook[:atc].first.start.should eq("2012-10-08 08:00:00")
|
20
|
+
"LQSB".vatbook[:atc].first.end.should eq("2012-10-08 10:00:00")
|
21
|
+
"LQSB".vatbook[:pilots].first.role.should eq("pilot")
|
22
|
+
"LQSB".vatbook[:pilots].first.callsign.should eq("KLM112")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Vatbook do
|
29
|
+
|
30
|
+
describe "vatsim_online" do
|
31
|
+
it "should work :)" do
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
describe Vatbook::BookFetcher do
|
39
|
+
describe "atcs count" do
|
40
|
+
it "should return correct count" do
|
41
|
+
icao = "LQSB"
|
42
|
+
Vatbook::BookFetcher.new(icao).atcs_count.should eq(207)
|
43
|
+
Vatbook::BookFetcher.new(icao).pilots_count.should eq(2)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "pilot bookings" do
|
48
|
+
it "should parse pilot attributes" do
|
49
|
+
icao = "LQSB"
|
50
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.role.should eq("pilot")
|
51
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.callsign.should eq("KLM112")
|
52
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.name.should eq("Edwin Middelaar EHAM")
|
53
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.cid.should eq("931960")
|
54
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.route.should eq("OTREX UM872 PLH UB1 DDM UM619 YNN UL604 BIGGE T281 NORKU")
|
55
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.dep.should eq("LGIR")
|
56
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.arr.should eq("EHAM")
|
57
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.aircraft.should eq("B738")
|
58
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.fir.should eq("LQSB")
|
59
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.first.enroute.should eq(true)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should identify enroutes" do
|
63
|
+
icao = "LQSB"
|
64
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.role.should eq("pilot")
|
65
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.callsign.should eq("KLM113")
|
66
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.name.should eq("Edwin Middelaar EHAM")
|
67
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.cid.should eq("931960")
|
68
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.route.should eq("OTREX UM872 PLH UB1 DDM UM619 YNN UL604 BIGGE T281 NORKU")
|
69
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.dep.should eq("LGIR")
|
70
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.arr.should eq("LQSA")
|
71
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.aircraft.should eq("B738")
|
72
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.fir.should eq("LQSB")
|
73
|
+
Vatbook::BookFetcher.new(icao).pilot_bookings.last.enroute.should eq(false)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should handle enroute hash options" do
|
77
|
+
icao = "LQSB"
|
78
|
+
args = {:enroute => true}
|
79
|
+
Vatbook::BookFetcher.new(icao, args).pilot_bookings.count.should eq(2)
|
80
|
+
Vatbook::BookFetcher.new(icao, args).pilot_bookings.first.arr.should eq("EHAM")
|
81
|
+
args = {:enroute => false}
|
82
|
+
Vatbook::BookFetcher.new(icao, args).pilot_bookings.count.should eq(1)
|
83
|
+
Vatbook::BookFetcher.new(icao, args).pilot_bookings.first.arr.should eq("LQSA")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "atc bookings" do
|
88
|
+
it "should parse atc attributes" do
|
89
|
+
icao = "LQSB"
|
90
|
+
Vatbook::BookFetcher.new(icao).atc_bookings.first.role.should eq("atc")
|
91
|
+
Vatbook::BookFetcher.new(icao).atc_bookings.first.fir.should eq("LQSB")
|
92
|
+
Vatbook::BookFetcher.new(icao).atc_bookings.first.callsign.should eq("LFMN_TWR")
|
93
|
+
Vatbook::BookFetcher.new(icao).atc_bookings.first.name.should eq("Tomba Quentin")
|
94
|
+
Vatbook::BookFetcher.new(icao).atc_bookings.first.cid.should eq("1227003")
|
95
|
+
Vatbook::BookFetcher.new(icao).atc_bookings.first.start.should eq("2012-10-08 08:00:00")
|
96
|
+
Vatbook::BookFetcher.new(icao).atc_bookings.first.end.should eq("2012-10-08 10:00:00")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|