fcc_reboot 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE.md +10 -0
- data/README.mkd +87 -0
- data/Rakefile +16 -0
- data/fcc_ruby_gem.gemspec +38 -0
- data/lib/fcc_reboot.rb +47 -0
- data/lib/fcc_reboot/client.rb +20 -0
- data/lib/fcc_reboot/client/api.rb +233 -0
- data/lib/fcc_reboot/client/connection.rb +37 -0
- data/lib/fcc_reboot/client/request.rb +40 -0
- data/lib/fcc_reboot/configuration.rb +44 -0
- data/lib/fcc_reboot/version.rb +3 -0
- data/spec/api.rb +294 -0
- data/spec/fixtures/broadband_test.json +1 -0
- data/spec/fixtures/census-block-conversions-api.json +7 -0
- data/spec/fixtures/frn-conversions-getinfo.json +13 -0
- data/spec/fixtures/frn-conversions-getlist.json +13 -0
- data/spec/fixtures/get_entities.json +1 -0
- data/spec/fixtures/get_issued.json +1 -0
- data/spec/fixtures/get_licenses.json +1 -0
- data/spec/fixtures/get_renewals.json +1 -0
- data/spec/fixtures/get_spectrum_bands.json +1 -0
- data/spec/fixtures/license-view-get-categories.json +1 -0
- data/spec/fixtures/license-view-get-common-names.json +1 -0
- data/spec/fixtures/license-view-get-licenses.json +1 -0
- data/spec/fixtures/license-view-get-statuses.json +1 -0
- data/spec/frn_conversions_spec.rb +0 -0
- data/spec/helper.rb +19 -0
- metadata +255 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday/response/raise_error'
|
3
|
+
|
4
|
+
module FccReboot
|
5
|
+
class Client
|
6
|
+
# @private
|
7
|
+
module Connection
|
8
|
+
private
|
9
|
+
|
10
|
+
def connection(raw=false)
|
11
|
+
options = {
|
12
|
+
#:headers => {'Accept' => "*/#{format}", 'User-Agent' => user_agent},
|
13
|
+
:headers => {'Accept' => 'application/json'},
|
14
|
+
:proxy => proxy,
|
15
|
+
:ssl => {:verify => false},
|
16
|
+
:url => 'http://data.fcc.gov/api/' + endpoint.to_s
|
17
|
+
}
|
18
|
+
|
19
|
+
Faraday::Connection.new(options) do |connection|
|
20
|
+
connection.use Faraday::Request::Multipart
|
21
|
+
unless raw
|
22
|
+
connection.use Faraday::Response::Mashify
|
23
|
+
case format.to_s.downcase
|
24
|
+
when 'json'
|
25
|
+
connection.use Faraday::Response::ParseJson
|
26
|
+
when 'xml'
|
27
|
+
connection.use Faraday::Response::ParseXml
|
28
|
+
end
|
29
|
+
end
|
30
|
+
connection.use Faraday::Response::RaiseError
|
31
|
+
connection.adapter(adapter)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module FccReboot
|
2
|
+
class Client
|
3
|
+
module Request
|
4
|
+
def get(path, options={}, raw=false)
|
5
|
+
request(:get, path, options, raw)
|
6
|
+
end
|
7
|
+
|
8
|
+
def post(path, options={}, raw=false)
|
9
|
+
request(:post, path, options, raw)
|
10
|
+
end
|
11
|
+
|
12
|
+
def put(path, options={}, raw=false)
|
13
|
+
request(:put, path, options, raw)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(path, options={}, raw=false)
|
17
|
+
request(:delete, path, options, raw)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def request(method, path, options, raw)
|
23
|
+
response = connection(raw).send(method) do |request|
|
24
|
+
case method
|
25
|
+
when :get, :delete
|
26
|
+
request.url(formatted_path(path), options)
|
27
|
+
when :post, :put
|
28
|
+
request.path = formatted_path(path)
|
29
|
+
request.body = options unless options.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
raw ? response : response.body
|
33
|
+
end
|
34
|
+
|
35
|
+
def formatted_path(path)
|
36
|
+
[path, format].compact.join('.')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module FccReboot
|
4
|
+
module Configuration
|
5
|
+
VALID_OPTIONS_KEYS = [
|
6
|
+
:adapter,
|
7
|
+
:endpoint,
|
8
|
+
:user_agent,
|
9
|
+
:proxy,
|
10
|
+
:format].freeze
|
11
|
+
|
12
|
+
VALID_FORMATS = [
|
13
|
+
:json,
|
14
|
+
:xml].freeze
|
15
|
+
|
16
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
17
|
+
DEFAULT_ENDPOINT = nil
|
18
|
+
DEFAULT_PROXY = nil
|
19
|
+
DEFAULT_FORMAT = nil
|
20
|
+
DEFAULT_USER_AGENT = "FccReboot Ruby Gem #{FccReboot::VERSION}".freeze
|
21
|
+
|
22
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
23
|
+
|
24
|
+
def self.extended(base)
|
25
|
+
base.reset
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure
|
29
|
+
yield self
|
30
|
+
end
|
31
|
+
|
32
|
+
def options
|
33
|
+
VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def reset
|
37
|
+
self.adapter = DEFAULT_ADAPTER
|
38
|
+
self.user_agent = DEFAULT_USER_AGENT
|
39
|
+
self.endpoint = DEFAULT_ENDPOINT
|
40
|
+
self.format = DEFAULT_FORMAT
|
41
|
+
self.proxy = DEFAULT_FORMAT
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/api.rb
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe FccReboot, ".broadband_test" do
|
4
|
+
before do
|
5
|
+
stub_request(:get, 'http://data.fcc.gov/api/speedtest/find').
|
6
|
+
with(:query => {:format => 'json', :latitude => '38.0', :longitude => '-77.5'}).
|
7
|
+
to_return(:body => fixture('broadband_test.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should request the correct resource" do
|
11
|
+
FccReboot.broadband_test({:latitude => '38.0', :longitude => '-77.5'})
|
12
|
+
a_request(:get, 'http://data.fcc.gov/api/speedtest/find').
|
13
|
+
with(:query => {:format => 'json', :latitude => '38.0', :longitude => '-77.5'}).
|
14
|
+
should have_been_made
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return the correct results" do
|
18
|
+
test = FccReboot.broadband_test({:latitude => '38.0', :longitude => '-77.5'})
|
19
|
+
puts test.inspect
|
20
|
+
test.should be_an Hash
|
21
|
+
test["wirelineMaxDownload"].should == 17773.0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe FccReboot, ".census_block" do
|
26
|
+
before do
|
27
|
+
stub_request(:get, 'http://data.fcc.gov/api/block/find').
|
28
|
+
with(:query => {:format => 'json', :latitude => '38.0', :longitude => '-77.5'}).
|
29
|
+
to_return(:body => fixture('census-block-conversions-api.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should request the correct resource" do
|
33
|
+
FccReboot.find_census_block(:latitude => '38.0', :longitude => '-77.5')
|
34
|
+
a_request(:get, 'http://data.fcc.gov/api/block/find').
|
35
|
+
with(:query => {:format => 'json', :latitude => '38.0', :longitude => '-77.5'}).
|
36
|
+
should have_been_made
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return the correct results" do
|
40
|
+
services = FccReboot.find_census_block(:latitude => '38.0', :longitude => '-77.5')
|
41
|
+
services.should be_a Hash
|
42
|
+
services["Block"]["FIPS"].should == '510339905003000'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe FccReboot, ".frn_getlist" do
|
47
|
+
before do
|
48
|
+
stub_request(:get, 'http://data.fcc.gov/api/frn/getList').
|
49
|
+
with(:query => {:format => 'json', :stateCode => 'IL', :multi => 'Yes'}).
|
50
|
+
to_return(:body => fixture('frn-conversions-getlist.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
51
|
+
stub_request(:get, 'http://data.fcc.gov/api/frn/getList').
|
52
|
+
with(:query => {:format => 'json', :stateCode => 'IL', :multi => 'No'}).
|
53
|
+
to_return(:body => fixture('frn-conversions-getlist.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should request the correct resource" do
|
57
|
+
FccReboot.frn_getlist(:stateCode => 'IL', :multi => true)
|
58
|
+
a_request(:get, 'http://data.fcc.gov/api/frn/getList').
|
59
|
+
with(:query => {:format => 'json', :stateCode => 'IL', :multi => 'Yes'}).
|
60
|
+
should have_been_made
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should request the correct resource" do
|
64
|
+
FccReboot.frn_getlist(:stateCode => 'IL', :multi => false)
|
65
|
+
a_request(:get, 'http://data.fcc.gov/api/frn/getList').
|
66
|
+
with(:query => {:format => 'json', :stateCode => 'IL', :multi => 'No'}).
|
67
|
+
should have_been_made
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return the correct results" do
|
71
|
+
services = FccReboot.frn_getlist(:stateCode => 'IL', :multi => false)
|
72
|
+
services.should be_a Hash
|
73
|
+
services["Frns"]["Frn"].first["frn"].should == '0017855545'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe FccReboot, ".frn_getinfo" do
|
78
|
+
before do
|
79
|
+
stub_request(:get, 'http://data.fcc.gov/api/frn/getInfo').
|
80
|
+
with(:query => {:format => 'json', :frn => '0017855545'}).
|
81
|
+
to_return(:body => fixture('frn-conversions-getinfo.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should request the correct resource" do
|
85
|
+
FccReboot.frn_getinfo(:frn => '0017855545')
|
86
|
+
a_request(:get, 'http://data.fcc.gov/api/frn/getInfo').
|
87
|
+
with(:query => {:format => 'json', :frn => '0017855545'}).
|
88
|
+
should have_been_made
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return the correct results" do
|
92
|
+
services = FccReboot.frn_getinfo(:frn => '0017855545')
|
93
|
+
services.should be_a Hash
|
94
|
+
services["Info"]["frn"].should == '0017855545'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe FccReboot, ".get_spectrum_bands" do
|
99
|
+
before do
|
100
|
+
stub_request(:get, 'http://data.fcc.gov/api/spectrum-view/services/advancedSearch/getSpectrumBands').
|
101
|
+
with(:query => {:format => 'json', :frequencyFrom=>'226', :frequencyTo => '900'}).
|
102
|
+
to_return(:body => fixture('get_spectrum_bands.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should request the correct resource" do
|
106
|
+
FccReboot.get_spectrum_bands(:frequencyFrom=>'226', :frequencyTo => '900')
|
107
|
+
a_request(:get, 'http://data.fcc.gov/api/spectrum-view/services/advancedSearch/getSpectrumBands').
|
108
|
+
with(:query => {:format => 'json', :frequencyFrom=>'226', :frequencyTo => '900'}).
|
109
|
+
should have_been_made
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return the correct results" do
|
113
|
+
services = FccReboot.get_spectrum_bands(:frequencyFrom=>'226', :frequencyTo => '900')
|
114
|
+
services.should be_a Array
|
115
|
+
services[0]["upperBand"].should == "235"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe FccReboot, ".get_spectrum_licenses" do
|
120
|
+
before do
|
121
|
+
stub_request(:get, 'http://data.fcc.gov/api/spectrum-view/services/advancedSearch/getLicenses').
|
122
|
+
with(:query => {:format => 'json', :name=> 'AT', :radioservice=>'Cellular'}).
|
123
|
+
to_return(:body => fixture('get_licenses.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should request the correct resource" do
|
127
|
+
FccReboot.get_spectrum_licenses(:name=> 'AT', :radioservice=>'Cellular')
|
128
|
+
a_request(:get, 'http://data.fcc.gov/api/spectrum-view/services/advancedSearch/getLicenses').
|
129
|
+
with(:query => {:format => 'json', :name=> 'AT', :radioservice=>'Cellular'}).
|
130
|
+
should have_been_made
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should return the correct results" do
|
134
|
+
services = FccReboot.get_spectrum_licenses(:name=> 'AT', :radioservice=>'Cellular')
|
135
|
+
services.should be_a Array
|
136
|
+
services[0]["id"].should == "11538"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe FccReboot, ".get_licenses" do
|
141
|
+
before do
|
142
|
+
@query = {:searchValue => 'Verizon%20Wireless', :format =>'json'}
|
143
|
+
stub_request(:get, 'http://data.fcc.gov/api/license-view/basicSearch/getLicenses').
|
144
|
+
with(:query => @query).
|
145
|
+
to_return(:body => fixture('license-view-get-licenses.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should request the correct resource" do
|
149
|
+
FccReboot.get_licenses(@query)
|
150
|
+
a_request(:get, 'http://data.fcc.gov/api/license-view/basicSearch/getLicenses').
|
151
|
+
with(:query => @query).
|
152
|
+
should have_been_made
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should return the correct results" do
|
156
|
+
licenses = FccReboot.get_licenses(@query)
|
157
|
+
licenses.should be_a Array
|
158
|
+
licenses[0]["licenseID"].should == '2300007967'
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe FccReboot, ".get_common_names" do
|
163
|
+
before do
|
164
|
+
@query = {:commonName => 'Sprint%20Nextel', :limit => '10'}
|
165
|
+
@url = 'http://data.fcc.gov/api/license-view/licenses/getCommonNames'
|
166
|
+
stub_request(:get, @url).
|
167
|
+
with(:query => @query).
|
168
|
+
to_return(:body => fixture('license-view-get-common-names.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should request the correct resource" do
|
172
|
+
FccReboot.get_common_names(@query)
|
173
|
+
a_request(:get, @url).
|
174
|
+
with(:query => @query).
|
175
|
+
should have_been_made
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should return the correct results" do
|
179
|
+
common_names = FccReboot.get_common_names(@query)
|
180
|
+
common_names.should be_a Array
|
181
|
+
common_names[0]["statCount"].should == '11989'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe FccReboot, ".get_statuses" do
|
186
|
+
before do
|
187
|
+
@query = {:commonName => 'Sprint%20Nextel', :limit => '10'}
|
188
|
+
@url = 'http://data.fcc.gov/api/license-view/licenses/getStatuses'
|
189
|
+
stub_request(:get, @url).
|
190
|
+
with(:query => @query).
|
191
|
+
to_return(:body => fixture('license-view-get-statuses.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should request the correct resource" do
|
195
|
+
FccReboot.get_statuses(@query)
|
196
|
+
a_request(:get, @url).
|
197
|
+
with(:query => @query).
|
198
|
+
should have_been_made
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should return the correct results" do
|
202
|
+
statuses = FccReboot.get_statuses(@query)
|
203
|
+
statuses.should be_a Array
|
204
|
+
statuses[0]["statCount"].should == '43980'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe FccReboot, ".get_issued" do
|
209
|
+
before do
|
210
|
+
@query = {:commonName => 'Sprint%Nextel', :format => 'json'}
|
211
|
+
stub_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getIssued').
|
212
|
+
with(:query => @query).
|
213
|
+
to_return(:body => fixture('get_issued.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should request the correct resource" do
|
217
|
+
FccReboot.get_issued(@query)
|
218
|
+
a_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getIssued').
|
219
|
+
with(:query => @query).
|
220
|
+
should have_been_made
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should return the correct results" do
|
224
|
+
licenses = FccReboot.get_issued(@query)
|
225
|
+
licenses.should be_a Array
|
226
|
+
licenses[0]["statDesc"].should == '2001'
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
describe FccReboot, ".get_renewals" do
|
231
|
+
before do
|
232
|
+
@query = {:commonName => 'Sprint%Nextel', :format => 'json'}
|
233
|
+
stub_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getRenewals').
|
234
|
+
with(:query => @query).
|
235
|
+
to_return(:body => fixture('get_renewals.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should request the correct resource" do
|
239
|
+
FccReboot.get_renewals(@query)
|
240
|
+
a_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getRenewals').
|
241
|
+
with(:query => @query).
|
242
|
+
should have_been_made
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should return the correct results" do
|
246
|
+
licenses = FccReboot.get_renewals(@query)
|
247
|
+
licenses.should be_a Array
|
248
|
+
licenses[0]["statDesc"].should == '201104'
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe FccReboot, ".get_entities" do
|
253
|
+
before do
|
254
|
+
@query = {:commonName => 'Sprint%Nextel', :format => 'json'}
|
255
|
+
stub_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getEntities').
|
256
|
+
with(:query => @query).
|
257
|
+
to_return(:body => fixture('get_entities.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should request the correct resource" do
|
261
|
+
FccReboot.get_entities(@query)
|
262
|
+
a_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getEntities').
|
263
|
+
with(:query => @query).
|
264
|
+
should have_been_made
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should return the correct results" do
|
268
|
+
licenses = FccReboot.get_entities(@query)
|
269
|
+
licenses.should be_a Array
|
270
|
+
licenses[0]["statDesc"].should == 'Individual'
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe FccReboot, ".get_categories" do
|
275
|
+
before do
|
276
|
+
@query = {:commonName => 'Sprint%Nextel', :limit=>"10", :format => 'json'}
|
277
|
+
stub_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getCategories').
|
278
|
+
with(:query => @query).
|
279
|
+
to_return(:body => fixture('get_entities.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should request the correct resource" do
|
283
|
+
FccReboot.get_categories(@query)
|
284
|
+
a_request(:get, 'http://data.fcc.gov/api/license-view/licenses/getCategories').
|
285
|
+
with(:query => @query).
|
286
|
+
should have_been_made
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should return the correct results" do
|
290
|
+
licenses = FccReboot.get_categories(@query)
|
291
|
+
licenses.should be_a Array
|
292
|
+
licenses[0]["statDesc"].should == 'Individual'
|
293
|
+
end
|
294
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"SpeedTestCounty":{"wirelineMaxDownload":17773.0,"wirelineMaxUpload":18680.0,"wirelineAvgDownload":9072.4,"wirelineAvgUpload":4562.2,"wirelessMaxDownload":14490.0,"wirelessMaxUpload":11180.0,"wirelessAvgDownload":9146.5,"wirelessAvgUpload":6498.5,"wirelineTests":66,"wirelessTests":21},"status":"OK","executionTime":"0.156"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"@executionTime": "0.014",
|
3
|
+
"@status": "OK",
|
4
|
+
"Info": {
|
5
|
+
"frn": "0017855545",
|
6
|
+
"companyName": "Cygnus Telecommunications Corporation",
|
7
|
+
"holdingCompanyName": "Cygnus Telecommunications Corporation",
|
8
|
+
"regulationStatus": "N",
|
9
|
+
"States": {"state": "IL"},
|
10
|
+
"TechnologyDescs": null,
|
11
|
+
"modifyDate": "2010.07.30 15:23:02"
|
12
|
+
}
|
13
|
+
}
|