Module: RESTHelpers::ResponseHelpers

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) created_response(*opts)



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

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

- (Object) deleted_response(id)



34
35
36
# File 'backend/app/lib/rest.rb', line 34

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

- (Object) json_response(obj, status = 200)



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

- (Object) modified_response(type, obj, jsonmodel = nil)



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

- (Object) moved_response(id, target)



44
45
46
# File 'backend/app/lib/rest.rb', line 44

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

- (Object) suppressed_response(id, state)



39
40
41
# File 'backend/app/lib/rest.rb', line 39

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

- (Object) updated_response(*opts)



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

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