contract Reoraclizer is UsingOraclize, Accessable {
    using SafeMath for uint256;

    uint256 public lastTimeUpdate;
    uint256 minUpdatePeriod = 3300; // min update period

    string internal response; //price in cents

    uint256 internal CALLBACK_GAS_LIMIT = 115000;

    // will rewritten after deploying
    // needs to prevent high gas price at first oraclize response
    uint256 internal price = 999999;

    event NewOraclizeQuery(string description);

    constructor() public {
        oraclize_setProof(proofType_Android | proofStorage_IPFS);
        oraclize_setCustomGasPrice(10000000000);
    }

    /**
    * @dev Receives the response from oraclize.
    */
    function __callback(bytes32 _myid, string _result, bytes _proof) public {
        require((lastTimeUpdate + minUpdatePeriod) < now);
        if (msg.sender != oraclize_cbAddress()) revert();

        price = parseInt(_result, 4);
        lastTimeUpdate = now;

        _update(3600);
    }

    function getEthUsdPrice() external onlyPayed payable returns(uint256) {
        return price;
    }

    /**
     * @dev Cyclic query to update ETHUSD price. Period is one hour.
     */
    function _update(uint256 _timeout) internal {
        oraclize_query(_timeout, "URL", "json(https://api.coinmarketcap.com/v2/ticker/1027).data.quotes.USD.price", CALLBACK_GAS_LIMIT);
    }

    function update(uint256 _timeout) public payable onlyOwner {
        _update(_timeout);
    }

    function setOraclizeGasLimit (uint256 _gasLimit) external onlyOwner {
        CALLBACK_GAS_LIMIT = _gasLimit;
    }

    function setGasPrice(uint256 _gasPrice) external onlyOwner {
        oraclize_setCustomGasPrice(_gasPrice);
    }

    function withdrawEth(uint256 _value) external onlyOwner {
        require(address(this).balance > _value.add(3 ether));
        owner.transfer(_value);
    }

    function setMinUpdatePeriod(uint256 _minUpdatePeriod) external onlyOwner {
        minUpdatePeriod = _minUpdatePeriod;
    }
}
function _update(uint256 _timeout) internal {
    oraclize_query(_timeout, "URL", "json(https://api.coinmarketcap.com/v2/ticker/1027).data.quotes.USD.price", CALLBACK_GAS_LIMIT);
}

/**
 * @dev Cyclic query to update ETHUSD price. Period is one hour.
 */