Class: FCC::Station::ExtendedInfo
- Inherits:
-
Object
- Object
- FCC::Station::ExtendedInfo
- Includes:
- HTTParty
- Defined in:
- lib/fcc/station/extended_info.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
Returns the value of attribute results.
-
#service ⇒ Object
Returns the value of attribute service.
Instance Method Summary collapse
- #all_results ⇒ Object
- #find(id_or_call_sign) ⇒ Object
- #find_directly(options) ⇒ Object
-
#initialize(service) ⇒ ExtendedInfo
constructor
A new instance of ExtendedInfo.
Constructor Details
#initialize(service) ⇒ ExtendedInfo
Returns a new instance of ExtendedInfo.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fcc/station/extended_info.rb', line 12 def initialize(service) @service = service @options = { follow_redirects: true } @query = { # state: nil, # call: nil, # city: nil, # arn: nil, # serv: service.to_s.downcase, # Only return primary main records, no backup transmitters, etc… for now status: 3, # licensed records only # freq: @service.to_sym == :fm ? '87.1' : '530', # fre2: @service.to_sym == :fm ? '107.9' : '1700', # facid: nil, # class: nil, # dkt: nil, # dist: nil, # dlat2: nil, # dlon2: nil, # mlon2: nil, # mlat2: nil, # slat2: nil, # slon2: nil, # NS: "N", # e: 9, # EW: 'W', list: 4, # pipe separated output size: 9 } end |
Instance Attribute Details
#results ⇒ Object
Returns the value of attribute results.
8 9 10 |
# File 'lib/fcc/station/extended_info.rb', line 8 def results @results end |
#service ⇒ Object
Returns the value of attribute service.
8 9 10 |
# File 'lib/fcc/station/extended_info.rb', line 8 def service @service end |
Instance Method Details
#all_results ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fcc/station/extended_info.rb', line 45 def all_results begin cache_key = "#{self.class.instance_variable_get('@default_options')[:base_uri]}/#{@service.to_s.downcase}q" FCC.cache.fetch cache_key do response = self.class.get("/#{service.to_s.downcase}q", @options.merge(query: @query)) FCC.log("Request: #{response.request.uri}") FCC.log("Inspect: #{response.request.uri.to_s.gsub('&list=4', '&list=0')}") response.parsed_response end rescue StandardError => e FCC.error(e.) FCC.error(e.backtrace) end end |
#find(id_or_call_sign) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fcc/station/extended_info.rb', line 63 def find(id_or_call_sign) if id_or_call_sign =~ /^\d+$/ id = id_or_call_sign all_results.filter { |r| r[:fcc_id].to_s == id.to_s } || find_directly({ facid: id_or_call_sign }) else all_results.filter { |r| 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]+$") } || find_directly({ call: id_or_call_sign }) end end |
#find_directly(options) ⇒ Object
74 75 76 77 78 |
# File 'lib/fcc/station/extended_info.rb', line 74 def find_directly() response = self.class.get("/#{service.to_s.downcase}q", @options.merge(query: @query.merge())) FCC.log response.request.uri.to_s.gsub('&list=4', '&list=0') response.parsed_response end |