flightcaster 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.
Files changed (41) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +24 -0
  5. data/Rakefile +54 -0
  6. data/VERSION +1 -0
  7. data/lib/flightcaster.rb +28 -0
  8. data/lib/flightcaster/base.rb +120 -0
  9. data/lib/flightcaster/request.rb +55 -0
  10. data/test/fixtures/airline.xml +9 -0
  11. data/test/fixtures/airline_flight.xml +421 -0
  12. data/test/fixtures/airline_flights.xml +2421 -0
  13. data/test/fixtures/airlines.xml +246 -0
  14. data/test/fixtures/airlines_page.xml +260 -0
  15. data/test/fixtures/airlines_per_page.xml +421 -0
  16. data/test/fixtures/airport.xml +30 -0
  17. data/test/fixtures/airports.xml +440 -0
  18. data/test/fixtures/arrivals.xml +1221 -0
  19. data/test/fixtures/departures.xml +1301 -0
  20. data/test/fixtures/flight.xml +99 -0
  21. data/test/fixtures/flight_date.xml +101 -0
  22. data/test/fixtures/flight_path.xml +43 -0
  23. data/test/fixtures/flight_path_date.xml +1786 -0
  24. data/test/fixtures/flights.xml +2420 -0
  25. data/test/fixtures/general_delay.xml +11 -0
  26. data/test/fixtures/general_delays.xml +22 -0
  27. data/test/fixtures/ground_delay.xml +9 -0
  28. data/test/fixtures/ground_delays.xml +25 -0
  29. data/test/fixtures/ground_stop.xml +8 -0
  30. data/test/fixtures/ground_stops.xml +16 -0
  31. data/test/fixtures/metar.xml +21 -0
  32. data/test/fixtures/metars.xml +201 -0
  33. data/test/fixtures/notfound.xml +56 -0
  34. data/test/fixtures/oldapi.xml +13 -0
  35. data/test/fixtures/taf.xml +25 -0
  36. data/test/fixtures/tafs.xml +288 -0
  37. data/test/helper.rb +31 -0
  38. data/test/test_base.rb +0 -0
  39. data/test/test_flightcaster.rb +219 -0
  40. data/test/test_request.rb +10 -0
  41. metadata +118 -0
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'matchy'
5
+ require 'fakeweb'
6
+
7
+ FakeWeb.allow_net_connect = false
8
+
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ require 'flightcaster'
12
+
13
+ class Test::Unit::TestCase
14
+ end
15
+
16
+ def flightcaster_url(path, params)
17
+ "http://api.flightcaster.com#{path}?api_key=foo#{params}"
18
+ end
19
+
20
+ def fixture_file(filename)
21
+ return '' if filename == ''
22
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
23
+ File.read(file_path)
24
+ end
25
+
26
+ def stub_get(path, filename, params='', status=nil)
27
+ options = {:body => fixture_file(filename)}
28
+ options.merge!({:status => status}) unless status.nil?
29
+
30
+ FakeWeb.register_uri(:get, flightcaster_url(path, params), options)
31
+ end
File without changes
@@ -0,0 +1,219 @@
1
+ require 'helper'
2
+
3
+ class TestFlightCaster < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @flightcaster = FlightCaster.new("foo")
7
+ end
8
+
9
+ context "Initialization" do
10
+ should "require an API key" do
11
+ lambda { FlightCaster.new }.should raise_error
12
+ end
13
+
14
+ should "be passed an API key" do
15
+ FlightCaster.new("foo").api_key.should == "foo"
16
+ end
17
+ end
18
+
19
+ context "Fetching airlines" do
20
+
21
+ should "get all airlines" do
22
+ stub_get('/airlines.xml', 'airlines.xml')
23
+ airlines = @flightcaster.airlines
24
+ airlines.current_page.should == '1'
25
+ airlines.total_entries.should == '504'
26
+ airlines.total_pages.should == '17'
27
+ end
28
+
29
+ should "get airlines on certain page" do
30
+ stub_get('/airlines.xml', 'airlines_page.xml', '&page=3')
31
+ airlines = @flightcaster.airlines(:page => 3)
32
+ airlines.current_page.should == '3'
33
+ end
34
+
35
+ should "get airlines with 50 on each page" do
36
+ stub_get('/airlines.xml', 'airlines_per_page.xml', '&per_page=50')
37
+ airlines = @flightcaster.airlines(:per_page => 50)
38
+ airlines.airline.size.should == 50
39
+ end
40
+
41
+ end
42
+
43
+ context "Fetching airline" do
44
+ should "get one airline" do
45
+ stub_get('/airlines/221.xml', 'airline.xml')
46
+ airline = @flightcaster.airline(221)
47
+ airline.callsign.should == 'UNITED'
48
+ airline.name.should == 'United Airlines'
49
+ airline.icao_id.should == 'UAL'
50
+ end
51
+
52
+ should "raise error when given invalid airline number" do
53
+ stub_get('/airlines/-10.xml', 'notfound.xml', '', 404)
54
+ @flightcaster.airline(-10).should raise_error
55
+ end
56
+ end
57
+
58
+ context "Fetching airports" do
59
+ should "get all airports" do
60
+ stub_get('/airports.xml', 'airports.xml')
61
+ airports = @flightcaster.airports
62
+ airports.current_page.should == '1'
63
+ airports.total_entries.should == '2026'
64
+ airports.total_pages.should == '68'
65
+ airports.airport[0].city.should == 'New York'
66
+ end
67
+ end
68
+
69
+ context "Fetching airport" do
70
+ should "get one airport" do
71
+ stub_get('/airports/1.xml', 'airport.xml')
72
+ airport = @flightcaster.airport(1)
73
+ airport.city.should == 'Waterford Township'
74
+ airport.id.should == '1'
75
+ airport.elevation.should == '299'
76
+ end
77
+ end
78
+
79
+ context "Fetching flights" do
80
+ should "get all flights" do
81
+ stub_get('/flights.xml', 'flights.xml')
82
+ flights = @flightcaster.flights
83
+ flights.flight[0].id.should == 2858102
84
+ flights.flight[0].status == 'Scheduled'
85
+ end
86
+
87
+ should "get flights by airline" do
88
+ stub_get('/airlines/221/flights.xml', 'airline_flights.xml')
89
+ flights = @flightcaster.flights_by_airline(221)
90
+ flights.total_entries.should == '4898'
91
+ flights.total_pages.should == '164'
92
+ end
93
+
94
+ should "get arrivals to airport" do
95
+ stub_get('/airports/1/arrivals.xml', 'arrivals.xml')
96
+ arrivals = @flightcaster.airport_arrivals(1)
97
+ arrivals.total_entries.should == '15'
98
+ arrivals.total_pages.should == '1'
99
+ end
100
+
101
+ should "get departures from airport" do
102
+ stub_get('/airports/1/departures.xml', 'departures.xml')
103
+ departures = @flightcaster.airport_departures(1)
104
+ departures.total_entries.should == '16'
105
+ departures.total_pages.should == '1'
106
+ end
107
+
108
+ should "get flights by airline and flight number" do
109
+ stub_get('/airlines/VX/flights/28.xml', 'airline_flight.xml')
110
+ flights = @flightcaster.flight_by_airline('VX', 28)
111
+ flights.total_entries.should == '5'
112
+ flights.total_pages.should == '1'
113
+ end
114
+
115
+ should "get flights by airline, flight number, and date" do
116
+ stub_get('/airlines/VX/flights/28/20100226.xml', 'flight_date.xml')
117
+ flights = @flightcaster.flights_by_airline_on('VX', 28, '20100226')
118
+ flights.total_entries.should == '1'
119
+ end
120
+
121
+ should "find a flight from one airport to another" do
122
+ stub_get('/airports/PDX/departures/DFW.xml', 'flight_path.xml')
123
+ flights = @flightcaster.flight_path('PDX', 'DFW')
124
+ flights.total_entries.should == '6'
125
+ flights.total_pages.should == '3'
126
+ end
127
+
128
+ should "find a flight from one airport to another on a certain day" do
129
+ stub_get('/airports/PDX/departures/DFW/20090911.xml', 'flight_path_date.xml')
130
+ flights = @flightcaster.flight_path_on('PDX', 'DFW', '20090911')
131
+ flights.flight[0].id.should == 2877686
132
+ flights.flight.size.should == 22
133
+ end
134
+ end
135
+
136
+ context "Fetching flight" do
137
+ should "get one flight" do
138
+ stub_get('/flights/2858102.xml', 'flight.xml')
139
+ flight = @flightcaster.flight(2858102)
140
+ flight.id.should == 2858102
141
+ flight.status_code.should == 'S'
142
+ flight.flightstats_id.should == '184971694'
143
+ end
144
+ end
145
+
146
+ context "Fetching METARs" do
147
+ should "get all METARs" do
148
+ stub_get('/metars.xml', 'metars.xml')
149
+ metars = @flightcaster.metars
150
+ metars.total_entries.should == '350774'
151
+ metars.total_pages.should == '11693'
152
+ end
153
+
154
+ should "get one METAR" do
155
+ stub_get('/metars/KPDX.xml', 'metar.xml')
156
+ metar = @flightcaster.metar('KPDX')
157
+ metar.icao_id.should == 'KPDX'
158
+ metar.id.should == '42017199'
159
+ end
160
+ end
161
+
162
+ context "Fetching TAFs" do
163
+ should "get all TAFs" do
164
+ stub_get('/tafs.xml', 'tafs.xml')
165
+ tafs = @flightcaster.tafs
166
+ tafs.total_entries.should == '22773'
167
+ tafs.total_pages.should == '760'
168
+ end
169
+
170
+ should "get one TAF" do
171
+ stub_get('/tafs/KPDX.xml', 'taf.xml')
172
+ taf = @flightcaster.taf('KPDX')
173
+ taf.icao_id.should == 'KPDX'
174
+ taf.id.should == '1163624'
175
+ end
176
+ end
177
+
178
+ context "Fetching delays" do
179
+ should "get all general delays" do
180
+ stub_get('/delays.xml', 'general_delays.xml')
181
+ delays = @flightcaster.delays
182
+ delays.total_entries.should == '2'
183
+ delays.delay[0].id.should == '394071'
184
+ end
185
+
186
+ should "get one general delay" do
187
+ stub_get('/delays/KPDX.xml', 'general_delay.xml')
188
+ delay = @flightcaster.delay('KPDX')
189
+ delay.id.should == '394069'
190
+ end
191
+
192
+ should "get all ground delays" do
193
+ stub_get('/ground_delays.xml', 'ground_delays.xml')
194
+ ground_delays = @flightcaster.ground_delays
195
+ ground_delays.total_entries.should == '3'
196
+ ground_delays.ground_delay[0].id.should == '373404'
197
+ end
198
+
199
+ should "get one ground delay" do
200
+ stub_get('/ground_delays/KPDX.xml', 'ground_delay.xml')
201
+ ground_delay = @flightcaster.ground_delay('KPDX')
202
+ ground_delay.id.should == '373404'
203
+ ground_delay.airport_id.should == '6259'
204
+ end
205
+
206
+ should "get all ground stops" do
207
+ stub_get('/ground_stops.xml', 'ground_stops.xml')
208
+ ground_stops = @flightcaster.ground_stops
209
+ ground_stops.total_entries.should == '2'
210
+ ground_stops.ground_stop[0].id.should == '125918'
211
+ end
212
+
213
+ should "get one ground stop" do
214
+ stub_get('/ground_stops/KPDX.xml', 'ground_stop.xml')
215
+ ground_stop = @flightcaster.ground_stop('KPDX')
216
+ ground_stop.id.should == '125918'
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,10 @@
1
+ require 'helper'
2
+
3
+ class TestRequest < Test::Unit::TestCase
4
+ context "Requesting" do
5
+ should "add API key to base_uri" do
6
+ FlightCaster::Request.set_api_key("foo")
7
+ FlightCaster::Request.full_uri('/').should == "http://api.flightcaster.com/?api_key=foo"
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flightcaster
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jarod Luebbert
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-02-26 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: |-
33
+ Simple interaction with the flightcaster API. Look up
34
+ flight predictions and information.
35
+ email: jarod.luebbert@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - lib/flightcaster.rb
51
+ - lib/flightcaster/base.rb
52
+ - lib/flightcaster/request.rb
53
+ - test/fixtures/airline.xml
54
+ - test/fixtures/airline_flight.xml
55
+ - test/fixtures/airline_flights.xml
56
+ - test/fixtures/airlines.xml
57
+ - test/fixtures/airlines_page.xml
58
+ - test/fixtures/airlines_per_page.xml
59
+ - test/fixtures/airport.xml
60
+ - test/fixtures/airports.xml
61
+ - test/fixtures/arrivals.xml
62
+ - test/fixtures/departures.xml
63
+ - test/fixtures/flight.xml
64
+ - test/fixtures/flight_date.xml
65
+ - test/fixtures/flight_path.xml
66
+ - test/fixtures/flight_path_date.xml
67
+ - test/fixtures/flights.xml
68
+ - test/fixtures/general_delay.xml
69
+ - test/fixtures/general_delays.xml
70
+ - test/fixtures/ground_delay.xml
71
+ - test/fixtures/ground_delays.xml
72
+ - test/fixtures/ground_stop.xml
73
+ - test/fixtures/ground_stops.xml
74
+ - test/fixtures/metar.xml
75
+ - test/fixtures/metars.xml
76
+ - test/fixtures/notfound.xml
77
+ - test/fixtures/oldapi.xml
78
+ - test/fixtures/taf.xml
79
+ - test/fixtures/tafs.xml
80
+ - test/helper.rb
81
+ - test/test_base.rb
82
+ - test/test_flightcaster.rb
83
+ - test/test_request.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/jarodluebbert/flightcaster
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.6
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Simple interaction with the flightcaster API
114
+ test_files:
115
+ - test/helper.rb
116
+ - test/test_base.rb
117
+ - test/test_flightcaster.rb
118
+ - test/test_request.rb