flightcaster 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ *.gem
20
21
 
21
22
  ## PROJECT::SPECIFIC
@@ -9,6 +9,8 @@ See the examples directory.
9
9
 
10
10
  == docs
11
11
 
12
+ http://rdoc.info/projects/jarodluebbert/flightcaster
13
+
12
14
  == Note on Patches/Pull Requests
13
15
 
14
16
  * Fork the project.
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
2
 
4
3
  begin
@@ -11,7 +10,12 @@ begin
11
10
  gem.email = "jarod.luebbert@gmail.com"
12
11
  gem.homepage = "http://github.com/jarodluebbert/flightcaster"
13
12
  gem.authors = ["Jarod Luebbert"]
14
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 2.10.2"
14
+ gem.add_development_dependency "shoulda", ">= 2.10.2"
15
+ gem.add_development_dependency "mhennemeyer-matchy", ">= 0.3.3"
16
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
17
+ gem.add_dependency "httparty", ">= 0.5.2"
18
+ gem.add_dependency "hashie", ">= 0.1.8"
15
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
20
  end
17
21
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'flightcaster')
2
+
3
+ flightcaster = FlightCaster.new('secret')
4
+
5
+ flights = flightcaster.flights
6
+
7
+ # all flights
8
+ flights.each do |f|
9
+ puts "#{f.airline_icao_id}-#{f.number}"
10
+ end
11
+
12
+ puts "*"*50
13
+
14
+ # all flights going from PDX to DFW
15
+ flights = flightcaster.flight_path('PDX', 'DFW')
16
+
17
+ flights.each do |f|
18
+ puts "#{f.airline_icao_id}-#{f.number}"
19
+ end
20
+
21
+ puts "*"*50
22
+
23
+ # all flights with a certain airline
24
+ flights = flightcaster.flights_by_airline('VX')
25
+
26
+ flights.each do |f|
27
+ puts "#{f.airline_icao_id}-#{f.number}"
28
+ end
@@ -0,0 +1,106 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{flightcaster}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jarod Luebbert"]
12
+ s.date = %q{2010-02-26}
13
+ s.description = %q{Simple interaction with the flightcaster API. Look up
14
+ flight predictions and information.}
15
+ s.email = %q{jarod.luebbert@gmail.com}
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "examples/flights.rb",
28
+ "flightcaster.gemspec",
29
+ "lib/flightcaster.rb",
30
+ "lib/flightcaster/base.rb",
31
+ "lib/flightcaster/request.rb",
32
+ "lib/flightcaster/result.rb",
33
+ "test/fixtures/airline.xml",
34
+ "test/fixtures/airline_flight.xml",
35
+ "test/fixtures/airline_flights.xml",
36
+ "test/fixtures/airlines.xml",
37
+ "test/fixtures/airlines_page.xml",
38
+ "test/fixtures/airlines_per_page.xml",
39
+ "test/fixtures/airport.xml",
40
+ "test/fixtures/airports.xml",
41
+ "test/fixtures/arrivals.xml",
42
+ "test/fixtures/departures.xml",
43
+ "test/fixtures/flight.xml",
44
+ "test/fixtures/flight_date.xml",
45
+ "test/fixtures/flight_path.xml",
46
+ "test/fixtures/flight_path_date.xml",
47
+ "test/fixtures/flights.xml",
48
+ "test/fixtures/general_delay.xml",
49
+ "test/fixtures/general_delays.xml",
50
+ "test/fixtures/ground_delay.xml",
51
+ "test/fixtures/ground_delays.xml",
52
+ "test/fixtures/ground_stop.xml",
53
+ "test/fixtures/ground_stops.xml",
54
+ "test/fixtures/metar.xml",
55
+ "test/fixtures/metars.xml",
56
+ "test/fixtures/notfound.xml",
57
+ "test/fixtures/oldapi.xml",
58
+ "test/fixtures/taf.xml",
59
+ "test/fixtures/tafs.xml",
60
+ "test/helper.rb",
61
+ "test/test_base.rb",
62
+ "test/test_flightcaster.rb",
63
+ "test/test_request.rb"
64
+ ]
65
+ s.homepage = %q{http://github.com/jarodluebbert/flightcaster}
66
+ s.rdoc_options = ["--charset=UTF-8"]
67
+ s.require_paths = ["lib"]
68
+ s.rubygems_version = %q{1.3.6}
69
+ s.summary = %q{Simple interaction with the flightcaster API}
70
+ s.test_files = [
71
+ "test/helper.rb",
72
+ "test/test_base.rb",
73
+ "test/test_flightcaster.rb",
74
+ "test/test_request.rb",
75
+ "examples/flights.rb"
76
+ ]
77
+
78
+ if s.respond_to? :specification_version then
79
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
80
+ s.specification_version = 3
81
+
82
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
83
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
84
+ s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
85
+ s.add_development_dependency(%q<mhennemeyer-matchy>, [">= 0.3.3"])
86
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
87
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
88
+ s.add_runtime_dependency(%q<hashie>, [">= 0.1.8"])
89
+ else
90
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
91
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
92
+ s.add_dependency(%q<mhennemeyer-matchy>, [">= 0.3.3"])
93
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
94
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
95
+ s.add_dependency(%q<hashie>, [">= 0.1.8"])
96
+ end
97
+ else
98
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
99
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
100
+ s.add_dependency(%q<mhennemeyer-matchy>, [">= 0.3.3"])
101
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
102
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
103
+ s.add_dependency(%q<hashie>, [">= 0.1.8"])
104
+ end
105
+ end
106
+
@@ -1,11 +1,12 @@
1
- require 'rubygems'
1
+ require 'forwardable'
2
2
  gem 'httparty', '~> 0.5.2'
3
3
  require 'httparty'
4
4
  gem 'hashie', '~> 0.1.8'
5
5
  require 'hashie'
6
6
 
7
7
  [ "base",
8
- "request" ].each do |file|
8
+ "request",
9
+ "result" ].each do |file|
9
10
  require File.join(File.dirname(__FILE__), 'flightcaster', file)
10
11
  end
11
12
 
@@ -7,44 +7,72 @@ module FlightCaster
7
7
  FlightCaster::Request.set_api_key(@api_key)
8
8
  end
9
9
 
10
+ # Params
11
+ # :per_page => The number of results per page. Defaults to 30.
12
+ # :page => The page of results displayed.
10
13
  def airlines(params={})
11
14
  perform_get('/airlines.xml', params)
12
15
  end
13
16
 
17
+ # id
18
+ # The FlightCaster id
19
+ # The 2 character IATA id
20
+ # The 3 chracter ICAO id of the airline
14
21
  def airline(id)
15
22
  perform_get("/airlines/#{id}.xml")
16
23
  end
17
24
 
25
+ # Params
26
+ # :per_page => The number of results per page. Defaults to 30.
27
+ # :page => The page of results displayed.
18
28
  def airports(params={})
19
29
  perform_get('/airports.xml', params)
20
30
  end
21
31
 
32
+ # id
33
+ # The FlightCaster id
34
+ # The 3 character IATA id
35
+ # The 4 chracter ICAO id of the airport
22
36
  def airport(id)
23
37
  perform_get("/airports/#{id}.xml")
24
38
  end
25
39
 
40
+ # id
41
+ # The FlightCaster id
42
+ # The 3 character IATA id
43
+ # The 4 chracter ICAO id of the airport
44
+ # Get all arrivals at an airport.
26
45
  def airport_arrivals(id, params={})
27
46
  perform_get("/airports/#{id}/arrivals.xml", params)
28
47
  end
29
48
 
49
+ # id
50
+ # The FlightCaster id
51
+ # The 3 character IATA id
52
+ # The 4 chracter ICAO id of the airport
53
+ # Get all departures leaving an airport.
30
54
  def airport_departures(id, params={})
31
55
  perform_get("/airports/#{id}/departures.xml", params)
32
56
  end
33
57
 
58
+ # id
59
+ # The id given to the flight by FlightCaster
34
60
  def flight(id)
35
61
  perform_get("/flights/#{id}.xml")
36
62
  end
37
63
 
38
- # TODO: rename this method to something more obvious
64
+ # Get all flights for a sepcific airline on a given date.
39
65
  def flights_by_airline_on(airline_id, flight_number, date, params={})
40
66
  t = convert_date(date)
41
67
  perform_get("/airlines/#{airline_id}/flights/#{flight_number}/#{t}.xml", params)
42
68
  end
43
69
 
70
+ # Get all flights from one airport to another.
44
71
  def flight_path(from, to, params={})
45
72
  perform_get("/airports/#{from}/departures/#{to}.xml", params)
46
73
  end
47
74
 
75
+ # Get all flights from one airport to another on a given date.
48
76
  def flight_path_on(from, to, date, params={})
49
77
  t = convert_date(date)
50
78
  perform_get("/airports/#{from}/departures/#{to}/#{t}.xml", params)
@@ -22,10 +22,7 @@ module FlightCaster
22
22
  begin
23
23
  raise_errors(response)
24
24
  data = parse(response)
25
- h = Hashie::Mash.new(data)
26
- # since the hash looks like { :airlines => { stuff we want } },
27
- # we just grab the value from the first key
28
- h[h.keys[0]]
25
+ FlightCaster::Result.new(data)
29
26
  rescue
30
27
  end
31
28
  end
@@ -50,6 +47,5 @@ module FlightCaster
50
47
  end
51
48
  final
52
49
  end
53
-
54
50
  end
55
51
  end
@@ -0,0 +1,51 @@
1
+ module FlightCaster
2
+ class Result
3
+ extend Forwardable
4
+
5
+ def initialize(data)
6
+ @h = generate_hash(data)
7
+ end
8
+
9
+ def_delegators :@h, :id, :replace, :each_key, :keys, :delete,
10
+ :[], :[]=, :merge!, :method_missing
11
+
12
+ # When enumerating a hash, look for an array with the
13
+ # response results and pass it the block.
14
+ def each(&blk)
15
+ @h.results.each(&blk)
16
+ end
17
+
18
+ def [](key)
19
+ @h.results[key]
20
+ end
21
+
22
+ def size
23
+ @h.results.size
24
+ end
25
+
26
+ private
27
+
28
+ def generate_hash(data)
29
+ h = Hashie::Mash.new(data)
30
+ # since the hash looks like { :airlines => { stuff we want } },
31
+ # we just grab the value from the first key
32
+ h = h[h.keys[0]]
33
+ # now we have:
34
+ # { :total_entries => 1, ... , :data_requested => [array of hashes], }
35
+ # for example if the user requests `.flights` then in order to
36
+ # iterate over all flights `.flights.flight.each` would be needed.
37
+ # To get around this, we need to grab out that array of hashes
38
+ # and store it in a general location so we can overload `.each`
39
+ h.each_key do |key|
40
+ if h[key].class == Array
41
+ results = []
42
+ h[key].each do |item|
43
+ results << item
44
+ end
45
+ h.delete(key)
46
+ h.merge!({ :results => results })
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,8 +1,8 @@
1
- require 'rubygems'
2
1
  require 'test/unit'
3
2
  require 'shoulda'
4
3
  require 'matchy'
5
4
  require 'fakeweb'
5
+ begin; require 'turn'; rescue LoadError; end
6
6
 
7
7
  FakeWeb.allow_net_connect = false
8
8
 
@@ -35,7 +35,7 @@ class TestFlightCaster < Test::Unit::TestCase
35
35
  should "get airlines with 50 on each page" do
36
36
  stub_get('/airlines.xml', 'airlines_per_page.xml', '&per_page=50')
37
37
  airlines = @flightcaster.airlines(:per_page => 50)
38
- airlines.airline.size.should == 50
38
+ airlines.size.should == 50
39
39
  end
40
40
 
41
41
  end
@@ -62,7 +62,7 @@ class TestFlightCaster < Test::Unit::TestCase
62
62
  airports.current_page.should == '1'
63
63
  airports.total_entries.should == '2026'
64
64
  airports.total_pages.should == '68'
65
- airports.airport[0].city.should == 'New York'
65
+ airports[0].city.should == 'New York'
66
66
  end
67
67
  end
68
68
 
@@ -80,8 +80,8 @@ class TestFlightCaster < Test::Unit::TestCase
80
80
  should "get all flights" do
81
81
  stub_get('/flights.xml', 'flights.xml')
82
82
  flights = @flightcaster.flights
83
- flights.flight[0].id.should == 2858102
84
- flights.flight[0].status == 'Scheduled'
83
+ flights[0].id.should == 2858102
84
+ flights[0].status == 'Scheduled'
85
85
  end
86
86
 
87
87
  should "get flights by airline" do
@@ -128,8 +128,8 @@ class TestFlightCaster < Test::Unit::TestCase
128
128
  should "find a flight from one airport to another on a certain day" do
129
129
  stub_get('/airports/PDX/departures/DFW/20090911.xml', 'flight_path_date.xml')
130
130
  flights = @flightcaster.flight_path_on('PDX', 'DFW', '20090911')
131
- flights.flight[0].id.should == 2877686
132
- flights.flight.size.should == 22
131
+ flights[0].id.should == 2877686
132
+ flights.size.should == 22
133
133
  end
134
134
  end
135
135
 
@@ -141,6 +141,12 @@ class TestFlightCaster < Test::Unit::TestCase
141
141
  flight.status_code.should == 'S'
142
142
  flight.flightstats_id.should == '184971694'
143
143
  end
144
+
145
+ should "get predictions for one flight" do
146
+ #stub_get('/flights/2858102.xml', 'flight.xml')
147
+ #flight = @flightcaster.flight(2858102)
148
+ #flight.predictions[0].state.should == 'delayed'
149
+ end
144
150
  end
145
151
 
146
152
  context "Fetching METARs" do
@@ -180,7 +186,7 @@ class TestFlightCaster < Test::Unit::TestCase
180
186
  stub_get('/delays.xml', 'general_delays.xml')
181
187
  delays = @flightcaster.delays
182
188
  delays.total_entries.should == '2'
183
- delays.delay[0].id.should == '394071'
189
+ delays[0].id.should == '394071'
184
190
  end
185
191
 
186
192
  should "get one general delay" do
@@ -193,7 +199,7 @@ class TestFlightCaster < Test::Unit::TestCase
193
199
  stub_get('/ground_delays.xml', 'ground_delays.xml')
194
200
  ground_delays = @flightcaster.ground_delays
195
201
  ground_delays.total_entries.should == '3'
196
- ground_delays.ground_delay[0].id.should == '373404'
202
+ ground_delays[0].id.should == '373404'
197
203
  end
198
204
 
199
205
  should "get one ground delay" do
@@ -207,7 +213,7 @@ class TestFlightCaster < Test::Unit::TestCase
207
213
  stub_get('/ground_stops.xml', 'ground_stops.xml')
208
214
  ground_stops = @flightcaster.ground_stops
209
215
  ground_stops.total_entries.should == '2'
210
- ground_stops.ground_stop[0].id.should == '125918'
216
+ ground_stops[0].id.should == '125918'
211
217
  end
212
218
 
213
219
  should "get one ground stop" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jarod Luebbert
@@ -29,6 +29,76 @@ dependencies:
29
29
  version: "0"
30
30
  type: :development
31
31
  version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: shoulda
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 2
41
+ - 10
42
+ - 2
43
+ version: 2.10.2
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: mhennemeyer-matchy
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ - 3
56
+ - 3
57
+ version: 0.3.3
58
+ type: :development
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: fakeweb
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 1
69
+ - 2
70
+ - 8
71
+ version: 1.2.8
72
+ type: :development
73
+ version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: httparty
76
+ prerelease: false
77
+ requirement: &id005 !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ - 5
84
+ - 2
85
+ version: 0.5.2
86
+ type: :runtime
87
+ version_requirements: *id005
88
+ - !ruby/object:Gem::Dependency
89
+ name: hashie
90
+ prerelease: false
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ - 1
98
+ - 8
99
+ version: 0.1.8
100
+ type: :runtime
101
+ version_requirements: *id006
32
102
  description: |-
33
103
  Simple interaction with the flightcaster API. Look up
34
104
  flight predictions and information.
@@ -47,9 +117,12 @@ files:
47
117
  - README.rdoc
48
118
  - Rakefile
49
119
  - VERSION
120
+ - examples/flights.rb
121
+ - flightcaster.gemspec
50
122
  - lib/flightcaster.rb
51
123
  - lib/flightcaster/base.rb
52
124
  - lib/flightcaster/request.rb
125
+ - lib/flightcaster/result.rb
53
126
  - test/fixtures/airline.xml
54
127
  - test/fixtures/airline_flight.xml
55
128
  - test/fixtures/airline_flights.xml
@@ -116,3 +189,4 @@ test_files:
116
189
  - test/test_base.rb
117
190
  - test/test_flightcaster.rb
118
191
  - test/test_request.rb
192
+ - examples/flights.rb