<commit_before>require 'net/http'
require 'json'

# All public functions return (Hash) result: success or error with message and error code
#
# For more information please visit:
# - http://www.cloudflare.com/docs/client-api.html
# - http://www.cloudflare.com/docs/host-api.html
#
# Note: param zone - the zone you'd like to run CNAMES through CloudFlare for, e.g. +example.com+.

class CloudFlare

    # URL for Client and Host API

    URL_API = {
        client: 'https://www.cloudflare.com/api_json.html',
        host: 'https://api.cloudflare.com/host-gw.html'
    }

    TIMEOUT = 5 # Default is 5 seconds

    # @param api_key [String] user or Host API key.
    # @param email [String] it is for a Client API.
    def initialize(api_key, email = nil)
        @params = Hash.new

        if email.nil?
            @params[:api_key] = api_key
        else
            @params[:api_key] = api_key
            @params[:email] = email
        end

    end

    # CLIENT

    # This function can be used to get currently settings of values such as the security level.
    #
    # More: http://www.cloudflare.com/docs/client-api.html#FUNCTION:_Current_Stats_and_Settings
    #
    # @param zone [String]
    # @param interval [Integer] the interval parameter defines what period you want to look at. Default is 30 days, but 1 day delayed. Pro only intervals are 100, 110, and 120.
    # @return [Hash] the current stats and settings for a particular website

    def stats(zone, interval = 20)
        send_req({a: :stats, z: zone, interval: interval})
    end

    # @return [Hash] all domains in a CloudFlare account along with other data.

    def zone_load_multi
        send_req(a: :zone_load_multi)
    end

    # @param zone [String]
    # @return [Hash] all of the DNS records from a particular domain in a CloudFlare account
    def rec_load_all(zone)
        send_req({a: :rec_load_all, z: zone})
    end

    # This function checks whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
    #
    # @param zones [String or Array] like 'example.com, example2.com' or ['examaple.com', 'example2.com']
    # @return [Hash] map of passed in zones. If a zone if hosted on CloudFlare and the email + tkn combination is correct for the given zone, the value for the zone will be its zone id (use this for other API calls). Otherwise 0.

    def zone_check(*zones)
        send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
    end

    # This function pulls recent IPs hitting your site.
    #
    # @param zone [String]
    # @param hours [Integer] number of hours to go back. Default is 24, max is 48.
    # @param classification [String] (optional) restrict the result set to a given classification. Currently r|s|t, for regular, crawler, threat resp.
    # @param geo [Fixnum] (optional) set to 1 to add longitude and latitude information to response
    # @return [Hash] a list of IP addresses which hit your site classified by type

    def zone_ips(zone, classification = nil, hours = 24, geo = 1)
        send_req({a: :zone_ips, z: zone, hours: hours, class: classification, geo: geo})
    end

    # This function checks the threat score for a given IP.
    #
    # @note scores are logarithmically increasing, like the Richter scale.
    #
    # @param ip [Fixnum] IP address to check.
    # @return [Array] the current threat score for a given IP.

    def ip_lkup(ip)
        send_req({a: :ip_lkup, ip: ip})
    end

    # @param zone [String]
    # @return [Hash] all current settings for a given domain

    def zone_settings(zone)
        send_req({a: :zone_settings, z: zone})
    end

    # This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
    #
    # @param zone [String]
    # @param value [String] must be one of low|med|high|help|eoff.

    def sec_lvl(zone, value)
        send_req({a: :sec_lvl, z: zone, v: value})
    end

    # This function sets the Caching Level to Aggressive or Basic.
    #
    # @param zone [String]
    # @param value [String] must be one of agg|basic

    def cache_lvl(zone, value)
        send_req({a: :cache_lvl, z: zone, v: value})
    end

    # This function allows you to toggle Development Mode on or off for a particular domain. When Development Mode is on the cache is bypassed. Development mode remains on for 3 hours or until when it is toggled back off.
    #
    # @note Development mode will expire on "expires_on" (3 hours from when it is toggled on). Development mode can be toggled off immediately by setting +value+ to 0.
    #
    # @param zone [String]
    # @param value [Boolean] may be set to true (on) or false (off).
    # @return [Hash] expires_on

    def devmode(zone, value)
        send_req({a: :devmode, z: zone, v: value ? 1 : 0})
    end

    # This function will purge CloudFlare of any cached files. It may take up to 48 hours for the cache to rebuild and optimum performance to be achieved so this function should be used sparingly.
    #
    # @param zone The zone you'd like to run CNAMES through CloudFlare for, e.g. +example.com+.
    # @return (Hash) fpurge_ts, cooldawn
    # @return *fpurge_ts* - Time at which cache was purged.
    # @return *cooldown* - Number of seconds before the next time this call is allowed again.

    def purge_cache(zone)
        send_req({a: :fpurge_ts, z: zone, v: 1})
    end

    # This functions updates the snapshot of your site for CloudFlare's challenge page.
    #
    # @note Yhis call is rate limited to once per zone per day. Also the new image may take up to 1 hour to appear.
    #
    # @param zoneid Id of the zone you would like to check.

    def update_image(zoneid)
        send_req({a: :zone_grab, zid: zoneid})
    end

    # This function adds an IP address to your white lists.
    #
    # @param address The address you wish to set a rule for.
<commit_msg>rename purge_cache to fpurge_ts and update doc of this method<commit_after>require 'net/http'
require 'json'

# All public functions return (Hash) result: success or error with message and error code
#
# For more information please visit:
# - http://www.cloudflare.com/docs/client-api.html
# - http://www.cloudflare.com/docs/host-api.html
#
# Note: param zone - the zone you'd like to run CNAMES through CloudFlare for, e.g. +example.com+.

class CloudFlare

    # URL for Client and Host API

    URL_API = {
        client: 'https://www.cloudflare.com/api_json.html',
        host: 'https://api.cloudflare.com/host-gw.html'
    }

    TIMEOUT = 5 # Default is 5 seconds

    # @param api_key [String] user or Host API key.
    # @param email [String] it is for a Client API.
    def initialize(api_key, email = nil)
        @params = Hash.new

        if email.nil?
            @params[:api_key] = api_key
        else
            @params[:api_key] = api_key
            @params[:email] = email
        end

    end

    # CLIENT

    # This function can be used to get currently settings of values such as the security level.
    #
    # More: http://www.cloudflare.com/docs/client-api.html#FUNCTION:_Current_Stats_and_Settings
    #
    # @param zone [String]
    # @param interval [Integer] the interval parameter defines what period you want to look at. Default is 30 days, but 1 day delayed. Pro only intervals are 100, 110, and 120.
    # @return [Hash] the current stats and settings for a particular website

    def stats(zone, interval = 20)
        send_req({a: :stats, z: zone, interval: interval})
    end

    # @return [Hash] all domains in a CloudFlare account along with other data.

    def zone_load_multi
        send_req(a: :zone_load_multi)
    end

    # @param zone [String]
    # @return [Hash] all of the DNS records from a particular domain in a CloudFlare account
    def rec_load_all(zone)
        send_req({a: :rec_load_all, z: zone})
    end

    # This function checks whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
    #
    # @param zones [String or Array] like 'example.com, example2.com' or ['examaple.com', 'example2.com']
    # @return [Hash] map of passed in zones. If a zone if hosted on CloudFlare and the email + tkn combination is correct for the given zone, the value for the zone will be its zone id (use this for other API calls). Otherwise 0.

    def zone_check(*zones)
        send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
    end

    # This function pulls recent IPs hitting your site.
    #
    # @param zone [String]
    # @param hours [Integer] number of hours to go back. Default is 24, max is 48.
    # @param classification [String] (optional) restrict the result set to a given classification. Currently r|s|t, for regular, crawler, threat resp.
    # @param geo [Fixnum] (optional) set to 1 to add longitude and latitude information to response
    # @return [Hash] a list of IP addresses which hit your site classified by type

    def zone_ips(zone, classification = nil, hours = 24, geo = 1)
        send_req({a: :zone_ips, z: zone, hours: hours, class: classification, geo: geo})
    end

    # This function checks the threat score for a given IP.
    #
    # @note scores are logarithmically increasing, like the Richter scale.
    #
    # @param ip [Fixnum] IP address to check.
    # @return [Array] the current threat score for a given IP.

    def ip_lkup(ip)
        send_req({a: :ip_lkup, ip: ip})
    end

    # @param zone [String]
    # @return [Hash] all current settings for a given domain

    def zone_settings(zone)
        send_req({a: :zone_settings, z: zone})
    end

    # This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
    #
    # @param zone [String]
    # @param value [String] must be one of low|med|high|help|eoff.

    def sec_lvl(zone, value)
        send_req({a: :sec_lvl, z: zone, v: value})
    end

    # This function sets the Caching Level to Aggressive or Basic.
    #
    # @param zone [String]
    # @param value [String] must be one of agg|basic

    def cache_lvl(zone, value)
        send_req({a: :cache_lvl, z: zone, v: value})
    end

    # This function allows you to toggle Development Mode on or off for a particular domain. When Development Mode is on the cache is bypassed. Development mode remains on for 3 hours or until when it is toggled back off.
    #
    # @note Development mode will expire on "expires_on" (3 hours from when it is toggled on). Development mode can be toggled off immediately by setting +value+ to 0.
    #
    # @param zone [String]
    # @param value [Boolean] may be set to true (on) or false (off).
    # @return [Hash] expires_on

    def devmode(zone, value)
        send_req({a: :devmode, z: zone, v: value ? 1 : 0})
    end

    # This function will purge CloudFlare of any cached files. It may take up to 48 hours for the cache to rebuild and optimum performance to be achieved so this function should be used sparingly.
    #
    # @param zone [String]
    # @return [Hash] expires_on, zone

    def fpurge_ts(zone)
        send_req({a: :fpurge_ts, z: zone, v: 1})
    end

    # This functions updates the snapshot of your site for CloudFlare's challenge page.
    #
    # @note Yhis call is rate limited to once per zone per day. Also the new image may take up to 1 hour to appear.
    #
    # @param zoneid Id of the zone you would like to check.

    def update_image(zoneid)
        send_req({a: :zone_grab, zid: zoneid})
    end

    # This function adds an IP address to your white lists.
    #
    # @param address The address you wish to set a rule for.

{'fraction_non_alphanumeric': 0.08872206108172667, 'fraction_numerical': 0.006142296536427231, 'mean_word_length': 2.8398296757287915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4693381', 'n_tokens_mistral': 3688, 'n_tokens_neox': 3489, 'n_words': 1518}