fcc 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad1777d7ebc8dd8c084af0608f12814e2ae110003ba57a0114ae3cfb9626bb9d
4
+ data.tar.gz: d0efadd9bc218bd07d680368cf199c35c718e3b5f14e2129c26589991ba8cf20
5
+ SHA512:
6
+ metadata.gz: 125643a4dc0d324d6cced8e1f0414a3a09ea7b6b5c3c40f6afba233bfa393c3d43db81b0eafa102230c30934abf3192f1002cc2b0052ca494e699feec3daa3dd
7
+ data.tar.gz: '0982811e500c437b802b7e01507e99b2ed91a930f01de49552bbef730449daff7069a479c8e2fec527963874780a7411068812c5242c6b6194eea5320f90a9a6'
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: Generate New Release
3
+
4
+ on:
5
+ workflow_dispatch:
6
+
7
+ jobs:
8
+ release:
9
+ name: Release
10
+ runs-on: ubuntu-18.04
11
+ steps:
12
+ - name: Checkout
13
+ uses: actions/checkout@v2
14
+ with:
15
+ fetch-depth: 0
16
+ persist-credentials: false
17
+ - name: Setup Node.js
18
+ uses: actions/setup-node@v2
19
+ with:
20
+ node-version: 14
21
+ - name: Install Dependencies
22
+ run: yarn install --frozen-lockfile
23
+ - name: Release
24
+ env:
25
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26
+ GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
27
+ run: node_modules/.bin/semantic-release
@@ -0,0 +1,53 @@
1
+ name: Tests
2
+ on:
3
+ push:
4
+ pull_request:
5
+ concurrency:
6
+ group: ci-tests-${{ github.ref }}-1
7
+ cancel-in-progress: true
8
+ jobs:
9
+ test:
10
+ name: Run Tests
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ ubuntu-latest ]
15
+ ruby: [ '2.7' ]
16
+ runs-on: ${{ matrix.os }}
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - uses: actions/cache@v3
24
+ with:
25
+ path: vendor/bundle
26
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
27
+ restore-keys: |
28
+ ${{ runner.os }}-gems-
29
+ - name: Bundle Install
30
+ run: |
31
+ gem install bundler
32
+ bundle install --jobs 4 --retry 3
33
+
34
+ - name: Run RSpec
35
+ run: bundle exec rspec -f j -o tmp/rspec_results.json -f p
36
+
37
+ - name: RSpec Report
38
+ uses: SonicGarden/rspec-report-action@v2
39
+ with:
40
+ token: ${{ secrets.GITHUB_TOKEN }}
41
+ json-path: tmp/rspec_results.json
42
+ if: always()
43
+ publish:
44
+ name: Release
45
+ runs-on: ubuntu-latest
46
+ if: github.ref == 'refs/heads/main'
47
+ needs: [test]
48
+ steps:
49
+ - name: Dispatch Release
50
+ uses: benc-uk/workflow-dispatch@v1
51
+ with:
52
+ workflow: Generate New Release
53
+ token: ${{ secrets.GITHUB_TOKEN }}
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+ .byebug_history
14
+ .vscode
15
+
16
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
17
+ #
18
+ # * Create a file at ~/.gitignore
19
+ # * Include files you want ignored
20
+ # * Run: git config --global core.excludesfile ~/.gitignore
21
+ #
22
+ # After doing this, these files will be ignored in all your git projects,
23
+ # saving you from having to 'pollute' every project you touch with them
24
+ #
25
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
26
+ #
27
+ # For MacOS:
28
+ #
29
+ #.DS_Store
30
+ #
31
+ # For TextMate
32
+ #*.tmproj
33
+ #tmtags
34
+ #
35
+ # For emacs:
36
+ #*~
37
+ #\#*
38
+ #.\#*
39
+ #
40
+ # For vim:
41
+ #*.swp
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ fcc changelog
2
+
3
+ # 1.0.0 (2023-02-12)
4
+
5
+ ## [1.4.0](https://github.com/jkeen/fcc/compare/v1.4.0...v1.3.0) (2022-11-25)
6
+
7
+
8
+ ## [1.3.0](https://github.com/jkeen/fcc/compare/v1.3.0...v1.2.1) (2022-07-10)
9
+
10
+ - Combine data from multiple sources to get a full picture of the station data (transition api, public api, LMS csv files)
11
+ - Now includes related transmitters, repeaters, low power stations, etc
data/Gemfile CHANGED
@@ -1,16 +1,11 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'https://rubygems.org'
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
3
+ git_source(:github) { |repo_name| 'https://github.com/jkeen/fcc' }
8
4
 
9
- gem "nokogiri"
5
+ # Specify your gem's dependencies in fcc.gemspec
6
+ gemspec
10
7
 
11
- group :development do
12
- gem "shoulda", ">= 0"
13
- gem "bundler", "~> 1.0.0"
14
- gem "jeweler", "~> 1.5.2"
15
- gem "rcov", ">= 0"
16
- end
8
+ # group :development do
9
+ # gem "awesome_print", require: true
10
+ # gem "byebug", require: true
11
+ # end
data/Gemfile.lock CHANGED
@@ -1,22 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fcc (1.4.0)
5
+ activesupport (>= 6.1)
6
+ httparty (~> 0.18)
7
+ lightly (~> 0.3.3)
8
+ logger
9
+ rubyzip (~> 2.3.2)
10
+
1
11
  GEM
2
- remote: http://rubygems.org/
12
+ remote: https://rubygems.org/
3
13
  specs:
4
- git (1.2.5)
5
- jeweler (1.5.2)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- nokogiri (1.4.4)
10
- rake (0.8.7)
11
- rcov (0.9.9)
12
- shoulda (2.11.3)
14
+ activesupport (7.0.4.2)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ concurrent-ruby (1.2.0)
20
+ diff-lcs (1.5.0)
21
+ httparty (0.21.0)
22
+ mini_mime (>= 1.0.0)
23
+ multi_xml (>= 0.5.2)
24
+ i18n (1.12.0)
25
+ concurrent-ruby (~> 1.0)
26
+ lightly (0.3.3)
27
+ logger (1.5.3)
28
+ mini_mime (1.1.2)
29
+ minitest (5.17.0)
30
+ multi_xml (0.6.0)
31
+ rake (12.3.3)
32
+ rspec (3.9.0)
33
+ rspec-core (~> 3.9.0)
34
+ rspec-expectations (~> 3.9.0)
35
+ rspec-mocks (~> 3.9.0)
36
+ rspec-core (3.9.3)
37
+ rspec-support (~> 3.9.3)
38
+ rspec-expectations (3.9.4)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.9.0)
41
+ rspec-mocks (3.9.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-support (3.9.4)
45
+ rubyzip (2.3.2)
46
+ tzinfo (2.0.6)
47
+ concurrent-ruby (~> 1.0)
13
48
 
14
49
  PLATFORMS
15
50
  ruby
16
51
 
17
52
  DEPENDENCIES
18
- bundler (~> 1.0.0)
19
- jeweler (~> 1.5.2)
20
- nokogiri
21
- rcov
22
- shoulda
53
+ bundler (~> 2.1)
54
+ fcc!
55
+ rake (~> 12.3.3)
56
+ rspec (~> 3.9.0)
57
+
58
+ BUNDLED WITH
59
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # fcc
2
+
3
+ Query the FCC database for fm, am, and tv information.
4
+
5
+
6
+ This gem uses the new FCC apis and the old FCC apis and combines records to be the most complete version possible. The old (transition.fcc.gov) API provides way more data than the new one does.
7
+
8
+ ## Install
9
+
10
+ ```
11
+ gem install fcc
12
+ ```
13
+
14
+ ## Requirements
15
+
16
+ * Ruby 2.0.0 or higher
17
+
18
+ #### Get station information by call sign
19
+
20
+ ```ruby
21
+ station = FCC::Station.find(:fm, "KOOP")
22
+
23
+ if station.exists? && station.licensed?
24
+ #Basic attributes, available quickly because the FCC actually caches these in a CDN:
25
+ station.id #=> 65320
26
+ station.status #=> LICENSED
27
+ station.rf_channel #=> 219
28
+ station.license_expiration_date #=> "08/01/2021"
29
+ station.facility_type #=> ED
30
+ station.frequency #=> 91.7
31
+ station.contact #=> <struct FCC::Station::Contact>
32
+ station.owner #=> <struct FCC::Station::Contact>
33
+ station.community #=> <struct FCC::Station::Community city="HORNSBY", state="TX">
34
+
35
+ # Extended attributes, takes several seconds to load initially because the FCC is running this endpoint on a 1960s era mainframe operated by trained hamsters.
36
+ station.station_class #=> A
37
+ station.signal_strength #=> 3.0 kW
38
+ station.antenna_type #=> ND
39
+ station.effective_radiated_power #=> 3.0 kW
40
+ station.haat_horizontal #=> 26.0
41
+ station.haat_vertical #=> 26.0
42
+ station.latitude #=> "30.266861111111112"
43
+ station.longitude #=> "-97.67444444444445"
44
+ station.file_number #=> BLED-19950103KA
45
+
46
+
47
+ station.to_json #=>
48
+ [{:band=>"FM",
49
+ :signal_strength=>"3.0 kW",
50
+ :latitude=>"30.266861111111112",
51
+ :longitude=>"-97.67444444444445",
52
+ :station_class=>"A",
53
+ :file_number=>"BLED-19950103KA",
54
+ :effective_radiated_power=>"3.0 kW",
55
+ :haat_horizontal=>"26.0",
56
+ :haat_vertical=>"26.0",
57
+ :antenna_type=>"ND",
58
+ :operating_hours=>nil,
59
+ :licensed_to=>"TEXAS EDUCATIONAL BROADCASTING CO-OPERATIVE, INC.",
60
+ :city=>"HORNSBY",
61
+ :state=>"TX",
62
+ :country=>"US",
63
+ :id=>"65320",
64
+ :call_sign=>"KOOP",
65
+ :status=>"LICENSED",
66
+ :rf_channel=>"219",
67
+ :license_expiration_date=>"08/01/2029",
68
+ :facility_type=>"ED",
69
+ :frequency=>"91.7",
70
+ :contact=>
71
+ {:name=>"Federico Pacheco",
72
+ :title=>"",
73
+ :address=>"3823 Airport Blvd. Suite B",
74
+ :address2=>"",
75
+ :city=>"Austin",
76
+ :state=>"TX",
77
+ :zip_code=>"78722",
78
+ :phone=>"(512)472-1369",
79
+ :fax=>"",
80
+ :email=>"federico.pacheco@koop.org",
81
+ :website=>"koop.org"},
82
+ :owner=>{:name=>"TEXAS EDUCATIONAL BROADCASTING CO-OPERATIVE, INC.", :city=>"AUSTIN", :state=>"TX", :phone=>"(512)472-1369"},
83
+ :community=>{:city=>"HORNSBY", :state=>"TX"}}]
84
+ ```
85
+ end
86
+
87
+
88
+ ### Caching
89
+ Extended attributes take several seconds to load from transition.fcc.gov. In order to work around this, we query the entire dataset and then cache the result locally for 3 days (using the lightly gem). To use your own cache, set `FCC.cache=` to your cache class (Rails.cache, maybe?) which should have a #fetch method that should take a key and a block like `cache.fetch(key) { // yield for expensive fetch }}`.
90
+
91
+ ### Get all station call signs on a particular service (:fm, :am, :tv)
92
+
93
+ ```ruby
94
+ results = FCC::Station.index(:fm).results
95
+ #=> [{"id"=>"198674", "callSign"=>"KANC", "frequency"=>"99.7", "activeInd"=>"Y"}, {"id"=>"174558", "callSign"=>"WUMZ", "frequency"=>"91.5", "activeInd"=>"Y"}, {"id"=>"184688", "callSign"=>"WHVC", "frequency"=>"102.5", "activeInd"=>"Y"} ....
96
+ ```
97
+
98
+ ## Contributing to fcc
99
+
100
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
101
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
102
+ * Fork the project
103
+ * Start a feature/bugfix branch
104
+ * Commit and push until you are happy with your contribution
105
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
106
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
data/Rakefile CHANGED
@@ -7,47 +7,11 @@ rescue Bundler::BundlerError => e
7
7
  $stderr.puts "Run `bundle install` to install missing gems"
8
8
  exit e.status_code
9
9
  end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "fcc"
16
- gem.homepage = "http://github.com/jkeen/fcc"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Searches the FCC's FM and AM databases}
19
- gem.description = %Q{}
20
- gem.email = "jeff@keen.me"
21
- gem.authors = ["Jeff Keen"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
10
 
36
- require 'rcov/rcovtask'
37
- Rcov::RcovTask.new do |test|
38
- test.libs << 'test'
39
- test.pattern = 'test/**/test_*.rb'
40
- test.verbose = true
41
- end
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
11
+ require 'rake'
12
+ require "bundler/gem_tasks"
13
+ require "rspec/core/rake_task"
48
14
 
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "fcc #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
15
+ RSpec::Core::RakeTask.new(:spec)
16
+ desc 'Runs the specs'
17
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'fcc'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/fcc.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = %q{fcc}
7
+ spec.version = FCC::VERSION
8
+ spec.authors = ["Jeff Keen"]
9
+ spec.description = %q{}
10
+ spec.email = %q{jeff@keen.me}
11
+ spec.homepage = "http://github.com/jkeen/fcc"
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+ spec.homepage = %q{http://github.com/jkeen/fcc}
17
+ spec.licenses = ["MIT"]
18
+ spec.rubygems_version = %q{1.4.1}
19
+ spec.summary = %q{Searches the FCC's FM, AM, and TV databases}
20
+ spec.add_dependency "activesupport", ">= 6.1"
21
+ spec.add_dependency "httparty", "~> 0.18"
22
+ spec.add_dependency "lightly", "~> 0.3.3"
23
+ spec.add_dependency "rubyzip", "~> 2.3.2"
24
+ spec.add_dependency "logger"
25
+ spec.add_development_dependency "bundler", "~> 2.1"
26
+ spec.add_development_dependency "rake", "~> 12.3.3"
27
+ spec.add_development_dependency 'rspec', '~> 3.9.0'
28
+ end
@@ -0,0 +1,35 @@
1
+ require 'httparty'
2
+ require_relative './parsers/extended_info'
3
+ require 'lightly'
4
+ require 'logger'
5
+
6
+ module FCC
7
+ module Station
8
+ class Cache
9
+ attr_reader :store
10
+
11
+ def initialize
12
+ @lightly = Lightly.new(life: '3d', hash: true).tap do |cache|
13
+ cache.prune
14
+ end
15
+ end
16
+
17
+ def flush
18
+ @lightly.flush
19
+ end
20
+
21
+ def fetch(key)
22
+ FCC.log("Retreiving #{key} from cache")
23
+ @lightly.get(key.to_s) do
24
+ FCC.log "Loading up the cache with results for key: #{key}. This might take a minute…"
25
+ value = yield
26
+ if value && value.present?
27
+ value
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,80 @@
1
+ require 'httparty'
2
+ require_relative './parsers/extended_info'
3
+
4
+ module FCC
5
+ module Station
6
+ class ExtendedInfo
7
+ include HTTParty
8
+ attr_accessor :results, :service
9
+
10
+ base_uri 'https://fcc-cache.b-cdn.net/fcc-bin/'
11
+
12
+ def initialize(service)
13
+ @service = service
14
+ @options = {
15
+ follow_redirects: true
16
+ }
17
+
18
+ @query = {
19
+ # state: nil,
20
+ # call: nil,
21
+ # city: nil,
22
+ # arn: nil,
23
+ # serv: service.to_s.downcase, # Only return primary main records, no backup transmitters, etc… for now
24
+ status: 3, # licensed records only
25
+ # freq: @service.to_sym == :fm ? '87.1' : '530',
26
+ # fre2: @service.to_sym == :fm ? '107.9' : '1700',
27
+ # facid: nil,
28
+ # class: nil,
29
+ # dkt: nil,
30
+ # dist: nil,
31
+ # dlat2: nil,
32
+ # dlon2: nil,
33
+ # mlon2: nil,
34
+ # mlat2: nil,
35
+ # slat2: nil,
36
+ # slon2: nil,
37
+ # NS: "N",
38
+ # e: 9,
39
+ # EW: 'W',
40
+ list: 4, # pipe separated output
41
+ size: 9
42
+ }
43
+ end
44
+
45
+ def all_results
46
+
47
+ begin
48
+ cache_key = "#{self.class.instance_variable_get('@default_options')[:base_uri]}/#{@service.to_s.downcase}q"
49
+ FCC.cache.fetch cache_key do
50
+ response = self.class.get("/#{service.to_s.downcase}q", @options.merge(query: @query))
51
+ FCC.log(response.request.uri.to_s.gsub('&list=4', '&list=0'))
52
+ response.parsed_response
53
+ end
54
+ rescue StandardError => e
55
+ FCC.error(e.message)
56
+ FCC.error(e.backtrace)
57
+ end
58
+ end
59
+
60
+ def find(id_or_call_sign)
61
+ if id_or_call_sign =~ /^\d+$/
62
+ id = id_or_call_sign
63
+ all_results.filter { |r| r[:fcc_id].to_s == id.to_s } || find_directly({ facid: id_or_call_sign })
64
+ else
65
+ all_results.filter { |r|
66
+ r[:call_sign].to_s == id_or_call_sign.to_s || r[:call_sign].to_s.upcase =~ Regexp.new("^#{id_or_call_sign.upcase}[-—–][A-Z0-9]+$")
67
+ } || find_directly({ call: id_or_call_sign })
68
+ end
69
+ end
70
+
71
+ def find_directly(options)
72
+ response = self.class.get("/#{service.to_s.downcase}q", @options.merge(query: @query.merge(options)))
73
+ FCC.log response.request.uri.to_s.gsub('&list=4', '&list=0')
74
+ response.parsed_response
75
+ end
76
+
77
+ parser FCC::Station::Parsers::ExtendedInfo
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,39 @@
1
+ require 'httparty'
2
+
3
+ module FCC
4
+ module Station
5
+ class Index
6
+ include HTTParty
7
+ base_uri 'publicfiles.fcc.gov'
8
+
9
+ attr_accessor :service
10
+
11
+ def initialize(service)
12
+ @service = service
13
+ end
14
+
15
+ def call_sign_to_id(call_sign)
16
+ found = results.detect do |hash|
17
+ hash['callSign'] == call_sign.upcase
18
+ end
19
+
20
+ found ||= results.detect do |hash|
21
+ hash['callSign'] == "#{call_sign.upcase}-#{service.to_s.upcase}"
22
+ end
23
+
24
+ found['id'] if found
25
+ end
26
+
27
+ def inspect
28
+ "<Station::Index @results=[#{results.size}]>"
29
+ end
30
+
31
+ def results
32
+ @results ||= begin
33
+ response = self.class.get("/api/service/#{service.to_s.downcase}/facility/getall.json")
34
+ response.parsed_response['results']['facilityList']
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ require 'httparty'
2
+
3
+ module FCC
4
+ module Station
5
+ class Info
6
+ include HTTParty
7
+ base_uri 'publicfiles.fcc.gov'
8
+
9
+ attr_accessor :results, :service
10
+
11
+ def initialize(service)
12
+ @service = service
13
+ end
14
+
15
+ def find(id_or_call_sign, options = {})
16
+ id = if id_or_call_sign =~ /^\d+$/
17
+ id_or_call_sign
18
+ else
19
+ Station.index(service).call_sign_to_id(id_or_call_sign)
20
+ end
21
+
22
+ response = self.class.get("/api/service/#{service.to_s.downcase}/facility/id/#{id}.json")
23
+
24
+ begin
25
+ body = response['results']['facility']
26
+ body['band'] = service.to_s.upcase.to_s
27
+
28
+ body
29
+ rescue StandardError => e
30
+ return nil
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end