lib/tika/requests.rb in tika-client-0.1.1 vs lib/tika/requests.rb in tika-client-0.2.0
- old
+ new
@@ -1,19 +1,63 @@
+require "json"
+require "net/http"
require_relative "request"
-require_relative "endpoints"
module Tika
module Requests
- include Endpoints
+ PUT = Net::HTTP::Put
+ GET = Net::HTTP::Get
- def self.request_class(endpoint)
- klass = Class.new(Request)
- klass.endpoint = endpoint
- klass
+ class TextRequest < Request
+ def self.headers
+ {"Accept" => "text/plain"}
+ end
end
- GetTextRequest = request_class GetTextEndpoint
- GetMetadataRequest = request_class GetMetadataEndpoint
+ class JSONRequest < Request
+ def self.headers
+ {"Accept" => "application/json"}
+ end
+
+ def handle_response(response)
+ JSON.load(response.body)
+ end
+ end
+
+ class GetTextRequest < TextRequest
+ self.http_method = PUT
+ self.path = "/tika"
+ end
+
+ class GetMetadataRequest < JSONRequest
+ self.http_method = PUT
+ self.path = "/meta"
+ end
+
+ class GetVersionRequest < Request
+ self.http_method = GET
+ self.path = "/version"
+ end
+
+ class GetMimeTypesRequest < JSONRequest
+ self.http_method = GET
+ self.path = "/mime-types"
+ end
+
+ class GetParsersRequest < JSONRequest
+ self.http_method = GET
+ self.path = "/parsers"
+ end
+
+ class GetParsersDetailsRequest < JSONRequest
+ self.http_method = GET
+ self.path = "/parsers/details"
+ end
+
+ class GetDetectorsRequest < JSONRequest
+ self.http_method = GET
+ self.path = "/detectors"
+ end
end
end