Class: Honey::DataFeed

Inherits:
Object
  • Object
show all
Defined in:
lib/honey/data_feed.rb

Overview

Data Feed

Access Honey’s Place data feeds in various formats

Constant Summary collapse

Formats =
%i(xml json csv woo shopify amazon_inventory).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, format) ⇒ DataFeed

Returns a new instance of DataFeed.



12
13
14
15
# File 'lib/honey/data_feed.rb', line 12

def initialize(code, format)
  @code = code
  @format = format if Formats.include?(format)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/honey/data_feed.rb', line 8

def code
  @code
end

#formatObject (readonly)

Returns the value of attribute format.



8
9
10
# File 'lib/honey/data_feed.rb', line 8

def format
  @format
end

Instance Method Details

#download_to(path) ⇒ Object



28
29
30
31
32
33
34
35
# 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

#parseObject



24
25
26
# File 'lib/honey/data_feed.rb', line 24

def parse
  read
end

#urlObject



17
18
19
20
21
22
# 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