Class: RailFeeds::NetworkRail::Schedule::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/rail_feeds/network_rail/schedule/fetcher.rb

Overview

A class for fetching the schedule data files.

Instance Method Summary collapse

Methods included from Logging

formatter, included, #logger, logger, #logger=, logger=

Constructor Details

#initialize(credentials: Credentials, logger: nil) ⇒ Fetcher

Initialize a new schedule

Parameters:

  • credentials (RailFeeds::NetworkRail::Credentials) (defaults to: Credentials)

    The credentials for connecting to the feed.

  • logger (Logger, nil) (defaults to: nil)

    The logger for outputting events, if nil the global logger will be used.



15
16
17
18
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 15

def initialize(credentials: Credentials, logger: nil)
  @credentials = credentials
  self.logger = logger unless logger.nil?
end

Instance Method Details

#download_all_full(format, file) ⇒ Object

Download the full schedule.

Parameters:

  • format (:json, :cif)

    The format to download the schedule in.

  • file (String)

    The path to the file to save the .json.gz / .cif.gz download in.



25
26
27
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 25

def download_all_full(format, file)
  download 'ALL', 'full', format, file
end

#download_all_update(day, format, file) ⇒ Object

Download the daily update to the full schedule.

Parameters:

  • day (String, #to_s)

    The day to get the update schedule for (“mon”, “tue”, “wed”, …). Defaults to the current day.

  • format (:json, :cif)

    The format to fetch the schedule in.

  • file (String)

    The path to the file to save the .json.gz / .cif.gz download in.



37
38
39
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 37

def download_all_update(day, format, file)
  download 'ALL', day, format, file
end

#download_freight_full(file) ⇒ Object

Fetch the freight schedule.

Parameters:

  • file (String)

    The path to the file to save the .json.gz download in.



44
45
46
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 44

def download_freight_full(file)
  download 'FREIGHT', 'full', :json, file
end

#download_freight_update(day, file) ⇒ Object

Fetch the daily update to the freight schedule.

Parameters:

  • day (String, #to_s)

    The day to get the update schedule for (“mon”, “tue”, “wed”, …). Defaults to the current day.

  • file (String)

    The path to the file to save the .json.gz download in.



54
55
56
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 54

def download_freight_update(day, file)
  download 'FREIGHT', day, :json, file
end

#download_toc_full(toc, file) ⇒ Object

Fetch the schedule for a TOC.

Parameters:

  • toc (String, #to_s, nil)

    The TOC to get the schedule for.

  • file (String)

    The path to the file to save the .json.gz download in.



63
64
65
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 63

def download_toc_full(toc, file)
  download toc, 'full', :json, file
end

#download_toc_update(toc, day, file) ⇒ Object

Fetch the daily update for a TOC.

Parameters:

  • toc (String, #to_s, nil)

    The TOC to get the schedule for.

  • day (String, #to_s)

    The day to get the update schedule for (“mon”, “tue”, “wed”, …). Defaults to the current day.

  • file (String)

    The path to the file to save the .json.gz download in.



75
76
77
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 75

def download_toc_update(toc, day, file)
  download toc, day, :json, file
end

#fetch_all_full(format) {|file| ... } ⇒ Object

Fetch the full schedule.

Parameters:

  • format (:json, :cif)

    The format to fetch the schedule in.

Yields:

  • (file)

    Once the block has run the temp file will be deleted. @yieldparam [Zlib::GzipReader] file The unzippable content of the file.



84
85
86
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 84

def fetch_all_full(format, &block)
  fetch 'ALL', 'full', format, &block
end

#fetch_all_update(day, format) {|file| ... } ⇒ Object

Fetch the daily update to the full schedule.

Parameters:

  • day (String, #to_s)

    The day to get the update schedule for (“mon”, “tue”, “wed”, …). Defaults to the current day.

  • format (:json, :cif)

    The format to fetch the schedule in.

Yields:

  • (file)

    Once the block has run the temp file will be deleted. @yieldparam [Zlib::GzipReader] file The unzippable content of the file.



96
97
98
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 96

def fetch_all_update(day, format, &block)
  fetch 'ALL', day, format, &block
end

#fetch_freight_full {|file| ... } ⇒ Object

Fetch the freight schedule.

Yields:

  • (file)

    Once the block has run the temp file will be deleted. @yieldparam [Zlib::GzipReader] file The unzippable content of the file.



103
104
105
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 103

def fetch_freight_full(&block)
  fetch 'FREIGHT', 'full', :json, &block
end

#fetch_freight_update(day) {|file| ... } ⇒ Object

Fetch the daily update to the freight schedule.

Parameters:

  • day (String, #to_s)

    The day to get the update schedule for (“mon”, “tue”, “wed”, …). Defaults to the current day.

Yields:

  • (file)

    Once the block has run the temp file will be deleted. @yieldparam [TempFile] file The unzippable content of the file.



113
114
115
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 113

def fetch_freight_update(day, &block)
  fetch 'FREIGHT', day, :json, &block
end

#fetch_toc_full(toc) {|file| ... } ⇒ Object

Fetch the schedule for a TOC.

Parameters:

  • toc (String, #to_s, nil)

    The TOC to get the schedule for.

Yields:

  • (file)

    Once the block has run the temp file will be deleted. @yieldparam [Zlib::GzipReader] file The unzippable content of the file.



122
123
124
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 122

def fetch_toc_full(toc, &block)
  fetch toc, 'full', :json, &block
end

#fetch_toc_update(toc, day) {|file| ... } ⇒ Object

Fetch the daily update for a TOC.

Parameters:

  • toc (String, #to_s, nil)

    The TOC to get the schedule for.

  • day (String, #to_s)

    The day to get the update schedule for (“mon”, “tue”, “wed”, …). Defaults to the current day.

Yields:

  • (file)

    Once the block has run the temp file will be deleted. @yieldparam [Zlib::GzipReader] file The unzippable content of the file.



134
135
136
# File 'lib/rail_feeds/network_rail/schedule/fetcher.rb', line 134

def fetch_toc_update(toc, day, &block)
  fetch toc, day, :json, &block
end