<commit_before>require "volunteermatch/version"

require 'base64'
require 'digest/sha2'
require 'net/http'
require 'uri'
require 'json'
require 'ostruct'

module Volunteermatch
  class << self
    attr_accessor :attributes

    def initialize(api_username, api_key)
      @api_username   = api_username
      @api_key        = api_key
    end

    protected

    def call(action, json_query)
      nonce           = Digest::SHA2.hexdigest(rand.to_s)[0, 20]
      creation_time   = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S%z")
      password_digest = Base64.encode64(Digest::SHA2.digest(nonce + creation_time + @api_key)).chomp
      url             = URI.parse("http://www.volunteermatch.org/api/call?action=#{action.to_s}&query=" + URI.encode(json_query))

      req             = Net::HTTP::Get.new(url.request_uri)

      req.add_field('Content-Type', 'application/json')
      req.add_field('Authorization', 'WSSE profile="UsernameToken"')
      req.add_field('X-WSSE', 'UsernameToken Username="' + @api_username + '", PasswordDigest="' + password_<PASSWORD> + '", ' +
          'Nonce="' + nonce + '", Created="' + creation_time + '"')
<commit_msg>Rename class as Client and add ArgumentError<commit_after>require "volunteermatch/version"

require 'base64'
require 'digest/sha2'
require 'net/http'
require 'uri'
require 'json'
require 'ostruct'

module Volunteermatch
  class Client
    attr_accessor :attributes

    def initialize(api_username, api_key)
      raise ArgumentError, 'username and key need to be defined' if api_username.nil? || api_username.empty? || api_key.nil? || api_key.empty?
      @api_username   = api_username
      @api_key        = api_key
    end

    protected

    def call(action, json_query)
      nonce           = Digest::SHA2.hexdigest(rand.to_s)[0, 20]
      creation_time   = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S%z")
      password_digest = Base64.encode64(Digest::SHA2.digest(nonce + creation_time + @api_key)).chomp
      url             = URI.parse("http://www.volunteermatch.org/api/call?action=#{action.to_s}&query=" + URI.encode(json_query))

      req             = Net::HTTP::Get.new(url.request_uri)

      req.add_field('Content-Type', 'application/json')
      req.add_field('Authorization', 'WSSE profile="UsernameToken"')
      req.add_field('X-WSSE', 'UsernameToken Username="' + @api_username + '", PasswordDigest="' + <PASSWORD> + '", ' +
          'Nonce="' + nonce + '", Created="' + creation_time + '"')

{'fraction_non_alphanumeric': 0.148582995951417, 'fraction_numerical': 0.009716599190283401, 'mean_word_length': 3.4683544303797467, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7181932', 'n_tokens_mistral': 853, 'n_tokens_neox': 812, 'n_words': 142}