class CertificateFactory::Factory

Attributes

count[R]
response[R]

Public Class Methods

new(options) click to toggle source
# File lib/certificate-factory/factory.rb, line 9
def initialize(options)
  @url = options[:feed]
  @limit = options[:limit]
  @campaign = options[:campaign]
  @count = 0
  @response = self.class.get(@url)
  @logger = options[:logger]
end

Public Instance Methods

build() { |certificate(url, campaign: campaign).generate| ... } click to toggle source
# File lib/certificate-factory/factory.rb, line 18
def build
  each do |item|
    url = get_link(item)
    yield Certificate.new(url, campaign: @campaign).generate
  end
end
ckan_url(api_url) click to toggle source
# File lib/certificate-factory/factory.rb, line 63
def ckan_url(api_url)
  CertificateFactory::API.new(api_url).ckan_url
end
each() { |item| ... } click to toggle source
# File lib/certificate-factory/factory.rb, line 25
def each
  loop do
    feed_items.each do |item|
      yield item
      @count += 1
      return if over_limit?
    end
    return unless fetch_next_page
  end
end
feed_items() click to toggle source
# File lib/certificate-factory/factory.rb, line 40
def feed_items
  [response["feed"]["entry"]].flatten # In case there is only one feed item
end
fetch_next_page() click to toggle source
# File lib/certificate-factory/factory.rb, line 48
def fetch_next_page
  @url = next_page
  if @url
    @logger.debug "feed: #{@url}" if @logger
    @response = self.class.get(@url)
  else
    return false
  end
end
next_page() click to toggle source
# File lib/certificate-factory/factory.rb, line 44
def next_page
  response["feed"]["link"].find { |l| l["rel"] == "next" }["href"] rescue nil
end
over_limit?() click to toggle source
# File lib/certificate-factory/factory.rb, line 36
def over_limit?
  @limit && @limit <= @count
end