<commit_before>require 'net/http'

module EmailApiHelper
  def parse_nps_response(response)
    result = {}
    if response['data'] && response['data'][0] && response['data'][0]['attributes']
      data = response['data'][0]['attributes']
      result['nps'] = data['nps'].round(2)
      result['respondents'] = [data['promoters'], data['passives'], data['detractors']]
    end
    result
  end

  def parse_comment_response(response)
    results = []
    response['responses'] && response['responses'].each do |resp|
      # only collect feedback responses if there was a comment left
      if resp['feedback']
        result = {}
        result['rating'] = resp['rating']
        result['feedback'] = resp['feedback']
        results << result
      end     
    end
    results
  end

  def get_satismeter_nps_data(start_time, end_time)
    uri = URI.parse("https://app.satismeter.com/api/v2/response-statistics?startDate=#{start_time}&endDate=#{end_time}&project=#{ENV['SATISMETER_PROJECT_KEY']}")
    request = Net::HTTP::Get.new(uri)
    request["Authkey"] = ENV['SATISMETER_AUTH_KEY']
    req_options = { use_ssl: uri.scheme == "https" }<commit_msg>move conditional to if block<commit_after>require 'net/http'

module EmailApiHelper
  def parse_nps_response(response)
    result = {}
    if response['data'] && response['data'][0] && response['data'][0]['attributes']
      data = response['data'][0]['attributes']
      result['nps'] = data['nps'].round(2)
      result['respondents'] = [data['promoters'], data['passives'], data['detractors']]
    end
    result
  end

  def parse_comment_response(response)
    results = []
    if response['responses']     
      response['responses'].each do |resp|
        # only collect feedback responses if there was a comment left
        if resp['feedback']
          result = {}
          result['rating'] = resp['rating']
          result['feedback'] = resp['feedback']
          results << result
        end     
      end
    end
    results
  end

  def get_satismeter_nps_data(start_time, end_time)
    uri = URI.parse("https://app.satismeter.com/api/v2/response-statistics?startDate=#{start_time}&endDate=#{end_time}&project=#{ENV['SATISMETER_PROJECT_KEY']}")
    request = Net::HTTP::Get.new(uri)
    request["Authkey"] = ENV['SATISMETER_AUTH_KEY']
    req_options = { use_ssl: uri.scheme == "https" }
{'fraction_non_alphanumeric': 0.15834038950042337, 'fraction_numerical': 0.004233700254022015, 'mean_word_length': 3.660749506903353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1685223', 'n_tokens_mistral': 744, 'n_tokens_neox': 740, 'n_words': 136}