Sha256: 9568271d710dd645f80e8b77cff848ebc845e1a4686c58260a79f28de387e0e4

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module EZAPIClient
  class GenData

    include Virtus.model
    attribute :username, String
    attribute :password, String
    attribute :prv_path, String
    attribute :eks_path, String
    attribute :reference_no, String
    attribute :message, Hash
    attribute :json, String, lazy: true, default: :default_json
    attribute :command, String, lazy: true, default: :default_command
    attribute :logger, Object
    attribute :log, Boolean

    def self.call(attributes)
      self.new(attributes).()
    end

    def call
      if log
        logger.info(EZAPIClient::LOG_PROGNAME) { command }
      end
      ExecCommand.(command)
    end

    private

    def default_command
      [
        "java -cp",
        JAR_PATH,
        "ezpadala.EZdata",
        prv_path,
        eks_path,
        username,
        password,
        reference_no,
        "'#{Shellwords.escape(json)}'",
      ].join(" ")
    end

    def default_json
      message.each_with_object({}) do |(key, value), hash|
        hash[key.to_s.camelcase(:lower)] = value
      end.to_json
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ezapi_client-1.0.2 lib/ezapi_client/services/gen_data.rb