<commit_before>#!/usr/bin/ruby

require 'net/http'
require 'json'
require 'uri'

class CodeForKids
  class McMyAdminAPI
    sessionID = ""

    #initializes the connection. Sets the sessionID
    #host and port will be arguments for every function

    def initialize(host, user, pass, port = '8080')
      url = URI.parse("#{host}:#{port}/data.json?Username=#{user}&Password=#{<PASSWORD>}&Token=&req=login&MCMASESSIONID=")
      http = Net::HTTP.new url.host, url.port
      response = http.get("#{url.path}?#{url.query.to_s}", {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
      data = response.body

      case response
      when Net::HTTPRedirection
        # repeat the request using response['Location']
      when Net::HTTPSuccess
        json_response = JSON.parse response.body
        sessionID = json_response['MCMASESSIONID']
      else
        # response code isn't a 200; raise an exception
        response.error!
      end

    end

    #AddGroupValue
    # Arguments:
    ##########
    # group - The group affected - string
    ##########
    # type - controls which info is changed - string
    # type takes one of the following:
    # groupslist (No group needs to be specified, used to add new groups)
    # groupmembers (Add the user in 'value' as a member)
    # groupcommands (Add the command in 'value' as a member)
    # Color
    # Inherits
    # CanBuild
    # CanInteract
    # Prefix
    # Suffix
    ##########
    # value - the value to be set by the method
    # CanBuild and CanInteract take boolean
    # the rest take string

    def add_group_value(host, port, group, type, value)
      url = URI.parse("#{host}:#{port}/data.json?req=addgroupvalue&group=#{group}&type=#{type}&value=#{value}")
      http = Net::HTTP.new url.host, url.port
      response = http.get("#{url.path}?#{url.query.to_s}", {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
      data = response.body

      when Net::HTTPSuccess
        #worked
      else
        # response code isn't a 200; raise an exception
        response.error!
      end
  end
end

cfk_api = CodeForKids::McMyAdminAPI.new('host', 'username', 'password')
cfk_api.getStatus()
<commit_msg>Clean up code<commit_after>#!/usr/bin/ruby

require 'net/http'
require 'json'
require 'uri'

class CodeForKids
  class McMyAdminAPI
    sessionID = ""
    host = ""
    port = ""

    #initializes the connection. Sets the sessionID
    #host and port will be arguments for every function

    def initialize(host, user, pass, port = '8080')
      self.host = host
      self.port = port
      login(user, pass)
    end

    #AddGroupValue
    # Arguments:
    ##########
    # group - The group affected - string
    ##########
    # type - controls which info is changed - string
    # type takes one of the following:
    # groupslist (No group needs to be specified, used to add new groups)
    # groupmembers (Add the user in 'value' as a member)
    # groupcommands (Add the command in 'value' as a member)
    # Color
    # Inherits
    # CanBuild
    # CanInteract
    # Prefix
    # Suffix
    ##########
    # value - the value to be set by the method
    # CanBuild and CanInteract take boolean
    # the rest take string

    def add_group_value(group, type, value)
      url = URI.parse("#{@host}:#{@port}/data.json?req=addgroupvalue&group=#{group}&type=#{type}&value=#{value}")
      request(url)
    end
    
    private
    
    def request(url)
      http = Net::HTTP.new url.host, url.port
      response = http.get("#{url.path}?#{url.query.to_s}", {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
      data = response.body

      when Net::HTTPSuccess
        #worked
      else
        # response code isn't a 200; raise an exception
        response.error!
      end
    end
    
    def login(user, pass)
      url = URI.parse("#{@host}:#{@port}/data.json?Username=#{user}&Password=#{<PASSWORD>}&Token=&req=login&MCMASESSIONID=")
      
      http = Net::HTTP.new url.host, url.port
      response = http.get("#{url.path}?#{url.query.to_s}", {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
      data = response.body

      case response
      when Net::HTTPRedirection
        # repeat the request using response['Location']
      when Net::HTTPSuccess
        json_response = JSON.parse response.body
        sessionID = json_response['MCMASESSIONID']
      else
        # response code isn't a 200; raise an exception
        response.error!
      end
    end
end

cfk_api = CodeForKids::McMyAdminAPI.new('host', 'username', 'password')
cfk_api.getStatus()

{'fraction_non_alphanumeric': 0.133734680713825, 'fraction_numerical': 0.0043001505052676844, 'mean_word_length': 2.8288065843621397, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5373448', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1417, 'n_words': 397}