<commit_before>require 'digest'

require 'klarna/methods/get_addresses'
require 'klarna/methods/reserve_amount'

module Klarna
  class Client
    VERSION = '4.1'
    NAME    = 'ruby_client'

    def initialize(options = {})
      @hostname     = options[:hostname]     || Klarna.configuration.hostname
      @port         = options[:port]         || Klarna.configuration.port
      @store_id     = options[:store_id]     || Klarna.configuration.store_id
      @store_secret = options[:store_secret] || Klarna.configuration.store_secret
    end

    def get_addresses(params)
      call_method(Klarna::Methods::GetAddresses, params)
    end

    def self.get_addresses(params)
      new.get_addresses(params)
    end

    def reserve_amount(params)
      call_method(Klarna::Methods::ReserveAmount, params)
    end

    def self.reserve_amount(params)
      new.reserve_amount(params)
    end

    private

    def call_method(method, params)
      connection.call(method.name, VERSION, NAME, *method.params(@store_id, @store_secret, params))
    end

    def connection
      @connection ||= Klarna::Connection.new(@hostname, @port)
    end

  end
end<commit_msg>Add support for 'activate' method in Klarna client and change calls for other methods accordingly<commit_after>require 'klarna/methods/get_addresses'
require 'klarna/methods/reserve_amount'
require 'klarna/methods/activate'

module Klarna
  class Client
    KLARNA_API_VERSION = '4.1'
    CLIENT_NAME        = 'ruby_client'

    def initialize(options = {})
      @hostname     = options[:hostname]     || Klarna.configuration.hostname
      @port         = options[:port]         || Klarna.configuration.port
      @store_id     = options[:store_id]     || Klarna.configuration.store_id
      @store_secret = options[:store_secret] || Klarna.configuration.store_secret
    end

    def get_addresses(params)
      call_method(Klarna::Methods::GetAddresses, params)
    end

    def self.get_addresses(params)
      new.get_addresses(params)
    end

    def reserve_amount(params)
      call_method(Klarna::Methods::ReserveAmount, params)
    end

    def self.reserve_amount(params)
      new.reserve_amount(params)
    end

    def activate(params)
      call_method(Klarna::Methods::Activate, params)
    end

    def self.activate(params)
      new.activate(params)
    end

    private

    def call_method(method, params)
      method_params = method.params(@store_id, @store_secret, KLARNA_API_VERSION, CLIENT_NAME, params)
      connection.call(method.name, KLARNA_API_VERSION, CLIENT_NAME, *method_params)
    end

    def connection
      @connection ||= Klarna::Connection.new(@hostname, @port)
    end

  end
end
{'fraction_non_alphanumeric': 0.09821428571428571, 'fraction_numerical': 0.001488095238095238, 'mean_word_length': 3.2955271565495208, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5407691', 'n_tokens_mistral': 843, 'n_tokens_neox': 816, 'n_words': 158}