Skip to content

Commit 742c6ae

Browse files
committed
add start of web app
1 parent 735510c commit 742c6ae

File tree

11 files changed

+337
-0
lines changed

11 files changed

+337
-0
lines changed

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

Gemfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source "https://rubygems.org"
2+
3+
gem "sinatra", "~> 1.4"
4+
5+
group :test do
6+
gem "rspec", "~> 3.0"
7+
gem "rack-test", "~> 0.6"
8+
gem "webmock", "~> 1.24"
9+
end

Gemfile.lock

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
addressable (2.4.0)
5+
crack (0.4.3)
6+
safe_yaml (~> 1.0.0)
7+
diff-lcs (1.2.5)
8+
hashdiff (0.3.0)
9+
rack (1.6.4)
10+
rack-protection (1.5.3)
11+
rack
12+
rack-test (0.6.3)
13+
rack (>= 1.0)
14+
rspec (3.4.0)
15+
rspec-core (~> 3.4.0)
16+
rspec-expectations (~> 3.4.0)
17+
rspec-mocks (~> 3.4.0)
18+
rspec-core (3.4.3)
19+
rspec-support (~> 3.4.0)
20+
rspec-expectations (3.4.0)
21+
diff-lcs (>= 1.2.0, < 2.0)
22+
rspec-support (~> 3.4.0)
23+
rspec-mocks (3.4.1)
24+
diff-lcs (>= 1.2.0, < 2.0)
25+
rspec-support (~> 3.4.0)
26+
rspec-support (3.4.1)
27+
safe_yaml (1.0.4)
28+
sinatra (1.4.7)
29+
rack (~> 1.5)
30+
rack-protection (~> 1.4)
31+
tilt (>= 1.3, < 3)
32+
tilt (2.0.2)
33+
webmock (1.24.0)
34+
addressable (>= 2.3.6)
35+
crack (>= 0.3.2)
36+
hashdiff
37+
38+
PLATFORMS
39+
ruby
40+
41+
DEPENDENCIES
42+
rack-test (~> 0.6)
43+
rspec (~> 3.0)
44+
sinatra (~> 1.4)
45+
webmock (~> 1.24)
46+
47+
BUNDLED WITH
48+
1.11.2

config.ru

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require './lib/app'
2+
3+
run FlightSchool

lib/app.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'sinatra/base'
2+
3+
class FlightSchool < Sinatra::Base
4+
get '/' do
5+
'Hello world!'
6+
end
7+
end

lib/radar.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require "json"
2+
require "net/http"
3+
require "uri"
4+
5+
Status = Struct.new(:code, :name, :city, :weather)
6+
7+
class Radar
8+
class NoSuchAirport < RuntimeError; end
9+
10+
def self.status_for(airport)
11+
uri = URI.parse("http://services.faa.gov/airport/status/#{airport}")
12+
req = Net::HTTP::Get.new(uri)
13+
req["Accept"] = "application/json"
14+
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
15+
http.request(req)
16+
end
17+
18+
raise NoSuchAirport if res.code == "404"
19+
20+
decoded = JSON.parse(res.body)
21+
22+
Status.new(
23+
decoded.fetch("IATA"),
24+
decoded.fetch("name"),
25+
decoded.fetch("city"),
26+
decoded.fetch("weather").fetch("weather"),
27+
)
28+
end
29+
end

spec/fixtures/edi

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
HTTP/1.1 404 Not Found
2+
Date: Sat, 20 Feb 2016 00:12:29 GMT
3+
Server: Apache/2.2.15 (Red Hat)
4+
X-Frame-Options: SAMEORIGIN
5+
Set-Cookie: CFID=183569536; Expires=Mon, 12-Feb-2046 00:12:29 GMT; Path=/; HttpOnly
6+
Set-Cookie: CFTOKEN=facd4a2349b110af-D8349027-DB60-728A-54506A5886BA3B47; Expires=Mon, 12-Feb-2046 00:12:29 GMT; Path=/; HttpOnly
7+
Set-Cookie: JSESSIONID=A5E7DE786986FD1A8AE6D46DCE28B827.websvc; Path=/; HttpOnly
8+
Connection: close
9+
Transfer-Encoding: chunked
10+
Content-Type: text/html;charset=UTF-8
11+
Set-Cookie: BIGipServerpool_prd_chh_cf_tr_http=1875030683.20480.0000; path=/
12+
Vary: Accept-Encoding
13+
14+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
15+
<html lang="en">
16+
<head>
17+
<title>Missing File or Error</title>
18+
<link href="/template/style/main.css" rel="stylesheet" type="text/css">
19+
<link href="/template/style/syntaxHighlighter.css" rel="stylesheet" type="text/css">
20+
<!--[if IE 8]> <link href="/template/style/fixes.ie8.css" rel="stylesheet" type="text/css"><![endif]-->
21+
<!--[if LTE IE 7]><link href="/template/style/fixes.ie7.css" rel="stylesheet" type="text/css"><![endif]-->
22+
<!--[if LTE IE 6]><link href="/template/style/fixes.ie6.css" rel="stylesheet" type="text/css"><![endif]-->
23+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
24+
<meta name="description" content="FAA Web Services">
25+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
26+
<script src="/template/script/jquery.corner.js" type="text/javascript"></script>
27+
<script src="/template/script/shCore.js" type="text/javascript"></script>
28+
<script src="/template/script/shBrushXml.js" type="text/javascript"></script>
29+
<script src="/template/script/shBrushJava.js" type="text/javascript"></script>
30+
<script src="/template/script/shBrushCSharp.js" type="text/javascript"></script>
31+
<script src="/template/script/doc.js" type="text/javascript"></script>
32+
<script src="/template/script/load.js" type="text/javascript"></script>
33+
34+
</head>
35+
<body>
36+
<div id="skipLinks">
37+
<ul>
38+
<li><a href="#content">Skip to Page Content</a></li>
39+
<li><a href="#vNav">Skip to Sidebar Navigation</a></li>
40+
</ul>
41+
</div>
42+
<div id="widthControl">
43+
<div id="head">
44+
<div id="formSearchDocumentation">
45+
<form action="/search/" method="get" class="clear layout no-print">
46+
<div class="formRow">
47+
<label for="wfq">Search Documentation</label>
48+
<input type="text" class="ac_input" id="wfq" tabindex="1" alt="Search Criteria" name="q" size="27" value="Search Documentation">
49+
<input type="submit" class="primary button" value="Search" alt="Submit Search" tabindex="2">
50+
</div>
51+
</form>
52+
53+
<p><strong><a href="/signin/">FAA Developer Sign In</a></strong></p>
54+
55+
</div>
56+
<a id="logoLink" href="/">FAA Services Home</a>
57+
</div>
58+
<div id="vNav">
59+
<ul class="Sle S1">
60+
<li>
61+
<ul>
62+
<li><a href="/" >FAA Web Services</a></li>
63+
<li><a href="/docs/basics/" >API Basics</a></li>
64+
<li><a href="/docs/tutorial/" >Simple Tutorial</a></li>
65+
<li><a href="/docs/formats/" >Response Formats</a></li>
66+
<li><a href="/docs/http/" >HTTP Response Codes and Errors</a></li>
67+
<li><a href="/docs/faq/" >Frequently Asked Questions</a></li>
68+
<li><a href="/docs/services/" >Services Catalog</a></li>
69+
70+
71+
72+
</ul>
73+
</li>
74+
</ul>
75+
</div>
76+
<div id="bodyPadding" class="clear">
77+
<img src="/template/images/logo_for_print.gif" alt="Federal Aviation Administration" class="forPrint" width="179" height="64">
78+
<div class="whiteSheet">
79+
<div id="content" class="content">
80+
<h1 class="pageTitle">Missing File or Error</h1>
81+
82+
<p>Whoops! Either the page you requested could not be found or there was some other kind of error.</p>
83+
<p>If you were trying to consume a web service, please double check the URI you're using or consult the <a href="/docs/services/">service catalog</a>.</p>
84+
<p>If you believe something's wrong on our end, please <a href="/contact/?reason=Bug%20Report">let us know</a>.</p>
85+
86+
</div>
87+
</div>
88+
</div>
89+
<div id="footer">
90+
<div class="address">
91+
<p><a href="http://www.dot.gov/" title="Department of Transportation">U.S.&nbsp;Department&nbsp;of&nbsp;Transportation</a><br>
92+
Federal&nbsp;Aviation&nbsp;Administration<br>
93+
800&nbsp;Independence&nbsp;Avenue,&nbsp;SW<br>
94+
Washington,&nbsp;DC&nbsp;20591<br>
95+
1-866-TELL-FAA&nbsp;(1-866-835-5322)</p>
96+
</div>
97+
<div class="midSection divide">
98+
<p class="title">Websites</p>
99+
<ul>
100+
<li><a href="http://www.faa.gov/">FAA.gov</a></li>
101+
</ul>
102+
<p class="title">Web Policies</p>
103+
<ul>
104+
<li><a href="http://faa.gov/web_policies/">Web Policies &amp; Notices</a></li>
105+
<li><a href="http://faa.gov/privacy/">Privacy Policy</a></li>
106+
</ul>
107+
</div>
108+
<div class="midSection divide">
109+
<p class="title">Technical Resources</p>
110+
<ul id="technical-links">
111+
112+
<li><a href="/exit/?pageName=REST&amp;pageLink=http://en.wikipedia.org/wiki/Representational_State_Transfer" class="exiter">REST</a></li>
113+
<li><a href="/exit/?pageName=HTTP&amp;pageLink=http://www.w3.org/Protocols/rfc2616/rfc2616.html" class="exiter">HTTP</a></li>
114+
<li><a href="/exit/?pageName=XML&amp;pageLink=http://en.wikipedia.org/wiki/XML" class="exiter">XML</a></li>
115+
<li><a href="/exit/?pageName=JSON&amp;pageLink=http://json.org/" class="exiter">JSON</a></li>
116+
117+
</ul>
118+
</div>
119+
<div class="right divide">
120+
<p class="title">Contact Links</p>
121+
<ul>
122+
<li><a href="/contact/">Contact Us</a></li>
123+
</ul>
124+
</div>
125+
</div>
126+
<p class="forPrint">This page can be viewed online at: http://services.faa.gov/execute/</p>
127+
</div>
128+
129+
</body>
130+
</html>

spec/fixtures/jfk

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
HTTP/1.1 200 OK
2+
Date: Fri, 19 Feb 2016 23:47:30 GMT
3+
Server: Apache/2.2.15 (Red Hat)
4+
X-Frame-Options: SAMEORIGIN
5+
Set-Cookie: CFID=182906332; Expires=Sun, 11-Feb-2046 23:47:30 GMT; Path=/; HttpOnly
6+
Set-Cookie: CFTOKEN=f49d6bbee61af81d-D74FAEE6-AF68-AFE5-3A724977A5DC1881; Expires=Sun, 11-Feb-2046 23:47:30 GMT; Path=/; HttpOnly
7+
Set-Cookie: JSESSIONID=201F19C1D228624879FDB1C8FBE09C97.websvc; Path=/; HttpOnly
8+
Access-Control-Allow-Origin: *
9+
Access-Control-Allow-Methods: GET, HEAD, OPTIONS
10+
Version-Requested: Any
11+
Connection: close
12+
Transfer-Encoding: chunked
13+
Content-Type: application/json;charset=UTF-8
14+
Set-Cookie: BIGipServerpool_prd_chh_cf_tr_http=1958916763.20480.0000; path=/
15+
16+
{"delay":"false","IATA":"JFK","state":"New York","name":"John F Kennedy International","weather":{"visibility":10.00,"weather":"Overcast","meta":{"credit":"NOAA's National Weather Service","updated":"5:51 PM Local","url":"http://weather.gov/"},"temp":"36.0 F (2.2 C)","wind":"Southeast at 9.2mph"},"ICAO":"KJFK","city":"New York","status":{"reason":"No known delays for this airport.","closureBegin":"","endTime":"","minDelay":"","avgDelay":"","maxDelay":"","closureEnd":"","trend":"","type":""}}

spec/integration_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "rack/test"
2+
3+
ENV['RACK_ENV'] = 'test'
4+
5+
require "app"
6+
7+
RSpec.describe "The FlightSchool application" do
8+
include Rack::Test::Methods
9+
10+
def app
11+
FlightSchool
12+
end
13+
14+
it "says hello" do
15+
get "/"
16+
expect(last_response).to be_ok
17+
expect(last_response.body).to eq("Hello world!")
18+
end
19+
end

spec/radar_spec.rb

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require "webmock/rspec"
2+
3+
require "radar"
4+
5+
RSpec.describe Radar, ".status_for" do
6+
context "when the airport can be found" do
7+
before do
8+
stub_request(:get, "http://services.faa.gov/airport/status/JFK").
9+
with(:headers => {"Accept" => "application/json"}).
10+
to_return(File.new(fixture("jfk")))
11+
end
12+
13+
subject(:status) do
14+
Radar.status_for("JFK")
15+
end
16+
17+
it "has a IATA code" do
18+
expect(status.code).to eq("JFK")
19+
end
20+
21+
it "has a name" do
22+
expect(status.name).to eq("John F Kennedy International")
23+
end
24+
25+
it "has a city" do
26+
expect(status.city).to eq("New York")
27+
end
28+
29+
it "has weather" do
30+
expect(status.weather).to eq("Overcast")
31+
end
32+
end
33+
34+
context "when the airport cannot be found" do
35+
before do
36+
stub_request(:get, "http://services.faa.gov/airport/status/EDI").
37+
with(:headers => {"Accept" => "application/json"}).
38+
to_return(File.new(fixture("edi")))
39+
end
40+
41+
it "raises an exception" do
42+
expect {
43+
Radar.status_for("EDI")
44+
}.to raise_error Radar::NoSuchAirport
45+
end
46+
end
47+
end

spec/spec_helper.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
RSpec.configure do |config|
2+
config.expect_with :rspec do |expectations|
3+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4+
end
5+
6+
config.mock_with :rspec do |mocks|
7+
mocks.verify_partial_doubles = true
8+
end
9+
10+
config.filter_run :focus
11+
config.run_all_when_everything_filtered = true
12+
13+
config.example_status_persistence_file_path = "spec/examples.txt"
14+
config.disable_monkey_patching!
15+
config.warnings = true
16+
17+
if config.files_to_run.one?
18+
config.default_formatter = 'doc'
19+
end
20+
21+
config.order = :random
22+
Kernel.srand config.seed
23+
end
24+
25+
def fixture(name)
26+
File.join(File.dirname(__FILE__), "fixtures", name)
27+
end

0 commit comments

Comments
 (0)