jetblue_plane_tracker 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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MWMyNWJlN2M1ZWEyNTYzZDc0YmVjZWM0ZGRkYjU4MGJlYWUxNTMzNA==
5
+ data.tar.gz: !binary |-
6
+ MjFmMGFjYjkzY2VjODRlZDEzMGJkYTQxZTc5MTMwYjAxZjVjOGIzNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ M2E1Nzg5YTM0ZmI1MDk3YjVhZWQ1ZDMyYmVkOTMzZGJkMGUzN2QxYmQ0Yjhh
10
+ OWZlNzA3ZmUxMWIyMGFmNTM4MDg5MmQwMWY0ZTNkYzM4ZGEzZTA0Y2ViMzAw
11
+ MDAzMzc0YTQyY2I5ZDU2YWFiYzk5YmQzZGYzZjQ4ZDMwYWI0MDU=
12
+ data.tar.gz: !binary |-
13
+ ODQzMzNjNjUwMTYzNmNkYmUwNzc4ZjY4M2YyZjg3ZTkyZTk3MGJlYTdkMWJm
14
+ MjM3ZDNiY2ViM2MyMzE5NTEwOTU0YTE4MWU5NTFjOGQ2YTc4Nzg2ZTUyM2Y5
15
+ ZDYwY2YxMzc0N2UxZDUzMWFjN2Y3MTU2OTliODMwOGQyNzRlZjI=
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # JetBlue Plane Tracker
2
+ A Ruby wrapper for JetBlue flights status tracker.
3
+
@@ -0,0 +1,64 @@
1
+ module JetBluePlaneTracker
2
+
3
+ class Airport
4
+
5
+ include HTTParty
6
+ base_uri "airport-data.com/api"
7
+
8
+ attr_accessor :icao, :iata, :name, :location, :country, :country_code, :longitude, :latitude
9
+
10
+ def initialize(icao, iata, name, location, country, country_code, longitude, latitude)
11
+ self.icao = icao
12
+ self.iata = iata
13
+ self.name = name
14
+ self.location = location
15
+ self.country = country
16
+ self.country_code = country_code
17
+ self.longitude = longitude
18
+ self.latitude = latitude
19
+ end
20
+
21
+ def to_s
22
+ str = ""
23
+ self.instance_variables.each do |var|
24
+ name = var.to_s.gsub!("@", "")
25
+ key = send(name)
26
+ str += "#{name}: #{key}, "
27
+ end
28
+ str[0..str.length-3]
29
+ end
30
+
31
+ def to_json
32
+ {
33
+ "icao" => self.icao,
34
+ "iata" => self.iata,
35
+ "name" => self.name,
36
+ "location" => self.location,
37
+ "country" => self.country,
38
+ "country_code" => self.country_code,
39
+ "longitude" => self.longitude,
40
+ "latitude" => self.latitude
41
+ }.to_json
42
+ end
43
+
44
+ class << self
45
+
46
+ def parse_airport_iata(airport_name)
47
+ airport_name[/[(][a-zA-Z]*[)]/, 0].gsub(/[()]/, "").strip.to_s
48
+ end
49
+
50
+ def find(options={})
51
+ response = self.get("/ap_info.json", query: options)
52
+ if response["status"] == 200
53
+ new(response["icao"], response["iata"], response["name"], response["location"],
54
+ response["country"], response["country_code"], response["longitude"], response["latitude"])
55
+ else
56
+ raise responsse["error"]
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,25 @@
1
+ module JetBluePlaneTracker
2
+ class Arrival < Travel
3
+
4
+ def initialize(airport, scheduled_takeoff, actual_takeoff, terminal, gate, temperature)
5
+ super(airport, scheduled_takeoff, actual_takeoff, terminal, gate, temperature)
6
+ end
7
+
8
+ class << self
9
+
10
+ def parse(leg)
11
+ airport = leg['destination']
12
+ scheduled_takeoff = leg['scheduledArrival']
13
+ actual_takeoff = leg['actualArrival']
14
+ terminal = leg['destinationTerminal']
15
+ gate = leg['destinationGate']
16
+ temperature = leg['destinationTemperature']
17
+
18
+ new(airport, scheduled_takeoff, actual_takeoff, terminal, gate, temperature)
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,24 @@
1
+ module JetBluePlaneTracker
2
+ class Departure < Travel
3
+
4
+ def initialize(airport, scheduled_takeoff, actual_takeoff, terminal, gate, temperature)
5
+ super(airport, scheduled_takeoff, actual_takeoff, terminal, gate, temperature)
6
+ end
7
+
8
+ class << self
9
+
10
+ def parse(leg)
11
+ airport = leg['origin']
12
+ scheduled_takeoff = leg['scheduledDepart']
13
+ actual_takeoff = leg['actualDepart']
14
+ terminal = leg['originTerminal']
15
+ gate = leg['originGate']
16
+ temperature = leg['originTemperature']
17
+
18
+ new(airport, scheduled_takeoff, actual_takeoff, terminal, gate, temperature)
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,29 @@
1
+ module JetBluePlaneTracker
2
+ class Flight
3
+ attr_accessor :origin, :destination, :legs
4
+
5
+ def initialize(origin, destination, legs)
6
+ self.origin = Airport.find(iata: Airport.parse_airport_iata(origin))
7
+ self.destination = Airport.find(iata: Airport.parse_airport_iata(destination))
8
+ self.legs = legs
9
+ end
10
+
11
+ def to_s
12
+ "#{origin} -> #{destination}\n [#{legs}]"
13
+ end
14
+
15
+ def all_legs
16
+ self.legs.each{ |leg| leg.to_json }
17
+ end
18
+
19
+ def to_json
20
+ {
21
+ "origin" => self.origin.to_json,
22
+ "destination" => self.destination.to_json,
23
+ "legs" => self.legs.map{ |leg| leg.to_json }
24
+ }.to_json
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ module JetBluePlaneTracker
2
+ class Leg
3
+ attr_accessor :number, :date, :departure, :arrival, :status
4
+
5
+ def initialize(number, date, departure, arrival, status)
6
+ self.number = number
7
+ self.date = date
8
+ self.departure = departure
9
+ self.arrival = arrival
10
+ self.status = status
11
+ end
12
+
13
+ def to_s
14
+ "##{number}\n#{departure}\n#{arrival}\n#{status}"
15
+ end
16
+
17
+ def to_json
18
+ {
19
+ "number" => self.number,
20
+ "date" => self.date,
21
+ "departure" => self.departure.to_json,
22
+ "arrival" => self.arrival.to_json,
23
+ "status" => self.status
24
+ }.to_json
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,39 @@
1
+ module JetBluePlaneTracker
2
+
3
+ class Tracker
4
+ include HTTParty
5
+ base_uri "http://www.jetblue.com/flightstatus"
6
+
7
+ attr_accessor :params
8
+
9
+ def initialize(params={})
10
+ self.params = params
11
+ end
12
+
13
+ def flights
14
+ data = get_data
15
+ flight_date = self.params.has_key?("date") ? options[:date] : Date.today
16
+ flights = []
17
+ legs = []
18
+ data['flights'].each do |flight|
19
+ flight['legs'].each do |leg|
20
+ lg = Leg.new(leg["flightNo"], flight_date,
21
+ Departure.parse(leg), Arrival.parse(leg), leg['flightStatus'])
22
+ legs << lg
23
+ end
24
+ fl = Flight.new(flight["tripOrigin"], flight["tripDestination"], legs)
25
+ flights << fl
26
+ end
27
+ flights
28
+ end
29
+
30
+ alias_method :get_flights, :flights
31
+
32
+ private
33
+
34
+ def get_data
35
+ self.class.get("/FlightStatusData.aspx", query: self.params)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ module JetBluePlaneTracker
2
+ class Travel
3
+ attr_accessor :airport, :scheduled_takeoff, :actual_takeoff, :terminal, :gate, :temperature
4
+
5
+ def initialize(airport, scheduled_takeoff, actual_takeoff, terminal, gate, temperature)
6
+ super()
7
+ self.airport = Airport.find(iata: Airport.parse_airport_iata(airport))
8
+ self.scheduled_takeoff = scheduled_takeoff
9
+ self.actual_takeoff = actual_takeoff
10
+ self.terminal = terminal
11
+ self.gate = gate
12
+ self.temperature = temperature
13
+ end
14
+
15
+ def to_s
16
+ "#{type}-> Airport: #{airport.name} Scheduled Take-Off: #{scheduled_takeoff} - Actual Take-Off: #{actual_takeoff} [Terminal: #{terminal}, Gate: #{gate}, Temperature: #{temperature}]"
17
+ end
18
+
19
+
20
+ def to_json
21
+ {
22
+ "airport" => self.airport.to_json,
23
+ "scheduled_takeoff" => self.scheduled_takeoff,
24
+ "actual_takeoff" => self.actual_takeoff,
25
+ "terminal" => self.terminal,
26
+ "gate" => self.gate,
27
+ "temperature" => self.temperature
28
+ }.to_json
29
+ end
30
+
31
+ def type
32
+ self.class.name.sub!("JetBluePlaneTracker::", "")
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,3 @@
1
+ module JetBluePlaneTracker
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'json'
2
+ require 'httparty'
3
+ require File.expand_path('../jetblue_plane_tracker/airport', __FILE__)
4
+ require File.expand_path('../jetblue_plane_tracker/flight', __FILE__)
5
+ require File.expand_path('../jetblue_plane_tracker/leg', __FILE__)
6
+ require File.expand_path('../jetblue_plane_tracker/travel', __FILE__)
7
+ require File.expand_path('../jetblue_plane_tracker/departure', __FILE__)
8
+ require File.expand_path('../jetblue_plane_tracker/arrival', __FILE__)
9
+ require File.expand_path('../jetblue_plane_tracker/tracker', __FILE__)
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jetblue_plane_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Díaz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ description: A Ruby wrapper for JetBlue flights status API
42
+ email: brian@briandiaz.me
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - lib/jetblue_plane_tracker.rb
49
+ - lib/jetblue_plane_tracker/airport.rb
50
+ - lib/jetblue_plane_tracker/arrival.rb
51
+ - lib/jetblue_plane_tracker/departure.rb
52
+ - lib/jetblue_plane_tracker/flight.rb
53
+ - lib/jetblue_plane_tracker/leg.rb
54
+ - lib/jetblue_plane_tracker/tracker.rb
55
+ - lib/jetblue_plane_tracker/travel.rb
56
+ - lib/jetblue_plane_tracker/version.rb
57
+ - spec/spec_helper.rb
58
+ homepage: https://github.com/briandiaz/jetblue_plane_tracker
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.7
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: This wrapper retrieves data of any flight by JetBlue Airways Corporation
82
+ test_files:
83
+ - spec/spec_helper.rb