<commit_before>require 'httparty'
require 'forwardable'
require 'cgi'
require 'mime/types'

module Preposterous
  
  class InvalidEmailOrPassword  < StandardError; end
  class InvalidSiteId           < StandardError; end
  class UserDoesNotHaveAccess   < StandardError; end
  class UnableToSave            < StandardError; end
  class UnableToFindObject      < StandardError; end
  class InvalidDate             < StandardError; end
  class InvalidPostId           < StandardError; end
  class CommentsDisabled        < StandardError; end
  class UnableToSaveComment     < StandardError; end
  class ApiRateLimitReached     < StandardError; end

  def self.make_friendly(response)
    raise_errors(response)
    Crack::XML.parse(response.body)["rsp"] if not response.nil?
  end

  def self.raise_errors(response)
    response.body =~ /code="(\d+)" msg="(.*)"/
    code = $1.to_i
    # going to pass this to the exception at some point
    msg = $2

    case code
      when 3001
        raise InvalidEmailOrPassword
      when 3002
        raise InvalidSiteId
      when 3003
        raise UserDoesNotHaveAccess
      when 3004
        raise UnableToSave
      when 3005
        raise UnableToFindObject
      when 3006
        raise InvalidDate
      when 3007
        raise InvalidPostId
      when 3008
        raise CommentsDisabled
      when 3009
        raise UnableToSaveComment
      when 3010
        raise ApiRateLimitReached
    end
  end

end

# bring in all of the files in the lib dir
directory = File.expand_path(File.dirname(__FILE__))
require File.join(directory, "preposterous", "base")
require File.join(directory, "preposterous", "httpauth")
require File.join(directory, "preposterous", "request")
<commit_msg>Exception raising passes the error message as well<commit_after>require 'httparty'
require 'forwardable'
require 'cgi'
require 'mime/types'

module Preposterous

  class InvalidEmailOrPassword  < StandardError; end
  class InvalidSiteId           < StandardError; end
  class UserDoesNotHaveAccess   < StandardError; end
  class UnableToSave            < StandardError; end
  class UnableToFindObject      < StandardError; end
  class InvalidDate             < StandardError; end
  class InvalidPostId           < StandardError; end
  class CommentsDisabled        < StandardError; end
  class UnableToSaveComment     < StandardError; end
  class ApiRateLimitReached     < StandardError; end

  def self.make_friendly(response)
    raise_errors(response)
    Crack::XML.parse(response.body)["rsp"] if not response.nil?
  end

  def self.raise_errors(response)
    response.body =~ /code="(\d+)" msg="(.*)"/
    code = $1.to_i
    # going to pass this to the exception at some point... maybe
    msg = $2

    case code
      when 3001
        raise InvalidEmailOrPassword, msg
      when 3002
        raise InvalidSiteId, msg
      when 3003
        raise UserDoesNotHaveAccess, msg
      when 3004
        raise UnableToSave, msg
      when 3005
        raise UnableToFindObject, msg
      when 3006
        raise InvalidDate, msg
      when 3007
        raise InvalidPostId, msg
      when 3008
        raise CommentsDisabled, msg
      when 3009
        raise UnableToSaveComment, msg
      when 3010
        raise ApiRateLimitReached, msg
    end
  end

end

# bring in all of the files in the lib dir
directory = File.expand_path(File.dirname(__FILE__))
require File.join(directory, "preposterous", "base")
require File.join(directory, "preposterous", "httpauth")
require File.join(directory, "preposterous", "request")

{'fraction_non_alphanumeric': 0.06664791901012374, 'fraction_numerical': 0.023622047244094488, 'mean_word_length': 2.8329741379310347, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4076869', 'n_tokens_mistral': 1071, 'n_tokens_neox': 987, 'n_words': 310}