After weeks of negotiations mediated by Qatar, Hamas and Israel have agreed to a temporary truce based on a mutual hostage exchange.