tika-client 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/tika/client.rb +14 -17
- data/lib/tika/endpoints.rb +18 -0
- data/lib/tika/request.rb +35 -13
- data/lib/tika/requests.rb +19 -0
- metadata +3 -2
- data/lib/tika/api.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bb963d542e83e8d690b3e243bf05a155ec22391
|
4
|
+
data.tar.gz: 7776e59b7a1210326b8006f3891dfb78f14cf9c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09198bec1ef7e2f79d0bee0b2b7762dc438ef3e5f821f52c000f297526a82d6e145d46a8e5b6ad17c9244f1dda5a978e96c9cb0bdc0aacf90269438165f16a5a
|
7
|
+
data.tar.gz: e058fd18fb370a579d21a58a1c227313d81000bc5a6e27344fb42a0c6a14c6a89644070fc435a5f6a68d1432f42db2ae77ee84848565c981fadaf98f16a08e2e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/tika/client.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require_relative "configuration"
|
2
|
-
require_relative "
|
3
|
-
require_relative "request"
|
4
|
-
require "forwardable"
|
2
|
+
require_relative "requests"
|
5
3
|
|
6
4
|
module Tika
|
7
5
|
class Client
|
8
|
-
|
6
|
+
|
7
|
+
include Requests
|
9
8
|
|
10
9
|
class << self
|
11
10
|
def config
|
@@ -17,31 +16,29 @@ module Tika
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
|
-
def_delegators :api, :endpoint, :has_endpoint?
|
19
|
+
attr_reader :host, :port
|
22
20
|
|
23
21
|
def initialize(opts={})
|
24
22
|
@host = opts.fetch(:host, config.host)
|
25
23
|
@port = opts.fetch(:port, config.port)
|
26
|
-
@api = Api.new
|
27
24
|
end
|
28
25
|
|
29
|
-
def
|
30
|
-
|
26
|
+
def get_text(opts={})
|
27
|
+
GetTextRequest.execute(connection, opts)
|
31
28
|
end
|
32
29
|
|
33
|
-
def
|
34
|
-
|
30
|
+
def get_metadata(opts={})
|
31
|
+
GetMetadataRequest.execute(connection, opts)
|
35
32
|
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
private
|
35
|
+
|
36
|
+
def config
|
37
|
+
self.class.config
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
43
|
-
|
44
|
-
super
|
40
|
+
def connection
|
41
|
+
@connection ||= Net::HTTP.new(host, port)
|
45
42
|
end
|
46
43
|
|
47
44
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module Tika
|
4
|
+
module Endpoints
|
5
|
+
|
6
|
+
PUT = Net::HTTP::Put
|
7
|
+
GET = Net::HTTP::Get
|
8
|
+
|
9
|
+
JSON = "application/json"
|
10
|
+
TEXT = "text/plain"
|
11
|
+
|
12
|
+
Endpoint = Struct.new(:request_method, :path, :response_format)
|
13
|
+
|
14
|
+
GetTextEndpoint = Endpoint.new(PUT, "/tika", TEXT)
|
15
|
+
GetMetadataEndpoint = Endpoint.new(PUT, "/meta", JSON)
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/tika/request.rb
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
require "uri"
|
2
2
|
require "net/http"
|
3
3
|
require "delegate"
|
4
|
-
# require "mime-types"
|
5
4
|
|
6
5
|
module Tika
|
7
|
-
# Executes an API method
|
8
6
|
class Request < SimpleDelegator
|
9
7
|
|
10
|
-
|
8
|
+
class << self
|
9
|
+
attr_accessor :endpoint
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :connection
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def self.execute(connection, opts={})
|
15
|
+
request = new(connection)
|
16
|
+
yield request if block_given?
|
17
|
+
request.execute(opts)
|
18
|
+
end
|
17
19
|
|
18
|
-
def initialize(connection
|
20
|
+
def initialize(connection)
|
19
21
|
@connection = connection
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
self["Accept"] = endpoint.response_format
|
22
|
+
super build_request
|
23
|
+
set_defaults
|
24
|
+
post_initialize
|
24
25
|
end
|
25
26
|
|
26
27
|
def execute(opts={})
|
@@ -30,9 +31,30 @@ module Tika
|
|
30
31
|
self.content_length = file.size
|
31
32
|
end
|
32
33
|
self.content_type = opts[:content_type] if opts[:content_type]
|
34
|
+
yield self if block_given?
|
33
35
|
conn.request(__getobj__)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
39
|
+
def endpoint
|
40
|
+
self.class.endpoint
|
41
|
+
end
|
42
|
+
|
43
|
+
def uri
|
44
|
+
@uri ||= URI::HTTP.build(host: connection.address, port: connection.port, path: endpoint.path)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def post_initialize; end
|
50
|
+
|
51
|
+
def build_request
|
52
|
+
endpoint.request_method.new(uri)
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_defaults
|
56
|
+
self["Accept"] = endpoint.response_format
|
57
|
+
end
|
58
|
+
|
37
59
|
end
|
38
60
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "request"
|
2
|
+
require_relative "endpoints"
|
3
|
+
|
4
|
+
module Tika
|
5
|
+
module Requests
|
6
|
+
|
7
|
+
include Endpoints
|
8
|
+
|
9
|
+
def self.request_class(endpoint)
|
10
|
+
klass = Class.new(Request)
|
11
|
+
klass.endpoint = endpoint
|
12
|
+
klass
|
13
|
+
end
|
14
|
+
|
15
|
+
GetTextRequest = request_class GetTextEndpoint
|
16
|
+
GetMetadataRequest = request_class GetMetadataEndpoint
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tika-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dchandekstark
|
@@ -67,10 +67,11 @@ files:
|
|
67
67
|
- Rakefile
|
68
68
|
- VERSION
|
69
69
|
- lib/tika-client.rb
|
70
|
-
- lib/tika/api.rb
|
71
70
|
- lib/tika/client.rb
|
72
71
|
- lib/tika/configuration.rb
|
72
|
+
- lib/tika/endpoints.rb
|
73
73
|
- lib/tika/request.rb
|
74
|
+
- lib/tika/requests.rb
|
74
75
|
- spec/spec_helper.rb
|
75
76
|
- tika-client.gemspec
|
76
77
|
homepage: https://github.com/duke-libraries/tika-client
|
data/lib/tika/api.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Tika
|
2
|
-
class Api
|
3
|
-
|
4
|
-
PUT = Net::HTTP::Put
|
5
|
-
GET = Net::HTTP::Get
|
6
|
-
|
7
|
-
JSON = "application/json"
|
8
|
-
TEXT = "text/plain"
|
9
|
-
|
10
|
-
Endpoint = Struct.new(:request_method, :path, :response_format)
|
11
|
-
|
12
|
-
ENDPOINTS = {
|
13
|
-
get_metadata: Endpoint.new(PUT, "/meta", JSON),
|
14
|
-
get_text: Endpoint.new(PUT, "/tika", TEXT)
|
15
|
-
}
|
16
|
-
|
17
|
-
def endpoint(name)
|
18
|
-
ENDPOINTS.fetch(name)
|
19
|
-
end
|
20
|
-
|
21
|
-
def has_endpoint?(name)
|
22
|
-
ENDPOINTS.include?(name)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|