class FakeFlorence::Retriever

Public Class Methods

new(root_url) click to toggle source
# File lib/fake_florence/retriever.rb, line 11
def initialize(root_url)
  @root = URI.parse(root_url)

  @http = Faraday.new do |f|
    f.response :json, content_type: /\bjson$/
    f.use Faraday::Request::BasicAuthentication, @root.user, @root.password if @root.user
    f.use Faraday::Response::RaiseError
    f.adapter Faraday.default_adapter
  end
end

Public Instance Methods

each_feature() { |get_feature(listing)| ... } click to toggle source
# File lib/fake_florence/retriever.rb, line 22
def each_feature
  urls = [@root.to_s]

  while url = urls.shift
    response = @http.get(url)
    links = response.body['_links']
    raise NotFlorenceServerError if links.nil?

    urls << links['next']['href'] if links['next']

    (links['features'] ||[]).each do |listing|
      yield get_feature(listing['href'])
    end
  end
rescue Faraday::Error::ClientError => e
  Config.log.debug e.message
  raise HTTPFailure
end

Private Instance Methods

get_feature(url) click to toggle source
# File lib/fake_florence/retriever.rb, line 43
def get_feature(url)
  response = @http.get(url)
  Feature.new(response.body)
end