Class: FakeFlorence::Retriever
- Inherits:
-
Object
- Object
- FakeFlorence::Retriever
- Defined in:
- lib/fake_florence/retriever.rb
Defined Under Namespace
Classes: HTTPFailure, NotFlorenceServerError
Instance Method Summary collapse
- #each_feature ⇒ Object
-
#initialize(root_url) ⇒ Retriever
constructor
A new instance of Retriever.
Constructor Details
#initialize(root_url) ⇒ Retriever
11 12 13 14 15 16 17 18 19 |
# File 'lib/fake_florence/retriever.rb', line 11 def initialize(root_url) @root = root_url @http = Faraday.new do |f| f.response :json, content_type: /\bjson$/ f.use Faraday::Response::RaiseError f.adapter Faraday.default_adapter end end |
Instance Method Details
#each_feature ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fake_florence/retriever.rb', line 21 def each_feature urls = [@root] 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. raise HTTPFailure end |