flightstats-flex 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 (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
@@ -0,0 +1,9 @@
1
+ module FlightStats
2
+ class FlightDurations < Resource
3
+ attr_accessor :scheduled_block_minutes,
4
+ :scheduled_air_minutes,
5
+ :scheduled_taxi_out_minutes,
6
+ :taxi_out_minutes,
7
+ :scheduled_taxi_in_minutes
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module FlightStats
2
+ class FlightEquipment < Resource
3
+ attr_accessor :scheduled_equipment_iata_code,
4
+ :actual_equipment_iata_code
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module FlightStats
2
+ class FlightId < Resource
3
+ attr_accessor :requested,
4
+ :interpreted
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ module FlightStats
2
+ class FlightLeg < Resource
3
+ attr_accessor :departure_airport_fs_code,
4
+ :arrival_airport_fs_code,
5
+ :departure_time,
6
+ :arrival_time,
7
+ :departure_date_adjustment,
8
+ :arrival_date_adjustment,
9
+ :departure_terminal,
10
+ :arrival_terminal,
11
+ :flight_number,
12
+ :codeshare,
13
+ :equipment_codes,
14
+ :distance_miles,
15
+ :flight_duration_minutes,
16
+ :layover_duration_minutes,
17
+ :operator,
18
+ :carrier_fs_code,
19
+ :wetlease_info
20
+
21
+ def to_s
22
+ "#{operator ? operator.carrier_fs_code : carrier_fs_code}#{flight_number}: #{departure_airport_fs_code} at #{departure_time} - #{arrival_airport_fs_code} at #{arrival_time} (+#{arrival_date_adjustment}) #{distance_miles} miles"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class FlightPlanPlannedArrival < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class FlightPlanPlannedDeparture < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,50 @@
1
+ module FlightStats
2
+ class FlightStatus < Resource
3
+ attr_accessor :flight_id,
4
+ :carrier_fs_code,
5
+ :flight_number,
6
+ :departure_airport_fs_code,
7
+ :arrival_airport_fs_code,
8
+ :departure_date,
9
+ :arrival_date,
10
+ :status,
11
+ :schedule,
12
+ :operational_times,
13
+ :codeshares,
14
+ :flight_durations,
15
+ :airport_resources,
16
+ :flight_equipment
17
+
18
+ @@base_path = "/flex/flightstatus/rest/v2/json"
19
+
20
+ class << self
21
+ def by_flight_id(flight_id, options = {})
22
+ from_response API.get("#{base_path}/flight/status/#{flight_id}", {}, options), 'flightStatus'
23
+ end
24
+
25
+ def departing_on(carrier, flight_number, year, month, day, options = {})
26
+ from_response API.get("#{base_path}/flight/status/#{carrier}/#{flight_number}/dep/#{year}/#{month}/#{day}", {}, options), 'flightStatuses'
27
+ end
28
+
29
+ def arriving_on(carrier, flight_number, year, month, day, options = {})
30
+ from_response API.get("#{base_path}/flight/status/#{carrier}/#{flight_number}/arr/#{year}/#{month}/#{day}", {}, options), 'flightStatuses'
31
+ end
32
+
33
+ def track_by_flight_id(flight_id, options = {})
34
+ from_response API.get("#{base_path}/flight/track/#{flight_id}", {}, options), 'flightTrack'
35
+ end
36
+
37
+ def track_arriving_on(carrier, flight_number, year, month, day, options = {})
38
+ from_response API.get("#{base_path}/flight/tracks/#{carrier}/#{flight_number}/arr/#{year}/#{month}/#{day}", {}, options), 'flightTracks'
39
+ end
40
+
41
+ def track_departing_on(carrier, flight_number, year, month, day, options = {})
42
+ from_response API.get("#{base_path}/flight/tracks/#{carrier}/#{flight_number}/dep/#{year}/#{month}/#{day}", {}, options), 'flightTracks'
43
+ end
44
+
45
+ def base_path
46
+ @@base_path
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ module FlightStats
2
+ module Helper
3
+ def camelize underscored_word
4
+ underscored_word.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }
5
+ end
6
+
7
+ def classify value
8
+ camelize value.to_s.sub(/.*\./, '')
9
+ end
10
+
11
+ def demodulize class_name_in_module
12
+ class_name_in_module.to_s.sub(/^.*::/, '')
13
+ end
14
+
15
+ def pluralize word
16
+ word.to_s.sub(/([^s])$/, '\1s')
17
+ end
18
+
19
+ def singularize word
20
+ if word.to_s =~ /ses$/
21
+ word.to_s.sub(/es$/, '')
22
+ else
23
+ word.to_s.sub(/s$/, '').sub(/ie$/, 'y')
24
+ end
25
+ end
26
+
27
+ def underscore camel_cased_word
28
+ word = camel_cased_word.to_s.dup
29
+ word.gsub!(/::/, '/')
30
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
31
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
32
+ word.tr! "-", "_"
33
+ word.downcase!
34
+ word
35
+ end
36
+
37
+ def hash_with_indifferent_read_access base = {}
38
+ indifferent = Hash.new { |hash, key| hash[key.to_s] if key.is_a? Symbol }
39
+ base.each_pair { |key, value| indifferent[key.to_s] = value }
40
+ indifferent
41
+ end
42
+
43
+ def stringify_keys! hash
44
+ hash.keys.each do |key|
45
+ stringify_keys! hash[key] if hash[key].is_a? Hash
46
+ hash[key.to_s] = hash.delete key if key.is_a? Symbol
47
+ end
48
+ end
49
+
50
+ extend self
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ module FlightStats
2
+ class OperationalTimes < Resource
3
+ attr_accessor :published_departure,
4
+ :published_arrival,
5
+ :scheduled_gate_departure,
6
+ :estimated_gate_departure,
7
+ :actual_gate_departure,
8
+ :flight_plan_planned_departure,
9
+ :estimated_runway_departure,
10
+ :actual_runway_departure,
11
+ :scheduled_gate_arrival,
12
+ :estimated_gate_arrival,
13
+ :flight_plan_planned_arrival,
14
+ :estimated_runway_arrival
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module FlightStats
2
+ class Operator < Resource
3
+ attr_accessor :carrier_fs_code
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class PublishedArrival < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class PublishedDeparture < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,108 @@
1
+ require 'date'
2
+ require 'json'
3
+
4
+ module FlightStats
5
+ class Resource
6
+ class << self
7
+ # Instantiates a record from an HTTP response.
8
+ #
9
+ # @return [Resource]
10
+ # @param response [Net::HTTPResponse]
11
+ # @param response_key [String]
12
+ def from_response response, response_key=nil
13
+ record = from_json response.body, response_key
14
+ record.instance_eval { @etag, @response = response['ETag'], response }
15
+ record
16
+ end
17
+
18
+ # Instantiates a record from a JSON blob.
19
+ #
20
+ # @return [Resource]
21
+ # @param json [String]
22
+ # @param response_key [String]
23
+ # @see from_response
24
+ def from_json json, response_key
25
+ model = nil
26
+ raw = JSON.parse(json)
27
+ response_key ? from_parsed_json(raw[response_key], response_key) : raw
28
+ end
29
+
30
+ # Given a string (key in the response json), find the right model.
31
+ #
32
+ # @return [Resource] class corresponding to the string, nil if no model is associated with it
33
+ # @param model_string [String]
34
+ # @see from_response
35
+ def string_to_model(model_string)
36
+ return nil if model_string.nil?
37
+ begin
38
+ class_name = Helper.classify(model_string)
39
+ FlightStats.const_get(class_name)
40
+ rescue NameError => e
41
+ # FlightStats.logger.warn e
42
+ nil
43
+ end
44
+ end
45
+
46
+ def from_parsed_json(json, model_string)
47
+ if json.is_a? Array
48
+ value = []
49
+ json.each do |one_value|
50
+ value << from_parsed_json(one_value, model_string)
51
+ end
52
+ value
53
+ else
54
+ model = nil
55
+ # See if it's a series of objects (e.g. schedules)
56
+ model = string_to_model(Helper.singularize(model_string))
57
+ model = string_to_model(model_string) if model.nil?
58
+
59
+ if !model.nil? and !json.is_a? Hash
60
+ json
61
+ else
62
+ model.nil? ? json : model.send("new", json)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ # @return [Hash] The raw hash of record attributes.
69
+ attr_reader :attributes
70
+
71
+ # @return [Net::HTTPResponse, nil] The most recent response object for the record.
72
+ attr_reader :response
73
+
74
+ # @return [String, nil] An ETag for the current record.
75
+ attr_reader :etag
76
+
77
+ # @return [String, nil] A writer to override the URI the record saves to.
78
+ attr_writer :uri
79
+
80
+ # @return [Resource] A new resource instance.
81
+ # @param attributes [Hash] A hash of attributes.
82
+ def initialize attributes = {}
83
+ if instance_of? Resource
84
+ raise Error, "#{self.class} is an abstract class and cannot be instantiated"
85
+ end
86
+
87
+ @attributes, @uri, @href = {}, false, false
88
+ self.attributes = attributes
89
+ yield self if block_given?
90
+ end
91
+
92
+ # Apply a given hash of attributes to an object.
93
+ #
94
+ # @return [Hash]
95
+ # @param attributes [Hash] A hash of attributes.
96
+ def attributes= attributes = {}
97
+ return if attributes.nil?
98
+ attributes.each_pair { |k, v|
99
+ value = FlightStats::Resource.from_parsed_json(v, k)
100
+ respond_to?(name = "#{Helper.underscore k}=") and send(name, value)
101
+ }
102
+ end
103
+
104
+ def to_param
105
+ self[self.class.param_name]
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,7 @@
1
+ module FlightStats
2
+ class Schedule < Resource
3
+ attr_accessor :flight_type,
4
+ :service_classes,
5
+ :restrictions
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class ScheduledGateArrival < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module FlightStats
2
+ class ScheduledGateDeparture < AbstractDate
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module FlightStats
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+ PRE = nil
7
+
8
+ VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
9
+
10
+ class << self
11
+ def inspect
12
+ VERSION.dup
13
+ end
14
+ alias to_s inspect
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flightstats-flex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - DidItClear
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.12.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.12.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.7.6
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.6
62
+ description: ! 'An API client library for FlightStats Flex: http://flightstats.com'
63
+ email: didyourupgradeclear@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - README.md
68
+ files:
69
+ - lib/flightstats/abstract_date.rb
70
+ - lib/flightstats/actual_gate_departure.rb
71
+ - lib/flightstats/actual_runway_departure.rb
72
+ - lib/flightstats/airline.rb
73
+ - lib/flightstats/airport.rb
74
+ - lib/flightstats/airport_resources.rb
75
+ - lib/flightstats/api/errors.rb
76
+ - lib/flightstats/api/net_http_adapter.rb
77
+ - lib/flightstats/api.rb
78
+ - lib/flightstats/appendix.rb
79
+ - lib/flightstats/arrival_date.rb
80
+ - lib/flightstats/codeshare.rb
81
+ - lib/flightstats/departure_date.rb
82
+ - lib/flightstats/equipment.rb
83
+ - lib/flightstats/estimated_gate_arrival.rb
84
+ - lib/flightstats/estimated_gate_departure.rb
85
+ - lib/flightstats/estimated_runway_arrival.rb
86
+ - lib/flightstats/estimated_runway_departure.rb
87
+ - lib/flightstats/extended_options.rb
88
+ - lib/flightstats/flight.rb
89
+ - lib/flightstats/flight_durations.rb
90
+ - lib/flightstats/flight_equipment.rb
91
+ - lib/flightstats/flight_id.rb
92
+ - lib/flightstats/flight_leg.rb
93
+ - lib/flightstats/flight_plan_planned_arrival.rb
94
+ - lib/flightstats/flight_plan_planned_departure.rb
95
+ - lib/flightstats/flight_status.rb
96
+ - lib/flightstats/helper.rb
97
+ - lib/flightstats/operational_times.rb
98
+ - lib/flightstats/operator.rb
99
+ - lib/flightstats/published_arrival.rb
100
+ - lib/flightstats/published_departure.rb
101
+ - lib/flightstats/resource.rb
102
+ - lib/flightstats/schedule.rb
103
+ - lib/flightstats/scheduled_gate_arrival.rb
104
+ - lib/flightstats/scheduled_gate_departure.rb
105
+ - lib/flightstats/version.rb
106
+ - lib/flightstats.rb
107
+ - README.md
108
+ homepage: https://github.com/diditclear/flightstats-client-ruby
109
+ licenses:
110
+ - MIT
111
+ post_install_message:
112
+ rdoc_options:
113
+ - --main
114
+ - README.md
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: -872591453760459958
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: -872591453760459958
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.24
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: FlightStats Flex API Client
141
+ test_files: []