flightstats-flex 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.md +252 -0
  2. data/lib/flightstats.rb +109 -0
  3. data/lib/flightstats/abstract_date.rb +6 -0
  4. data/lib/flightstats/actual_gate_departure.rb +4 -0
  5. data/lib/flightstats/actual_runway_departure.rb +4 -0
  6. data/lib/flightstats/airline.rb +10 -0
  7. data/lib/flightstats/airport.rb +88 -0
  8. data/lib/flightstats/airport_resources.rb +7 -0
  9. data/lib/flightstats/api.rb +73 -0
  10. data/lib/flightstats/api/errors.rb +120 -0
  11. data/lib/flightstats/api/net_http_adapter.rb +114 -0
  12. data/lib/flightstats/appendix.rb +6 -0
  13. data/lib/flightstats/arrival_date.rb +4 -0
  14. data/lib/flightstats/codeshare.rb +7 -0
  15. data/lib/flightstats/departure_date.rb +4 -0
  16. data/lib/flightstats/equipment.rb +10 -0
  17. data/lib/flightstats/estimated_gate_arrival.rb +4 -0
  18. data/lib/flightstats/estimated_gate_departure.rb +4 -0
  19. data/lib/flightstats/estimated_runway_arrival.rb +4 -0
  20. data/lib/flightstats/estimated_runway_departure.rb +4 -0
  21. data/lib/flightstats/extended_options.rb +6 -0
  22. data/lib/flightstats/flight.rb +61 -0
  23. data/lib/flightstats/flight_durations.rb +9 -0
  24. data/lib/flightstats/flight_equipment.rb +6 -0
  25. data/lib/flightstats/flight_id.rb +6 -0
  26. data/lib/flightstats/flight_leg.rb +25 -0
  27. data/lib/flightstats/flight_plan_planned_arrival.rb +4 -0
  28. data/lib/flightstats/flight_plan_planned_departure.rb +4 -0
  29. data/lib/flightstats/flight_status.rb +50 -0
  30. data/lib/flightstats/helper.rb +52 -0
  31. data/lib/flightstats/operational_times.rb +16 -0
  32. data/lib/flightstats/operator.rb +5 -0
  33. data/lib/flightstats/published_arrival.rb +4 -0
  34. data/lib/flightstats/published_departure.rb +4 -0
  35. data/lib/flightstats/resource.rb +108 -0
  36. data/lib/flightstats/schedule.rb +7 -0
  37. data/lib/flightstats/scheduled_gate_arrival.rb +4 -0
  38. data/lib/flightstats/scheduled_gate_departure.rb +4 -0
  39. data/lib/flightstats/version.rb +17 -0
  40. metadata +141 -0
data/README.md ADDED
@@ -0,0 +1,252 @@
1
+ flightstats-flex
2
+ ================
3
+
4
+ Ruby client for the FlightStats Flex API.
5
+
6
+ ## Installation
7
+
8
+ In your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'flightstats-flex', :git => 'https://github.com/diditclear/flightstats-client-ruby'
12
+ ```
13
+
14
+ Note that there is an old **flightstats** gem on [Rubygems](http://rubygems.org/gems/flightstats), hence the name **flightstats-flex** for this library.
15
+
16
+ ## Usage
17
+
18
+ You only need to configure your FlightStats app id and keys:
19
+
20
+ ```ruby
21
+ FlightStats.app_id = '1234'
22
+ FlightStats.app_key = '5678'
23
+ ```
24
+
25
+ You can also specify your own logger:
26
+
27
+ ```ruby
28
+ FlightStats.logger = Logger.new
29
+ ```
30
+
31
+ When using Rails, you can set it up in an initializer (e.g. config/initializers/flightstats.rb):
32
+
33
+ ```ruby
34
+ require 'flightstats'
35
+
36
+ FlightStats.app_id = '1234'
37
+ FlightStats.app_key = '5678'
38
+ FlightStats.logger = Rails.logger
39
+ ```
40
+
41
+ ## Supported APIs
42
+
43
+ ### Airports
44
+
45
+ #### Active airports
46
+
47
+ ```ruby
48
+ airports = FlightStats::Airport.actives
49
+ ```
50
+
51
+ #### Active airports for date
52
+
53
+ ```ruby
54
+ airports = FlightStats::Airport.actives_for_date 2013, 5, 1
55
+ ```
56
+
57
+ #### All airports (active and inactive)
58
+
59
+ ```ruby
60
+ airports = FlightStats::Airport.all
61
+ ```
62
+
63
+ #### Current airport by code (code type chosen via precedence order)
64
+
65
+ ```ruby
66
+ airports = FlightStats::Airport.current 'PDX'
67
+ ```
68
+
69
+ #### Airport on date by code
70
+
71
+ ```ruby
72
+ airports = FlightStats::Airport.on_date 'PDX', 2013, 5, 1
73
+ ```
74
+
75
+ #### Airports by city code
76
+
77
+ ```ruby
78
+ airports = FlightStats::Airport.by_city_code 'ABC'
79
+ ```
80
+
81
+ #### Airports by country code
82
+
83
+ ```ruby
84
+ airports = FlightStats::Airport.by_country_code 'GB'
85
+ ```
86
+
87
+ #### Airport by FlightStats code
88
+
89
+ ```ruby
90
+ airport = FlightStats::Airport.by_flight_stats_code 'PDX'
91
+ ```
92
+
93
+ #### Airports by IATA code
94
+
95
+ ```ruby
96
+ airports = FlightStats::Airport.by_iata_code 'PDX'
97
+ ```
98
+
99
+ #### Airport by IATA code on date
100
+
101
+ ```ruby
102
+ airport = FlightStats::Airport.by_iata_code_on_date 'PDX', 2013, 5, 1
103
+ ```
104
+
105
+ #### Airports by ICAO code
106
+
107
+ ```ruby
108
+ airports = FlightStats::Airport.by_icao_code 'KPDX'
109
+ ```
110
+
111
+ #### Airport by ICAO code on date
112
+
113
+ ```ruby
114
+ airport = FlightStats::Airport.by_icao_code_on_date 'KPDX', 2013, 5, 1
115
+ ```
116
+
117
+ #### Airports within radius of location
118
+
119
+ ```ruby
120
+ airports = FlightStats::Airport.within_radius 17, 39, 150
121
+ airports.size # => 9
122
+ airports[5].name # => "Papola Casale Airport"
123
+ ```
124
+
125
+ ### Flight Status & Track by Flight
126
+
127
+ #### Flight Status (by flight ID)
128
+
129
+ ```ruby
130
+ flight_status = FlightStats::FlightStatus.by_flight_id 1234
131
+ ```
132
+
133
+ #### Flight status (flights departing on date)
134
+
135
+ ```ruby
136
+ flight_statuses = FlightStats::FlightStatus.departing_on 'UA', 901, 2013, 5, 1
137
+ ```
138
+
139
+ #### Flight status (flights arriving on date)
140
+
141
+ ```ruby
142
+ flight_statuses = FlightStats::FlightStatus.arriving_on 'UA', 901, 2013, 5, 1
143
+ ```
144
+
145
+ #### Flight track (by flight ID)
146
+
147
+ ```ruby
148
+ flight_track = FlightStats::FlightStatus.track_by_flight_id 1234
149
+ ```
150
+
151
+ #### Flight tracks arriving on date (starting from specified hour of day)
152
+
153
+ ```ruby
154
+ flight_tracks = FlightStats::FlightStatus.track_arriving_on 'UA', 901, 2013, 5, 1
155
+ ```
156
+
157
+ #### Flight tracks departing on date (starting from specified hour of day)
158
+
159
+ ```ruby
160
+ flight_tracks = FlightStats::FlightStatus.track_departing_on 'UA', 901, 2013, 5, 1
161
+ ```
162
+
163
+
164
+ ### Schedules/Connections
165
+
166
+ #### Direct scheduled flights by arrival location and date
167
+
168
+ ```ruby
169
+ flights = FlightStats::Flight.direct_arriving_at 'EWR', 2013, 5, 1
170
+ ```
171
+
172
+ #### Direct scheduled flights by departure location and departure date
173
+
174
+ ```ruby
175
+ flights = FlightStats::Flight.direct_departing_from 'EWR', 2013, 5, 1
176
+ ```
177
+
178
+ #### Direct scheduled flights by carrier, flight number, and arrival date(s)
179
+
180
+ ```ruby
181
+ flights = FlightStats::Flight.direct_arriving_by_flight_number 'UA', 901, 2013, 5, 1
182
+ ```
183
+
184
+ #### Direct scheduled flights by carrier, flight number, arrival location and arrival date(s)
185
+
186
+ ```ruby
187
+ flights = FlightStats::Flight.direct_arriving_by_flight_number_and_location 'UA', 901, 'FRA', 2013, 5, 1
188
+ ```
189
+
190
+ #### Direct scheduled flights by carrier, flight number, and departure date(s)
191
+
192
+ ```ruby
193
+ flights = FlightStats::Flight.direct_arriving_by_flight_number 'UA', 901, 2013, 5, 1
194
+ ```
195
+
196
+ #### Direct scheduled flights by carrier, flight number, departure location and departure date(s)
197
+
198
+ ```ruby
199
+ flights = FlightStats::Flight.direct_arriving_by_flight_number_and_location 'UA', 901, 'FRA', 2013, 5, 1
200
+ ```
201
+
202
+ #### Direct and connecting scheduled flights between two locations by arrival date
203
+
204
+ ```ruby
205
+ flights = FlightStats::Flight.direct_and_connecting_arriving 'SFO', 'FRA', 2013, 5, 1
206
+ ```
207
+
208
+ #### Direct and connecting scheduled flights between two locations by departure date
209
+
210
+ ```ruby
211
+ flights = FlightStats::Flight.direct_and_connecting_departing 'SFO', 'FRA', 2013, 5, 1
212
+ ```
213
+
214
+
215
+ ## Contributing
216
+
217
+ There are two sets of tests.
218
+
219
+ The default one uses mock HTTP calls and can be run via:
220
+ ```bash
221
+ rake test:spec
222
+ ```
223
+
224
+ The remote ones will issue HTTP calls to FlightStats. You need to update your API credentials in spec/spec_helper.rb before running them:
225
+
226
+ ```bash
227
+ rake test:remote:spec
228
+ ```
229
+
230
+ ## License
231
+
232
+ (The MIT License.)
233
+
234
+ © 2013 DidItClear
235
+
236
+ Permission is hereby granted, free of charge, to any person obtaining a copy
237
+ of this software and associated documentation files (the "Software"), to deal
238
+ in the Software without restriction, including without limitation the rights
239
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
240
+ copies of the Software, and to permit persons to whom the Software is
241
+ furnished to do so, subject to the following conditions:
242
+
243
+ The above copyright notice and this permission notice shall be included in all
244
+ copies or substantial portions of the Software.
245
+
246
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
247
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
248
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
249
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
250
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
251
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
252
+ SOFTWARE.
@@ -0,0 +1,109 @@
1
+ module FlightStats
2
+ # The exception class from which all FlightStats exceptions inherit.
3
+ class Error < StandardError
4
+ def set_message message
5
+ @message = message
6
+ end
7
+
8
+ # @return [String]
9
+ def to_s
10
+ defined? @message and @message or super
11
+ end
12
+ end
13
+
14
+ # This exception is raised if FlightStats has not been configured.
15
+ class ConfigurationError < Error
16
+ end
17
+
18
+ class << self
19
+ # @return [String] An APP id.
20
+ # @raise [ConfigurationError] If not configured.
21
+ def app_id
22
+ defined? @app_id and @app_id or raise(
23
+ ConfigurationError, "FlightStats.app_id not configured"
24
+ )
25
+ end
26
+ attr_writer :app_id
27
+
28
+ # @return [String] An APP key.
29
+ # @raise [ConfigurationError] If not configured.
30
+ def app_key
31
+ defined? @app_key and @app_key or raise(
32
+ ConfigurationError, "FlightStats.app_key not configured"
33
+ )
34
+ end
35
+ attr_writer :app_key
36
+
37
+ # Assigns a logger to log requests/responses and more.
38
+ #
39
+ # @return [Logger, nil]
40
+ # @example
41
+ # require 'logger'
42
+ # FlightStats.logger = Logger.new STDOUT
43
+ # @example Rails applications automatically log to the Rails log:
44
+ # FlightStats.logger = Rails.logger
45
+ # @example Turn off logging entirely:
46
+ # FlightStats.logger = nil # Or FlightStats.logger = Logger.new nil
47
+ attr_accessor :logger
48
+
49
+ # Convenience logging method includes a Logger#progname dynamically.
50
+ # @return [true, nil]
51
+ def log level, message
52
+ logger.send(level, name) { message }
53
+ end
54
+
55
+ if RUBY_VERSION <= "1.9.0"
56
+ def const_defined? sym, inherit = false
57
+ raise ArgumentError, "inherit must be false" if inherit
58
+ super sym
59
+ end
60
+
61
+ def const_get sym, inherit = false
62
+ raise ArgumentError, "inherit must be false" if inherit
63
+ super sym
64
+ end
65
+ end
66
+ end
67
+
68
+ require 'flightstats/version'
69
+
70
+ require 'flightstats/helper'
71
+ require 'flightstats/api/errors'
72
+ require 'flightstats/api/net_http_adapter'
73
+
74
+ require 'flightstats/resource'
75
+
76
+ require 'flightstats/abstract_date'
77
+ require 'flightstats/actual_gate_departure'
78
+ require 'flightstats/actual_runway_departure'
79
+ require 'flightstats/airline'
80
+ require 'flightstats/airport'
81
+ require 'flightstats/airport_resources'
82
+ require 'flightstats/appendix'
83
+ require 'flightstats/arrival_date'
84
+ require 'flightstats/codeshare'
85
+ require 'flightstats/departure_date'
86
+ require 'flightstats/equipment'
87
+ require 'flightstats/estimated_gate_arrival'
88
+ require 'flightstats/estimated_gate_departure'
89
+ require 'flightstats/estimated_runway_arrival'
90
+ require 'flightstats/estimated_runway_departure'
91
+ require 'flightstats/extended_options'
92
+ require 'flightstats/flight'
93
+ require 'flightstats/flight_durations'
94
+ require 'flightstats/flight_equipment'
95
+ require 'flightstats/flight_id'
96
+ require 'flightstats/flight_leg'
97
+ require 'flightstats/flight_plan_planned_arrival'
98
+ require 'flightstats/flight_plan_planned_departure'
99
+ require 'flightstats/flight_status'
100
+ require 'flightstats/operational_times'
101
+ require 'flightstats/operator'
102
+ require 'flightstats/published_arrival'
103
+ require 'flightstats/published_departure'
104
+ require 'flightstats/schedule'
105
+ require 'flightstats/scheduled_gate_arrival'
106
+ require 'flightstats/scheduled_gate_departure'
107
+
108
+ require 'flightstats/api'
109
+ end
@@ -0,0 +1,6 @@
1
+ module FlightStats
2
+ class AbstractDate < Resource
3
+ attr_accessor :date_local,
4
+ :date_utc
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class ActualGateDeparture < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class ActualRunwayDeparture < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module FlightStats
2
+ class Airline < Resource
3
+ attr_accessor :fs,
4
+ :iata,
5
+ :icao,
6
+ :name,
7
+ :phone_number,
8
+ :active
9
+ end
10
+ end
@@ -0,0 +1,88 @@
1
+ module FlightStats
2
+ class Airport < Resource
3
+ attr_accessor :fs,
4
+ :iata,
5
+ :icao,
6
+ :faa,
7
+ :name,
8
+ :street1,
9
+ :city,
10
+ :city_code,
11
+ :state_code,
12
+ :postal_code,
13
+ :country_code,
14
+ :country_name,
15
+ :region_name,
16
+ :time_zone_region_name,
17
+ :weather_zone,
18
+ :local_time,
19
+ :utc_offset_hours,
20
+ :latitude,
21
+ :longitude,
22
+ :elevation_feet,
23
+ :classification,
24
+ :active,
25
+ :delay_index_url,
26
+ :weather_url
27
+
28
+ @@base_path = "/flex/airports/rest/v1/json"
29
+
30
+ class << self
31
+ def actives(options = {})
32
+ from_response API.get("#{base_path}/active", {}, options), 'airports'
33
+ end
34
+
35
+ def actives_for_date(year, month, day, options = {})
36
+ from_response API.get("#{base_path}/active/#{year}/#{month}/#{day}", {}, options), 'airports'
37
+ end
38
+
39
+ def all(options = {})
40
+ from_response API.get("#{base_path}/all", {}, options), 'airports'
41
+ end
42
+
43
+ def current(code, options = {})
44
+ from_response API.get("#{base_path}/#{code}/today", {}, options), 'airport'
45
+ end
46
+
47
+ def on_date(code, year, month, day, options = {})
48
+ from_response API.get("#{base_path}/#{code}/#{year}/#{month}/#{day}", {}, options), 'airport'
49
+ end
50
+
51
+ def by_city_code(city_code, options = {})
52
+ from_response API.get("#{base_path}/cityCode/#{city_code}", {}, options), 'airports'
53
+ end
54
+
55
+ def by_country_code(country_code, options = {})
56
+ from_response API.get("#{base_path}/countryCode/#{country_code}", {}, options), 'airports'
57
+ end
58
+
59
+ def by_flight_stats_code(flight_stats_code, options = {})
60
+ from_response API.get("#{base_path}/fs/#{flight_stats_code}", {}, options), 'airport'
61
+ end
62
+
63
+ def by_iata_code(iata_code, options = {})
64
+ from_response API.get("#{base_path}/iata/#{iata_code}", {}, options), 'airports'
65
+ end
66
+
67
+ def by_iata_code_on_date(iata_code, year, month, day, options = {})
68
+ from_response API.get("#{base_path}/iata/#{iata_code}/#{year}/#{month}/#{day}", {}, options), 'airport'
69
+ end
70
+
71
+ def by_icao_code(icao_code, options = {})
72
+ from_response API.get("#{base_path}/icao/#{icao_code}", {}, options), 'airports'
73
+ end
74
+
75
+ def by_icao_code_on_date(icao_code, year, month, day, options = {})
76
+ from_response API.get("#{base_path}/icao/#{icao_code}/#{year}/#{month}/#{day}", {}, options), 'airport'
77
+ end
78
+
79
+ def within_radius(longitude, latitude, radius_miles, options = {})
80
+ from_response API.get("#{base_path}/withinRadius/#{longitude}/#{latitude}/#{radius_miles}", {}, options), 'airports'
81
+ end
82
+
83
+ def base_path
84
+ @@base_path
85
+ end
86
+ end
87
+ end
88
+ end