fcc 0.1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c1a2e65473c73d939b88beed853dfe8cb2ab4bb67684c522996a4b1eb0f8d7f8
4
+ data.tar.gz: d86f808b6da433d743ac6e2546307cf4bdfeb42ec521796cb78a0ecfffb7da63
5
+ SHA512:
6
+ metadata.gz: e6a3bea8e717984ddd25fed17731e3ba06709c70dcb49340a274d148fcdd281e1463baf6483879d9a2427961589f2e0d7af908d8ce4ab6508776c8ba1d80c5e3
7
+ data.tar.gz: 6da0ba2408b94f8488c45900938d3950e580a5cb71493b942a78696b462f0bc4dee61ea26b5bf4cbd1c54a155ad0b0c5670cde37e90c99ede9581b196cd75586
@@ -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/Gemfile CHANGED
@@ -1,16 +1,23 @@
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 popularity.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
+ #
9
+ # source "http://rubygems.org"
10
+ # # Add dependencies required to use your gem here.
11
+ # # Example:
12
+ # # gem "activesupport", ">= 2.3.5"
13
+ #
14
+ # # Add dependencies to develop your gem here.
15
+ # # Include everything needed to run rake, tests, features, etc.
16
+ #
17
+ # gem "nokogiri"
18
+ #
19
+ # group :development do
20
+ # gem "shoulda", ">= 0"
21
+ # gem "bundler"
22
+ # gem "jeweler"
23
+ # end
@@ -1,22 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fcc (1.1)
5
+ activesupport (>= 6.1)
6
+ httparty (~> 0.18)
7
+
1
8
  GEM
2
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
3
10
  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)
11
+ activesupport (6.1.0)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ awesome_print (1.8.0)
18
+ byebug (11.1.3)
19
+ concurrent-ruby (1.1.7)
20
+ diff-lcs (1.4.4)
21
+ httparty (0.18.1)
22
+ mime-types (~> 3.0)
23
+ multi_xml (>= 0.5.2)
24
+ i18n (1.8.6)
25
+ concurrent-ruby (~> 1.0)
26
+ mime-types (3.3.1)
27
+ mime-types-data (~> 3.2015)
28
+ mime-types-data (3.2020.1104)
29
+ minitest (5.14.2)
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
+ tzinfo (2.0.4)
46
+ concurrent-ruby (~> 1.0)
47
+ zeitwerk (2.4.2)
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
+ awesome_print
54
+ bundler (~> 2.1)
55
+ byebug
56
+ fcc!
57
+ rake (~> 12.3.3)
58
+ rspec (~> 3.9.0)
59
+
60
+ BUNDLED WITH
61
+ 2.1.4
@@ -0,0 +1,60 @@
1
+ # fcc
2
+
3
+ Query the FCC database for fm, am, and tv information.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ gem install fcc
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ * Ruby 2.0.0 or higher
14
+
15
+ ## Examples
16
+
17
+ #### Get station information by call sign
18
+
19
+ ```ruby
20
+ station = FCC::Station.find(:fm, "KOOP")
21
+
22
+ #Basic attributes, available quickly because the FCC actually caches these in a CDN:
23
+ station.id #=> 65320
24
+ station.status #=> LICENSED
25
+ station.rf_channel #=> 219
26
+ station.license_expiration_date #=> "08/01/2021"
27
+ station.facility_type #=> ED
28
+ station.frequency #=> 91.7
29
+ station.contact #=> <struct FCC::Station::Contact>
30
+ station.owner #=> <struct FCC::Station::Contact>
31
+ station.community #=> <struct FCC::Station::Community city="HORNSBY", state="TX">
32
+
33
+ #Extended attributes, takes several seconds to load because the FCC is running this endpoint on a 1960s era mainframe operated by trained hamsters
34
+ station.station_class #=> A
35
+ station.signal_strength #=> 3.0 kW
36
+ station.antenna_type #=> ND
37
+ station.effective_radiated_power #=> 3.0 kW
38
+ station.haat_horizontal #=> 26.0
39
+ station.haat_vertical #=> 26.0
40
+ station.latitude #=> "30.266861111111112"
41
+ station.longitude #=> "-97.67444444444445"
42
+ station.file_number #=> BLED-19950103KA
43
+ ```
44
+
45
+ ### Get all station call signs on a particular service (:fm, :am, :tv)
46
+
47
+ ```ruby
48
+ results = FCC::Station.index(:fm).results
49
+ #=> [{"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"} ....
50
+ ```
51
+
52
+ ## Contributing to fcc
53
+
54
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
55
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
56
+ * Fork the project
57
+ * Start a feature/bugfix branch
58
+ * Commit and push until you are happy with your contribution
59
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
60
+ * 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
@@ -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__)
@@ -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
@@ -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.date = %q{2011-01-30}
10
+ spec.description = %q{}
11
+ spec.email = %q{jeff@keen.me}
12
+ spec.homepage = "http://github.com/jkeen/fcc"
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+ spec.homepage = %q{http://github.com/jkeen/fcc}
18
+ spec.licenses = ["MIT"]
19
+ spec.rubygems_version = %q{1.4.1}
20
+ spec.summary = %q{Searches the FCC's FM, AM, and TV databases}
21
+ spec.add_dependency "activesupport", ">= 6.1"
22
+ spec.add_dependency "httparty", "~> 0.18"
23
+ spec.add_development_dependency "bundler", "~> 2.1"
24
+ spec.add_development_dependency "rake", "~> 12.3.3"
25
+ spec.add_development_dependency 'rspec', '~> 3.9.0'
26
+ spec.add_development_dependency "byebug", ">= 0"
27
+ spec.add_development_dependency "awesome_print", ">= 0"
28
+ end
data/lib/fcc.rb CHANGED
@@ -1,3 +1,10 @@
1
- require 'open-uri'
2
- require 'fm'
3
- require 'am'
1
+ # frozen_string_literal: true
2
+ require_relative './fcc/station'
3
+ require_relative './fcc/station/cache'
4
+ require_relative './fcc/station/info'
5
+ require_relative './fcc/station/extended_info'
6
+ require_relative './fcc/station/result_delegate'
7
+
8
+ module FCC
9
+
10
+ end
@@ -0,0 +1,107 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ require_relative 'station/result_delegate'
3
+ require_relative 'station/extended_info'
4
+ require_relative 'station/index'
5
+ require_relative 'station/info'
6
+
7
+ module FCC
8
+ module Station
9
+ Contact = Struct.new(:name, :title, :address, :address2, :city, :state, :zip_code, :phone, :fax, :email, :website, keyword_init: true)
10
+ Community = Struct.new(:city, :state, keyword_init: true)
11
+
12
+ def self.find_each(service, &block)
13
+ results = index(service).results
14
+
15
+ results.each do |result|
16
+ yield find(service, result['callSign'])
17
+ end
18
+ end
19
+
20
+ def self.find(service, call_sign, options = {})
21
+ Result.new(service, call_sign, options)
22
+ end
23
+
24
+ def self.index(service)
25
+ case service.to_s.downcase.to_sym
26
+ when :fm
27
+ @fm_index ||= Index.new(:fm)
28
+ when :am
29
+ @am_index ||= Index.new(:am)
30
+ when :tv
31
+ @tv_index ||= Index.new(:tv)
32
+ else
33
+ raise "unsupported service #{service}. :fm, :am, and :tv are valid"
34
+ end
35
+ end
36
+
37
+ def self.extended_info_cache(service)
38
+ @cache ||= {}
39
+ @cache[service] ||= Station::Cache.new(service)
40
+ @cache[service]
41
+ end
42
+
43
+ class Result
44
+ EXTENDED_ATTRIBUTES = %i[signal_strength latitude longitude coordinates station_class file_number effective_radiated_power haat_horizontal haat_vertical] # these take a long time to query
45
+ BASIC_ATTRIBUTES = %i[id call_sign status rf_channel license_expiration_date facility_type frequency]
46
+
47
+ delegate *EXTENDED_ATTRIBUTES, to: :extended_data
48
+ delegate *BASIC_ATTRIBUTES, to: :data
49
+
50
+ alias_method :channel, :rf_channel
51
+
52
+ def initialize(service, call_sign, options = {})
53
+ @call_sign = call_sign.upcase
54
+ @service = service
55
+ @options = options
56
+
57
+ data
58
+ end
59
+
60
+ def to_json
61
+ {}.tap do |hash|
62
+ [EXTENDED_ATTRIBUTES | BASIC_ATTRIBUTES | %i[contact owner community]].flatten.each do |attr|
63
+ result = send(attr.to_sym)
64
+ if result.respond_to?(:to_h)
65
+ hash[attr] = result.to_h
66
+ else
67
+ hash[attr] = result.to_s
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def owner
74
+ @owner ||= Contact.new(name: data.partyName, address: data.partyAddress1, address2: data.partyAddress2, city: data.partyCity, state: data.partyState, zip_code: data.partyZip1, phone: data.partyPhone)
75
+ end
76
+
77
+ def community
78
+ @community ||= Community.new(city: data.communityCity, state: data.communityState)
79
+ end
80
+
81
+ def contact
82
+ contact = data.mainStudioContact
83
+ @contact ||= Contact.new(name: contact['contactName'], title: contact['contactTitle'], address: contact['contactAddress1'], address2: contact['contactAddress2'], city: contact['contactCity'], state: contact['contactState'], zip_code: contact['contactZip'], phone: contact['contactPhone'], fax: contact['contactFax'], email: contact['contactEmail'], website: contact['contactWebsite'])
84
+ end
85
+
86
+ def coordinates
87
+ [latitude.to_f, longitude.to_f].to_json
88
+ end
89
+
90
+ def coordinates_url
91
+ "https://www.google.com/maps/search/#{coordinates[0]},#{coordinates[1]}"
92
+ end
93
+
94
+ def extended_data_url
95
+ "https://transition.fcc.gov/fcc-bin/#{@service.to_s.downcase}q?list=4&facid=#{id}"
96
+ end
97
+
98
+ def extended_data
99
+ @extended_data ||= ResultDelegate.new(ExtendedInfo.new(@service).find(@call_sign))
100
+ end
101
+
102
+ def data
103
+ @data ||= ResultDelegate.new(Info.new(@service).find(@call_sign))
104
+ end
105
+ end
106
+ end
107
+ end