Class: ULS::Retriever

Inherits:
Object
  • Object
show all
Defined in:
lib/uls/retriever.rb

Constant Summary collapse

APPLICATION_PREFIX =
'a'.freeze
LICENSE_PREFIX =
'l'.freeze
SERVICES =
{
  amateur_radio: {
    filename: {
      daily: 'am',
      weekly: 'amat'
    },
    records: {
      applications: APPLICATION_PREFIX,
      licenses: LICENSE_PREFIX
    }
  }
}.freeze
DAILY_BASE_URL =

Different base URLs whether we’re looking for the daily updates or the full weekly downloads.

'https://data.fcc.gov/download/pub/uls/daily'.freeze
WEEKLY_BASE_URL =
'https://data.fcc.gov/download/pub/uls/complete'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ Retriever

Returns a new instance of Retriever.

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/uls/retriever.rb', line 34

def initialize(service)
  raise ArgumentError, "Invalid service #{service}" unless services.include?(service)

  self.service = service
end

Instance Attribute Details

#serviceObject

Returns the value of attribute service.



28
29
30
# File 'lib/uls/retriever.rb', line 28

def service
  @service
end

Class Method Details

.amateur_radioObject



30
31
32
# File 'lib/uls/retriever.rb', line 30

def self.amateur_radio
  Retriever.new(:amateur_radio)
end

Instance Method Details

#daily(type, wday = Date.new.prev_day.wday) ⇒ Object



64
65
66
67
# File 'lib/uls/retriever.rb', line 64

def daily(type, wday = Date.new.prev_day.wday)
  url = daily_url(type, wday)
  download(url)
end

#daily_url(type, wday = Date.new.prev_day.wday) ⇒ Object

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
# File 'lib/uls/retriever.rb', line 54

def daily_url(type, wday = Date.new.prev_day.wday)
  raise ArgumentError, "Invalid type #{type}" unless types.include?(type)

  abbreviated_day = Date::ABBR_DAYNAMES[wday].downcase
  prefix = SERVICES[service][:records][type]
  name = SERVICES[service][:filename][:daily]

  "#{DAILY_BASE_URL}/#{prefix}_#{name}_#{abbreviated_day}.zip"
end

#servicesObject



73
74
75
# File 'lib/uls/retriever.rb', line 73

def services
  SERVICES.keys
end

#typesObject



69
70
71
# File 'lib/uls/retriever.rb', line 69

def types
  SERVICES[service][:records].keys
end

#weekly(type) ⇒ Object



49
50
51
52
# File 'lib/uls/retriever.rb', line 49

def weekly(type)
  url = weekly_url(type)
  download(url)
end

#weekly_url(type) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
# File 'lib/uls/retriever.rb', line 40

def weekly_url(type)
  raise ArgumentError, "Invalid type #{type}" unless types.include?(type)

  prefix = SERVICES[service][:records][type]
  name = SERVICES[service][:filename][:weekly]

  "#{WEEKLY_BASE_URL}/#{prefix}_#{name}.zip"
end