class Honey::DataFeed
Data Feed
Access Honey's Place data feeds in various formats
Constants
- Formats
Attributes
code[R]
format[R]
Public Class Methods
new(code, format)
click to toggle source
# File lib/honey/data_feed.rb, line 12 def initialize(code, format) @code = code @format = format if Formats.include?(format) end
Public Instance Methods
download_to(path)
click to toggle source
# File lib/honey/data_feed.rb, line 28 def download_to(path) File.open(path, 'w') do |file| file.write(read) # HTTParty.get(url, stream: true) do |fragment| # file.write(fragment) # end end end
parse()
click to toggle source
# File lib/honey/data_feed.rb, line 24 def parse read end
url()
click to toggle source
# File lib/honey/data_feed.rb, line 17 def url if format.nil? raise ArgumentError, "format is required to be one of #{Formats}" end "https://www.honeysplace.com/df/#{code}/#{format}" end
Private Instance Methods
read()
click to toggle source
# File lib/honey/data_feed.rb, line 39 def read response = HTTParty.get(url) if response.headers['content-type'].start_with?('text/html;') raise StandardError, 'This data feed is not ready. Try again later.' end response.parsed_response end