<commit_before>require 'smsified'
require 'maestro_agent'

module MaestroDev
  class SmsifiedWorker < Maestro::MaestroWorker
    
    def validate_input_fields(fields)
      workitem['fields']['__error__'] = ''
      fields.each do |field|
        workitem['fields']['__error__'] += "Missing Field #{field}, " if workitem['fields'][field].nil? or workitem['fields'][field].to_s.empty?
      end
    end
    
    def send_sms
      
      write_output("Validating Inputs\n")
      validate_input_fields(['username','password','body','to','number'])
      return unless workitem['fields']['__error__'].empty?
      
      oneapi = Smsified::OneAPI.new(:username => workitem['fields']['username'],
                                    :password => workitem['fields']['password'])

      r = oneapi.send_sms :address => workitem.fields['to'],
                          :message => workitem.fields['body'],
                          :sender_address => Maestro.sms_config['number']

      if r.http.is_a? Net::HTTPCreated
        write_output "SMS sent to #{workitem.fields['to']} with #{workitem.fields['body']}\n"
        write_output "#{r.http.class}:#{r.data['resourceReference']}"

        return true

      elsif r.http.is_a? Net::HTTPUnauthorized
        write_output "Invalid credentials for sending SMS, check configuration.\n"
        workitem['fields']['__error__'] = "Invalid credentials for sending SMS, check configuration."

      elsif r.http.is_a? Net::HTTPBadRequest
        Maestro.log.error "Invalid (from) number for credentials used, check configuration."
        workitem['fields']['__error__'] = "Invalid (from) number for credentials used, check configuration."<commit_msg>hash fields correction<commit_after>require 'smsified'
require 'maestro_agent'

module MaestroDev
  class SmsifiedWorker < Maestro::MaestroWorker
    
    def validate_input_fields(fields)
      workitem['fields']['__error__'] = ''
      fields.each do |field|
        workitem['fields']['__error__'] += "Missing Field #{field}, " if workitem['fields'][field].nil? or workitem['fields'][field].to_s.empty?
      end
    end
    
    def send_sms
      
      write_output("Validating Inputs\n")
      validate_input_fields(['username','password','body','to','number'])
      return unless workitem['fields']['__error__'].empty?
      
      oneapi = Smsified::OneAPI.new(:username => workitem['fields']['username'],
                                    :password => workitem['fields']['password'])

      r = oneapi.send_sms :address => workitem['fields']['to'],
                          :message => workitem['fields']['body'],
                          :sender_address => workitem['fields']['number']

      if r.http.is_a? Net::HTTPCreated
        write_output "SMS sent to #{workitem['fields']['to']} with #{workitem['fields']['body']}\n"
        write_output "#{r.http.class}:#{r.data['resourceReference']}"

        return true

      elsif r.http.is_a? Net::HTTPUnauthorized
        write_output "Invalid credentials for sending SMS, check configuration.\n"
        workitem['fields']['__error__'] = "Invalid credentials for sending SMS, check configuration."

      elsif r.http.is_a? Net::HTTPBadRequest
        Maestro.log.error "Invalid (from) number for credentials used, check configuration."
        workitem['fields']['__error__'] = "Invalid (from) number for credentials used, check configuration."
{'fraction_non_alphanumeric': 0.14537444933920704, 'fraction_numerical': 0.0, 'mean_word_length': 3.2153465346534653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7354658', 'n_tokens_mistral': 948, 'n_tokens_neox': 948, 'n_words': 201}