<commit_before>class MuninnAdapter

  def self.custom_query(json_string, page, per_page )
    muninn_host = Huginn::Application::CONFIG["muninn_host"]
    muninn_port = Huginn::Application::CONFIG["muninn_port"]

    muninn_response = HTTParty.get("http://#{muninn_host}:#{muninn_port}/search/custom/query", { :body => json_string,
    :headers => { 'Content-Type' => 'application/json'} })

    output_string= ActiveSupport::JSON.decode(muninn_response.body.to_json)

    results= MuninnAdapter.extract_results(output_string)

    results = results.sort_by { |k| "#{k[:sort_name]}"}

    results.paginate(page: page, per_page: per_page)

   end



  def self.extract_results(search_response)
    response_hash = JSON.parse(search_response)
    if !response_hash.has_key?("result")
      LogTime.info("No contents.")
      return []
    end
    output = []
    response_hash["result"]["hits"]["hits"].each do |hit|

      node ={
        :id => hit["_id"].to_i,
        :type => hit["_type"],
        :score => hit["_score"],
        :data => hit["_source"],
        :sort_name =>hit["_source"]["name"]
      }
      if hit["highlight"] != nil
        if hit["highlight"]["name"] != nil
          node1  = {:m_name => hit["highlight"]["name"][0]}
          node.merge!(node1)
        end
        if hit["highlight"]["definition"] != nil
          node2 ={:m_definition => hit["highlight"]["definition"][0]}
          node.merge!(node2)
        end
      end

      output << node

    end

    return output

  end<commit_msg>added methods for each http action<commit_after>class MuninnAdapter




  def self.post( resource_uri, body )
    req = Net::HTTP::Post.new( resource_uri )
    req["Content-Type"] = "application/json"
    req.body = body

    MuninnAdapter.perform( req )

  end

  def self.delete( resource_uri )
    req = Net::HTTP::Delete.new( resource_uri )
    req.body = nil
    MuninnAdapter.perform( req )
  end

  def self.put( resource_uri, body )
    req = Net::HTTP::Put.new( resource_uri )
    req["Content-Type"] = "application/json"
    req.body = body
    MuninnAdapter.perform( req )
  end


  def self.get( resource_uri )

    http = MuninnAdapter.new_http_request

    http.use_ssl = Huginn::Application::CONFIG["muninn_uses_ssl"]

    if !Huginn::Application::CONFIG["validate_muninn_certificate"]
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE #for when Muninn is using a self-signed cert
    end

    if Huginn::Application::CONFIG["muninn_uses_ssl"]
      muninn_response = http.get("https://#{muninn_host}:#{muninn_port}/#{resource_uri}")
    else
      muninn_response = http.get("http://#{muninn_host}:#{muninn_port}/#{resource_uri}")
    end

    JSON.parse(muninn_response.body)
  end

  private
  def self.new_http_request
    Net::HTTP.new( Huginn::Application::CONFIG["muninn_host"], Huginn::Application::CONFIG["muninn_port"] )
  end

  def self.perform( req )
    response = MuninnAdapter.new_http_request.start do |http|
      http.request(req)
    end
  end
{'fraction_non_alphanumeric': 0.14675540765391015, 'fraction_numerical': 0.0019966722129783694, 'mean_word_length': 3.4011713030746704, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '3192975', 'n_tokens_mistral': 997, 'n_tokens_neox': 978, 'n_words': 173}