class WebFetch::Resources
Glue between the router and the guts of the application; calls the relevant code and builds responses
Public Class Methods
find(server, params)
click to toggle source
# File lib/web_fetch/resources.rb, line 35 def find(server, params) retrieve(server, params, block: false) end
gather(server, params)
click to toggle source
# File lib/web_fetch/resources.rb, line 16 def gather(server, params) gatherer = Gatherer.new(server.storage, params) if gatherer.valid? { status: status(:ok), payload: gatherer.start, command: 'gather' } else { status: status(:unprocessable), payload: { error: gatherer.errors }, command: 'gather' } end end
retrieve(server, params, options = {})
click to toggle source
# File lib/web_fetch/resources.rb, line 26 def retrieve(server, params, options = {}) retriever = Retriever.new(server.storage, params, options) unless retriever.valid? return { status: status(:unprocessable), command: 'retrieve', payload: { error: retriever.errors } } end defer_if_found(retriever) end
root(_server, _params)
click to toggle source
# File lib/web_fetch/resources.rb, line 8 def root(_server, _params) { status: status(:ok), command: 'root', payload: { application: 'WebFetch' } } end
Private Class Methods
defer_if_found(retriever)
click to toggle source
# File lib/web_fetch/resources.rb, line 48 def defer_if_found(retriever) { command: 'retrieve', request: retriever.find } end
status(name)
click to toggle source
# File lib/web_fetch/resources.rb, line 41 def status(name) { ok: 200, unprocessable: 422 }.fetch(name) end