fcc_reboot 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gem_template.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2011, Code for America
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ * Neither the name of Code for America nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.mkd ADDED
@@ -0,0 +1,87 @@
1
+ FCC Reboot
2
+ =======
3
+ A Ruby wrapper for the FCC Reboot APIs.
4
+
5
+ Does your project or organization use this gem?
6
+ ------------------------------------------
7
+ Add it to the [apps](http://github.com/cfalabs/fcc_reboot/wiki/apps) wiki!
8
+
9
+ Installation
10
+ ------------
11
+ $ [sudo] gem install fcc_reboot
12
+
13
+ Usage Examples
14
+ --------------
15
+ require 'fcc_reboot'
16
+
17
+ # Provide speed test statistics for a US County given the passed Latitude and Longitude
18
+ FccReboot.broadband_test(:latitude => '38.0', :longitude => '-77.5')
19
+
20
+ # Returns a list of the frequency bands
21
+ FccReboot.get_spectrum_bands(:frequencyFrom=>'226', :frequencyTo => '900')
22
+
23
+ # Provide high level overview of who owns spectrum across the country within the 225 MHz to 3700 MHz frequency
24
+ FccReboot.get_spectrum_licenses(:name=> 'AT', :radioservice=>'Cellular')
25
+
26
+ # Provide census block info for the given latitude and longitude
27
+ FccReboot.find_census_block(:latitude => '38.0', :longitude => '-77.5')
28
+
29
+ # Provide FRN list for the state of Illinois
30
+ FccReboot.frn_getlist(:stateCode => 'IL', :multi => 'No')
31
+
32
+ # Provide FRN info for Cygnus Telecommunications Corporation (FRN number 0017855545)
33
+ FccReboot.find_census_block(:frn => '0017855545')
34
+
35
+ # Returns the number of licenses up for renewal in a given month for Sprint Nextel.
36
+ FccReboot.get_issued(:commonName=> 'Sprint Nextel')
37
+
38
+ # Returns the counts and percent distribution of active licenses by entity type
39
+ FccReboot.get_renewals()
40
+
41
+ # Provide number of licenses that were issued by the Commission on a yearly basis
42
+ FccReboot.get_licenses(:searchValue => 'Verizon Wireless')
43
+
44
+ # Returns the license counts and percent distribution by status.
45
+ FccReboot.get_statuses(:commonName => 'Sprint Nextel')
46
+
47
+ Contributing
48
+ ------------
49
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
50
+
51
+ Here are some ways *you* can contribute:
52
+
53
+ * by using alpha, beta, and prerelease versions
54
+ * by reporting bugs
55
+ * by suggesting new features
56
+ * by writing or editing documentation
57
+ * by writing specifications
58
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
59
+ * by refactoring code
60
+ * by resolving [issues](http://github.com/cfalabs/fcc_reboot/issues)
61
+ * by reviewing patches
62
+
63
+ Submitting an Issue
64
+ -------------------
65
+ We use the [GitHub issue tracker](http://github.com/cfalabs/fcc_reboot/issues) to track bugs and
66
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
67
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
68
+ bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
69
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
70
+ operating system. Ideally, a bug report should include a pull request with failing specs.
71
+
72
+ Submitting a Pull Request
73
+ -------------------------
74
+ 1. Fork the project.
75
+ 2. Create a topic branch.
76
+ 3. Implement your feature or bug fix.
77
+ 4. Add documentation for your feature or bug fix.
78
+ 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
79
+ 6. Add specs for your feature or bug fix.
80
+ 7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
81
+ 8. Commit and push your changes.
82
+ 9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
83
+
84
+ Copyright
85
+ ---------
86
+ Copyright (c) 2010 Code for America Laboratories
87
+ See [LICENSE](https://github.com/cfalabs/fcc_reboot/blob/master/LICENSE.mkd) for details.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+ task :test => :spec
9
+
10
+ require 'yard'
11
+ namespace :doc do
12
+ YARD::Rake::YardocTask.new do |task|
13
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
14
+ task.options = ['--markup', 'markdown']
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fcc_reboot/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fcc_reboot"
7
+ s.version = FccReboot::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Dan Melton", "Javier"]
10
+ s.email = "info@codeforamerica.org"
11
+ s.homepage = ""
12
+ s.summary = %q{FCC API Wrapper}
13
+ s.description = %q{Wrapper for FCC API}
14
+
15
+ s.rubyforge_project = "fcc_reboot"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency('ZenTest', '~> 4.5')
23
+ s.add_development_dependency('maruku', '~> 0.6')
24
+ s.add_development_dependency('rake', '~> 0.8')
25
+ s.add_development_dependency('rspec', '~> 2.5')
26
+ s.add_development_dependency('simplecov', '~> 0.4')
27
+ s.add_development_dependency('yard', '~> 0.6')
28
+ s.add_development_dependency('nokogiri', '~> 1.4')
29
+ s.add_development_dependency('webmock', '~> 1.5')
30
+
31
+ s.add_runtime_dependency('hashie', '~> 1.0.0')
32
+ s.add_runtime_dependency('faraday', '~> 0.6.0')
33
+ s.add_runtime_dependency('faraday_middleware', '~> 0.6.0')
34
+ s.add_runtime_dependency('multi_json', '~> 0.0.5')
35
+ s.add_runtime_dependency('multi_xml', '~> 0.2.0')
36
+
37
+ s.add_dependency('json', '~>1.5.1')
38
+ end
data/lib/fcc_reboot.rb ADDED
@@ -0,0 +1,47 @@
1
+ require ::File.expand_path('../fcc_reboot/version', __FILE__)
2
+ require ::File.expand_path('../fcc_reboot/configuration.rb', __FILE__)
3
+ require ::File.expand_path('../fcc_reboot/client', __FILE__)
4
+
5
+ module FccReboot
6
+ extend Configuration
7
+
8
+ # Alias for FccReboot::Client.new
9
+ #
10
+ # @return [FccReboot::Client]
11
+ def self.client(options={})
12
+ FccReboot::Client.new(options)
13
+ end
14
+
15
+ # Delegate to FccReboot::Client
16
+ def self.method_missing(method, *args, &block)
17
+ return super unless client.respond_to?(method)
18
+ client.send(method, *args, &block)
19
+ end
20
+
21
+ # Custom error class for rescuing from all FccReboot errors
22
+ class Error < StandardError; end
23
+
24
+ # Raised when FccReboot returns a 400 HTTP status code
25
+ class BadRequest < Error; end
26
+
27
+ # Raised when FccReboot returns a 401 HTTP status code
28
+ class Unauthorized < Error; end
29
+
30
+ # Raised when FccReboot returns a 403 HTTP status code
31
+ class Forbidden < Error; end
32
+
33
+ # Raised when FccReboot returns a 404 HTTP status code
34
+ class NotFound < Error; end
35
+
36
+ # Raised when FccReboot returns a 406 HTTP status code
37
+ class NotAcceptable < Error; end
38
+
39
+ # Raised when FccReboot returns a 500 HTTP status code
40
+ class InternalServerError < Error; end
41
+
42
+ # Raised when FccReboot returns a 502 HTTP status code
43
+ class BadGateway < Error; end
44
+
45
+ # Raised when FccReboot returns a 503 HTTP status code
46
+ class ServiceUnavailable < Error; end
47
+ end
@@ -0,0 +1,20 @@
1
+ require ::File.expand_path('../client/connection', __FILE__)
2
+ require ::File.expand_path('../client/request', __FILE__)
3
+ require ::File.expand_path('../client/api.rb', __FILE__)
4
+
5
+ module FccReboot
6
+ class Client
7
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+
9
+ def initialize(options={})
10
+ options = FccReboot.options.merge(options)
11
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
12
+ send("#{key}=", options[key])
13
+ end
14
+ end
15
+
16
+ include FccReboot::Client::Connection
17
+ include FccReboot::Client::Request
18
+ include FccReboot::Client::Api
19
+ end
20
+ end
@@ -0,0 +1,233 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'JSON'
3
+
4
+ module FccReboot
5
+ class Client
6
+ module Api
7
+ # speed test statistics for a US County given the passed Latitude and Longitude
8
+ #
9
+ # @format :json
10
+ # @key false
11
+ # @param options [Hash] A customizable set of options.
12
+ # @return [Array]
13
+ # @see http://reboot.fcc.gov/developer/consumer-broadband-test-api
14
+ # @example Provide speed test statistics for a US County given the passed Latitude and Longitude
15
+ # FccReboot.broadband_test(:latitude => '38.0', :longitude => '-77.5')
16
+ def broadband_test(options={})
17
+ options.merge!({:format => "json"})
18
+ response = get('speedtest/find', options)
19
+ JSON.parse(response)["SpeedTestCounty"]
20
+ end
21
+
22
+ # This API returns the US Census Bureau Census Block number (aka the 15 character FIPS Code) given
23
+ # a passed Latitude and Longitude. The API also returns the US State and County name associated with
24
+ # the Block.
25
+ #
26
+ # @format :json
27
+ # @key false
28
+ # @param options [Hash] A customizable set of options.
29
+ # @return [Hash]
30
+ # @see http://reboot.fcc.gov/developer/census-block-conversions-api
31
+ # @example Provide census block info for the given latitude and longitude
32
+ # FccReboot.find_census_block({:latitude => '38.0', :longitude => '-77.5'})
33
+ def find_census_block(options={})
34
+ options.merge!({:format => "json"})
35
+ response = get('block/find', options)
36
+ JSON.parse(response)
37
+ end
38
+
39
+ # This API returns returns all the broadband providers in a given state, where those operators
40
+ # or do not operate in multiple states.
41
+ #
42
+ # @format :json
43
+ # @key false
44
+ # @param options [Hash] A customizable set of options.
45
+ # @return [Hash]
46
+ # @see http://reboot.fcc.gov/developer/frn-conversions-api
47
+ # @example Provide FRN list for the state of Illinois
48
+ # FccReboot.frn_getlist({:stateCode => 'IL', :multi => 'No'})
49
+ def frn_getlist(options={})
50
+ options[:multi] = options[:multi] ? "Yes" : "No"
51
+ options.merge!({:format => "json"})
52
+ response = get('frn/getList', options)
53
+ JSON.parse(response)
54
+ end
55
+
56
+ # This API returns information about a provider by FRN number.
57
+ #
58
+ # @format :json
59
+ # @key false
60
+ # @param options [Hash] A customizable set of options.
61
+ # @return [Hash]
62
+ # @see http://reboot.fcc.gov/developer/frn-conversions-api
63
+ # @example Provide FRN info for Cygnus Telecommunications Corporation (FRN number 0017855545)
64
+ # FccReboot.frn_getinfo(:frn => '0017855545')
65
+ def frn_getinfo(options={})
66
+ options.merge!({:format => "json"})
67
+ response = get('frn/getInfo', options)
68
+ JSON.parse(response)
69
+ end
70
+
71
+ # This API accepts a frequency range and returns a list of the frequency bands
72
+ # along with a high level description of how the band is allocated and for what uses within the 225 MHz and 3700 MHz frequency range.
73
+ # @format :json
74
+ # @key false
75
+ # @param options [Hash] A customizable set of options:
76
+ # frequencyFrom (Optional) – If a frequency range is not provided then the API will return all spectrum bands falling within the 225 to 3700 MHz range. Both a lower and upper frequency value must be provided when entering search criteria.
77
+ # frequencyTo (Optional) – If a frequency range is not provided then the API will return all spectrum bands falling within the 225 to 3700 MHz range. Both a lower and upper frequency value must be provided when entering search criteria.
78
+ # pageNum (Optional) – Default is 1.
79
+ # sortColumn (Optional) – Default is lowerBand. Valid values are: lowerBand, upperBand, or desc.
80
+ # sortOrder (Optional) – Default is asc. Valid values are: asc, desc.
81
+ # pageSize (Optional) – Default value is 1000.
82
+ # limit (Optional) – Default value is 100.
83
+ # format (Optional) – Default value is xml. Valid values are: xml, json, jsonp
84
+ # jsonCallback (Optional) – Default value is callback.
85
+ # @return [Array]
86
+ # @see http://reboot.fcc.gov/developer/spectrum-dashboard-api
87
+ # @example Returns a list of the frequency bands
88
+ # FccReboot.get_spectrum_bands(:frequencyFrom=>'226', :frequencyTo => '900')
89
+ def get_spectrum_bands(options={})
90
+ options.merge!({:format => "json"})
91
+ response = get('spectrum-view/services/advancedSearch/getSpectrumBands', options)
92
+ JSON.parse(response)["SpectrumBands"]["SpectrumBand"]
93
+ end
94
+
95
+ # This API returns a high level overview of who owns spectrum across the country
96
+ # within the 225 MHz to 3700 MHz frequency range in radio services deemed appropriate for
97
+ # mobile broadband use.
98
+ # @format :json
99
+ # @key false
100
+ # @param options [Hash] A customizable set of options:
101
+ # frequencyFrom (Optional) – If a frequency range is not provided then the API will return all spectrum bands falling within the 225 to 3700 MHz range. Both a lower and upper frequency value must be provided when entering search criteria.
102
+ # frequencyTo (Optional) – If a frequency range is not provided then the API will return all spectrum bands falling within the 225 to 3700 MHz range. Both a lower and upper frequency value must be provided when entering search criteria.
103
+ # pageNum (Optional) – Default is 1.
104
+ # sortColumn (Optional) – Default is lowerBand. Valid values are: lowerBand, upperBand, or desc.
105
+ # sortOrder (Optional) – Default is asc. Valid values are: asc, desc.
106
+ # pageSize (Optional) – Default value is 1000.
107
+ # limit (Optional) – Default value is 100.
108
+ # format (Optional) – Default value is xml. Valid values are: xml, json, jsonp
109
+ # @return [Array]
110
+ # @see http://reboot.fcc.gov/developer/spectrum-dashboard-api
111
+ # @example Provide high level overview of who owns spectrum across the country within the 225 MHz to 3700 MHz frequency
112
+ # FccReboot.get_license(:name=> 'AT', :radioservice=>'Cellular')
113
+ def get_spectrum_licenses(options={})
114
+ options.merge!({:format => "json"})
115
+ response = get('spectrum-view/services/advancedSearch/getLicenses', options)
116
+ JSON.parse(response)["Licenses"]["License"]
117
+ end
118
+
119
+ # his API returns high level license information including name, FRN, call sign,
120
+ # category, service, status, expiration date and license id, based on the search criteria passed.
121
+ # @format :json
122
+ # @key false
123
+ # @param options [Hash] A customizable set of options:
124
+ # searchValue (Required)
125
+ # pageNum (Optional) – Default is 1.
126
+ # sortColumn (Optional) – Default is licName. Valid values are: licName, frn, callsign, service, status, expdate
127
+ # sortOrder (Optional) – Default is asc. Valid values are: asc, desc
128
+ # pageSize (Optional) – Default is 100.
129
+ # @return [Array]
130
+ # @see http://reboot.fcc.gov/developer/license-view-api
131
+ # @example Provide number of licenses that were issued by the Commission on a yearly basis
132
+ # FccReboot.get_licenses(:searchValue => 'Verizon Wireless')
133
+ def get_licenses(options={})
134
+ options.merge!({:format => "json"})
135
+ response = get('license-view/basicSearch/getLicenses', options)
136
+ JSON.parse(response)["Licenses"]["License"]
137
+ end
138
+
139
+ # This API returns a list of currently known licensee names associated with a common name.
140
+ # @format :json
141
+ # @key false
142
+ # @param options [Hash] A customizable set of options:
143
+ # commonName (Optional)
144
+ # limit (Optional) – Number of request rows
145
+ # @return [Array]
146
+ # @see http://reboot.fcc.gov/developer/license-view-api
147
+ # @example Returns a list of currently known licensee names associated with a common name.
148
+ # FccReboot.get_common_names(:commonName => 'Sprint Nextel')
149
+ def get_common_names(options={})
150
+ options.merge!({:format => "json"})
151
+ response = get('license-view/licenses/getCommonNames', options)
152
+ JSON.parse(response)['Stats']['Stat']
153
+ end
154
+
155
+ # This API returns the license counts and percent distribution by status.
156
+ # @format :json
157
+ # @key false
158
+ # @param options [Hash] A customizable set of options:
159
+ # commonName (Optional)
160
+ # limit (Optional) – Number of request rows
161
+ # @return [Array]
162
+ # @see http://reboot.fcc.gov/developer/license-view-api
163
+ # @example Returns the license counts and percent distribution by status.
164
+ # FccReboot.get_statuses(:commonName => 'Sprint Nextel')
165
+ def get_statuses(options={})
166
+ options.merge!({:format => "json"})
167
+ response = get('license-view/licenses/getStatuses', options)
168
+ JSON.parse(response)['Stats']['Stat']
169
+ end
170
+
171
+ # This API returns the number of licenses that were issued by the Commission on a yearly basis.
172
+ #The data returned includes the year and the total number of licenses issued.
173
+ # @format :json
174
+ # @key false
175
+ # @param options [Hash] A customizable set of options:
176
+ # commonName - Name of the coporation
177
+ # @return [Array]
178
+ # @see http://reboot.fcc.gov/developer/license-view-api
179
+ # @example Provide number of licenses that were issued by the Commission on a yearly basis
180
+ # FccReboot.get_issued(:commonName=> 'Sprint Nextel')
181
+ def get_issued(options={})
182
+ options.merge!({:format => "json"})
183
+ response = get('license-view/licenses/getIssued', options)
184
+ JSON.parse(response)["Stats"]["Stat"]
185
+ end
186
+
187
+ # This API returns the number of licenses up for renewal in a given month. The API returns 12 months worth of data.
188
+ # @format :json
189
+ # @key false
190
+ # @param options [Hash] A customizable set of options:
191
+ # commonName - Name of the coporation
192
+ # @return [Array]
193
+ # @see http://reboot.fcc.gov/developer/license-view-api
194
+ # @example Returns the number of licenses up for renewal in a given month. The API returns 12 months worth of data for Sprint Nextel.
195
+ # FccReboot.get_renewals(:commonName=> 'Sprint Nextel')
196
+ def get_renewals(options={})
197
+ options.merge!({:format => "json"})
198
+ response = get('license-view/licenses/getRenewals', options)
199
+ JSON.parse(response)["Stats"]["Stat"]
200
+ end
201
+
202
+ # This API returns the counts and percent distribution of active licenses by entity type.
203
+ # There are four entity categories: Individual, Business, Government and Other.
204
+ # @format :json
205
+ # @key false
206
+ # @param options [Hash] A customizable set of options:
207
+ # @return [Array]
208
+ # @see http://reboot.fcc.gov/developer/license-view-api
209
+ # @example Returns the counts and percent distribution of active licenses by entity type
210
+ # FccReboot.get_renewals()
211
+ def get_entities(options={})
212
+ options.merge!({:format => "json"})
213
+ response = get('license-view/licenses/getEntities', options)
214
+ JSON.parse(response)["Stats"]["Stat"]
215
+ end
216
+
217
+ # This API returns the counts and percent distribution of active licenses by category. A license falls into only one category.
218
+ # There are four entity categories: Individual, Business, Government and Other.
219
+ # @format :json
220
+ # @key false
221
+ # @param options [Hash] A customizable set of options:
222
+ # @return [Array]
223
+ # @see http://reboot.fcc.gov/developer/license-view-api
224
+ # @example Returns the counts and percent distribution of active licenses by category
225
+ # FccReboot.get_categories()
226
+ def get_categories(options={})
227
+ options.merge!({:format => "json"})
228
+ response = get('license-view/licenses/getCategories', options)
229
+ JSON.parse(response)["Stats"]["Stat"]
230
+ end
231
+ end
232
+ end
233
+ end