module PIM::Webservice

Public Instance Methods

check_response(response) click to toggle source
# File webservice.rb, line 63
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 94
def delete path, &block
  add_path_handler('DELETE', path, block)
end
get(path, &block) click to toggle source
# File webservice.rb, line 98
def get path, &block
  add_path_handler('GET', path, block)
end
handle_request() click to toggle source
# File webservice.rb, line 38
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 102
def head path, &block
  add_path_handler('HEAD', path, block)
end
options(path, &block) click to toggle source
# File webservice.rb, line 106
def options path, &block
  add_path_handler('OPTIONS', path, block)
end
post(path, &block) click to toggle source
# File webservice.rb, line 110
def post path, &block
  add_path_handler('POST', path, block)
end
put(path, &block) click to toggle source
# File webservice.rb, line 114
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 68
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 122
def retrieve_value key
  __service(:cacheService).get(cache_name, key)
end
send_error(code, message = nil) click to toggle source
# File webservice.rb, line 81
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 118
def store_value key, value
  __service(:cacheService).put(cache_name, key, value)
end