module PIM::Webservice

Public Instance Methods

check_response(response) click to toggle source
# File webservice.rb, line 61
def check_response response
  code = response.code.to_i
  raise Net::HTTPError.new(response) if code < 200 or code >= 300
end
delete(path, &block) click to toggle source
# File webservice.rb, line 92
def delete path, &block
  add_path_handler('DELETE', path, block)
end
get(path, &block) click to toggle source
# File webservice.rb, line 96
def get path, &block
  add_path_handler('GET', path, block)
end
handle_request() click to toggle source
# File webservice.rb, line 36
def handle_request

  return if $request.nil? or $path.nil?

  begin

    method = $request.method
    path = $path

    block = get_path_handler(method, path)
    if block
      context = WebserviceRequestContext.new($request, $response, $organization, $path)
      block.call(context)
    else
      PIM.log_warn("No webservice request defined for #{method} #{$path}")
      send_error HttpStatus::METHOD_NOT_ALLOWED, 'Method Not Allowed'
    end

  rescue Exception => e
    PIM.log_warn("Error in webservice request to #{method} #{path}", e)
    send_error HttpStatus::WEBSERVICE_ERROR, e.message
  end

end
head(path, &block) click to toggle source
# File webservice.rb, line 100
def head path, &block
  add_path_handler('HEAD', path, block)
end
options(path, &block) click to toggle source
# File webservice.rb, line 104
def options path, &block
  add_path_handler('OPTIONS', path, block)
end
post(path, &block) click to toggle source
# File webservice.rb, line 108
def post path, &block
  add_path_handler('POST', path, block)
end
put(path, &block) click to toggle source
# File webservice.rb, line 112
def put path, &block
  add_path_handler('PUT', path, block)
end
redirect(location, code = HttpStatus::SEE_OTHER) click to toggle source
# File webservice.rb, line 66
def redirect location, code = HttpStatus::SEE_OTHER

  return if not $response

  $response.setStatus(code)
  $response.setHeader(HttpHeader::LOCATION, $response.encodeRedirectURL(location))
  $response.sendRedirect(location);

  writer = $response.getWriter()
  writer.write(location)

end
retrieve_value(key) click to toggle source
# File webservice.rb, line 120
def retrieve_value key
  __service(:cacheService).get(cache_name, key)
end
send_error(code, message = nil) click to toggle source
# File webservice.rb, line 79
def send_error code, message = nil

  return if not $response

  code = code.to_i
  if message
    $response.sendError(code, message)
  else
    $response.sendError(code)
  end

end
store_value(key, value) click to toggle source
# File webservice.rb, line 116
def store_value key, value
  __service(:cacheService).put(cache_name, key, value)
end