Sha256: c80af1dae2ab5f52d26a4d22252fa97b6f3052c47289f420c40a073faf8db75e

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

require_relative "configuration"
require_relative "api"
require_relative "request"
require "forwardable"

module Tika
  class Client
    extend Forwardable

    class << self
      def config
        @config ||= Configuration.new
      end

      def configure
        yield config
      end
    end

    attr_accessor :host, :port, :api
    def_delegators :api, :endpoint, :has_endpoint?

    def initialize(opts={})
      @host = opts.fetch(:host, config.host)
      @port = opts.fetch(:port, config.port)
      @api = Api.new
    end

    def config
      self.class.config
    end

    def connection
      @connection ||= Net::HTTP.new(host, port)
    end

    def execute(name, opts={})
      request = Request.new(connection, endpoint(name))
      request.execute(opts)
    end

    def method_missing(name, *args)
      return execute(name, *args) if has_endpoint?(name)
      super
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tika-client-0.1.0 lib/tika/client.rb