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



35
36
37
# File 'lib/web_fetch/resources.rb', line 35

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

.gather(server, params) ⇒ Object



16
17
18
19
20
21
22
23
24
# 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 = {}) ⇒ Object



26
27
28
29
30
31
32
33
# 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) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/web_fetch/resources.rb', line 8

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