<commit_before>require 'net/https'
require 'smstraderb/constants'
require 'smstraderb/response'

class SMSTradeRB
  class InvalidRoute < Exception; end
  class InvalidOption < Exception; end
  class InvalidFormat < Exception; end

  attr_reader :key, :message, :to, :from, :route, :debug, :charset

  def initialize(options = {})
    @charset = 'UTF-8'

    @key = options[:key]
    @message = options[:message]
    @to = check_phone_number(options[:to])
    @route = check_route(options[:route]) || SMSTradeRB::DEFAULT_ROUTE
    @from = options[:from]
    @debug = options[:debug] ? 1 : 0

    check_from_allowed(@from, @route)
    check_value_length(@from, 11) if @from

    @message = escape(@message)
    @from = escape(@from)
  end

  def send(options)
    @to = escape(check_phone_number(options[:to]))
    @message = escape(options[:message])

    uri = URI.parse(SMSTradeRB::HTTP_GATEWAY)
    http = Net::HTTP.new(uri.host, uri.port)
    #http.use_ssl = true if uri.scheme == "https"  # enable SSL/TLS

    response = http.start do
      http.request_get(build_request)
    end

    SMSTradeRB::Response.new(response.body)
  end

  private
    def build_request
      options = {
        :key => key,
        :message => message,
        :to => to,
        :route => route,
        :from => from,
        :debug => debug,
        :charset => charset
      }.map do |key, value|
        [key, value].join('=') if value
      end.compact

      "/?#{options.join('&')}"
    end

    def check_phone_number(number)
      if number and number.to_s !~ %r{^\+?[\s0-9\-\(\)]+$}
        raise SMSTradeRB::InvalidFormat, "Invalid phone number: #{number}"
      else
        sanitize_phone_number(number)
      end<commit_msg>Added Delivery Report attribute<commit_after>require 'net/https'
require 'smstraderb/constants'
require 'smstraderb/response'

class SMSTradeRB
  class InvalidRoute < Exception; end
  class InvalidOption < Exception; end
  class InvalidFormat < Exception; end

  attr_reader :key, :message, :to, :from, :route, :debug, :charset, :dlr

  def initialize(options = {})
    @charset = 'UTF-8'

    @key = options[:key]
    @message = options[:message]
    @to = check_phone_number(options[:to])
    @route = check_route(options[:route]) || SMSTradeRB::DEFAULT_ROUTE
    @from = options[:from]
    @debug = options[:debug] ? 1 : 0
    @dlr = options[:dlr] || 0
    check_from_allowed(@from, @route)
    check_value_length(@from, 11) if @from

    @message = escape(@message)
    @from = escape(@from)
  end

  def send(options)
    @to = escape(check_phone_number(options[:to]))
    @message = escape(options[:message])

    uri = URI.parse(SMSTradeRB::HTTP_GATEWAY)
    http = Net::HTTP.new(uri.host, uri.port)
    #http.use_ssl = true if uri.scheme == "https"  # enable SSL/TLS

    response = http.start do
      http.request_get(build_request)
    end

    SMSTradeRB::Response.new(response.body)
  end

  private
    def build_request
      options = {
        :key => key,
        :message => message,
        :to => to,
        :route => route,
        :from => from,
        :debug => debug,
        :charset => charset,
        :dlr => dlr
      }.map do |key, value|
        [key, value].join('=') if value
      end.compact

      "/?#{options.join('&')}"
    end

    def check_phone_number(number)
      if number and number.to_s !~ %r{^\+?[\s0-9\-\(\)]+$}
        raise SMSTradeRB::InvalidFormat, "Invalid phone number: #{number}"
      else
        sanitize_phone_number(number)
      end
{'fraction_non_alphanumeric': 0.14395229982964225, 'fraction_numerical': 0.004258943781942078, 'mean_word_length': 2.9144444444444444, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, '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': '461983', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1155, 'n_words': 264}