<commit_before>require "cryptsy/api/version"
require "httparty"
require "uri"
require "openssl"
require "json"

module Cryptsy
  module API
    class PublicMethod
      include HTTParty
      base_uri "http://pubapi.cryptsy.com"

      def execute_method(all_markets, single_market, marketid)
        api_method = marketid.nil? ? all_markets : single_market
        query = {method: api_method}
        query["marketid"] = marketid if marketid

        response = self.class.get("/api.php", query: query)
        begin
          response_body = JSON.parse(response.body)
          response = [true, response_body]
        rescue => e
          response = [false, e.response]
        end

        response
      end
    end

    class PrivateMethod
      include HTTParty
      base_uri "https://api.cryptsy.com"

      def initialize(key=nil, secret=nil)
        @key = key
        @secret = secret
      end

      def execute_method(method_name, params)
        post_data = {method: method_name, nonce: nonce}.merge(params)
        post_body = URI.encode_www_form(post_data)

        response = self.class.post("/api",
                           headers: { "User-Agent" => "Mozilla/4.0 (compatible; Cryptsy API ruby client)",
                                    "Sign" => signed_message(post_body),
                                    "Key" => @key,
                           },
                           body: post_data)
        begin
          response_body = JSON.parse(response.body)
          response = [true, response_body]
        rescue => e
          response = [false, e.response]
        end

        response
      end

      def auth_changed?(key, secret)
        return @key == key && @secret == secret
      end

     private

       def nonce
         Time.now.to_i
       end

       def signed_message(msg)
         OpenSSL::HMAC.hexdigest('sha512', @secret, msg)
       end

    end
<commit_msg>send exception in case of an error from private/public api<commit_after>require "cryptsy/api/version"
require "httparty"
require "uri"
require "openssl"
require "json"

module Cryptsy
  module API
    class PublicMethod
      include HTTParty
      base_uri "http://pubapi.cryptsy.com"

      def execute_method(all_markets, single_market, marketid)
        api_method = marketid.nil? ? all_markets : single_market
        query = {method: api_method}
        query["marketid"] = marketid if marketid

        response = self.class.get("/api.php", query: query)
        begin
          response_body = JSON.parse(response.body)
          response = [true, response_body]
        rescue => e
          response = [false, e]
        end

        response
      end
    end

    class PrivateMethod
      include HTTParty
      base_uri "https://api.cryptsy.com"

      def initialize(key=nil, secret=nil)
        @key = key
        @secret = secret
      end

      def execute_method(method_name, params)
        post_data = {method: method_name, nonce: nonce}.merge(params)
        post_body = URI.encode_www_form(post_data)

        response = self.class.post("/api",
                           headers: { "User-Agent" => "Mozilla/4.0 (compatible; Cryptsy API ruby client)",
                                    "Sign" => signed_message(post_body),
                                    "Key" => @key,
                           },
                           body: post_data)
        begin
          response_body = JSON.parse(response.body)
          response = [true, response_body]
        rescue => e
          response = [false, e]
        end

        response
      end

      def auth_changed?(key, secret)
        return @key == key && @secret == secret
      end

     private

       def nonce
         Time.now.to_i
       end

       def signed_message(msg)
         OpenSSL::HMAC.hexdigest('sha512', @secret, msg)
       end

    end

{'fraction_non_alphanumeric': 0.09340232858990945, 'fraction_numerical': 0.00258732212160414, 'mean_word_length': 1.7437899219304471, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2179494', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1073, 'n_words': 267}