Module: RESTHelpers::ResponseHelpers

Defined in:
backend/app/lib/rest.rb

Instance Method Summary collapse

Instance Method Details

#created_response(*opts) ⇒ Object



25
26
27
# File 'backend/app/lib/rest.rb', line 25

def created_response(*opts)
  modified_response('Created', *opts)
end

#deleted_response(id) ⇒ Object



50
51
52
# File 'backend/app/lib/rest.rb', line 50

def deleted_response(id)
  json_response({:status => 'Deleted', :id => id})
end

#json_response(obj, status = 200) ⇒ Object



8
9
10
# File 'backend/app/lib/rest.rb', line 8

def json_response(obj, status = 200)
  [status, {"Content-Type" => "application/json"}, [obj.to_json(:mode => :trusted, :max_nesting => false) + "\n"]]
end

#merged_response(target, victims, selections = [], result = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'backend/app/lib/rest.rb', line 35

def merged_response(target, victims, selections = [], result = nil)
  type = target[:type].to_sym
  response = {:status => 'Merged', :id => target[:id], :selections => selections }

  response[:target_uri] = JSONModel(type).uri_for(target[:id], :repo_id => params[:repo_id])
  response[:deleted_uris] = victims.map { |v| JSONModel(type).uri_for(v[:id], :repo_id => params[:repo_id]) }

  unless result.nil?
    response[:result] = result
  end

  json_response(response)
end

#modified_response(type, obj, jsonmodel = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'backend/app/lib/rest.rb', line 13

def modified_response(type, obj, jsonmodel = nil)
  response = {:status => type, :id => obj[:id], :lock_version => obj[:lock_version], :stale => obj.system_modified?}

  if jsonmodel
    response[:uri] = jsonmodel.class.uri_for(obj[:id], params)
    response[:warnings] = jsonmodel._warnings
  end

  json_response(response)
end

#moved_response(id, target) ⇒ Object



60
61
62
# File 'backend/app/lib/rest.rb', line 60

def moved_response(id, target)
  json_response({:status => 'Moved', :id => id, :target => target.id})
end

#suppressed_response(id, state) ⇒ Object



55
56
57
# File 'backend/app/lib/rest.rb', line 55

def suppressed_response(id, state)
  json_response({:status => 'Suppressed', :id => id, :suppressed_state => state})
end

#updated_response(*opts) ⇒ Object



30
31
32
# File 'backend/app/lib/rest.rb', line 30

def updated_response(*opts)
  modified_response('Updated', *opts)
end