Class: WebFetch::Resources

Inherits:
Object
  • Object
show all
Defined in:
lib/web_fetch/resources.rb

Overview

Glue between the router and the guts of the application; calls the relevant code and builds responses

Class Method Summary collapse

Class Method Details

.find(server, params) ⇒ Object



31
32
33
# File 'lib/web_fetch/resources.rb', line 31

def find(server, params)
  retrieve(server, params, block: false)
end

.gather(server, params) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/web_fetch/resources.rb', line 12

def gather(server, params)
  gatherer = Gatherer.new(server, params)
  if gatherer.valid?
    { status: status(:ok), payload: gatherer.start }
  else
    { status: status(:unprocessable),
      payload: { error: gatherer.errors } }
  end
end

.retrieve(server, params, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/web_fetch/resources.rb', line 22

def retrieve(server, params, options = {})
  retriever = Retriever.new(server, params, options)
  unless retriever.valid?
    return { status: status(:unprocessable),
             payload: { error: retriever.errors } }
  end
  defer_if_found(retriever)
end

.root(_server, _params) ⇒ Object



8
9
10
# File 'lib/web_fetch/resources.rb', line 8

def root(_server, _params)
  { status: status(:ok), payload: { application: 'WebFetch' } }
end