tika-client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a520c2018bc2474f7006b3dc2defca7ba0dd051
4
- data.tar.gz: 33a1f20b73f45f6f4c3f46a58136569041dac139
3
+ metadata.gz: 3bb963d542e83e8d690b3e243bf05a155ec22391
4
+ data.tar.gz: 7776e59b7a1210326b8006f3891dfb78f14cf9c8
5
5
  SHA512:
6
- metadata.gz: a2adeecc540ee13117e32848226d8616f833a82103caa7ebb6d09185948c22dc753801499e9f3c355bc43cf7fef8d7cf6372737462a7cfcd60692a04cb42ce1b
7
- data.tar.gz: 6461f28df9c2975bb0e707dff6fac55ec1141b5fdd157bafa57c00d298491759c2392d7a571ab814b863e463c0188686053e3267e43428cce3a093d32a915897
6
+ metadata.gz: 09198bec1ef7e2f79d0bee0b2b7762dc438ef3e5f821f52c000f297526a82d6e145d46a8e5b6ad17c9244f1dda5a978e96c9cb0bdc0aacf90269438165f16a5a
7
+ data.tar.gz: e058fd18fb370a579d21a58a1c227313d81000bc5a6e27344fb42a0c6a14c6a89644070fc435a5f6a68d1432f42db2ae77ee84848565c981fadaf98f16a08e2e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/tika/client.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  require_relative "configuration"
2
- require_relative "api"
3
- require_relative "request"
4
- require "forwardable"
2
+ require_relative "requests"
5
3
 
6
4
  module Tika
7
5
  class Client
8
- extend Forwardable
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
- attr_accessor :host, :port, :api
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 config
30
- self.class.config
26
+ def get_text(opts={})
27
+ GetTextRequest.execute(connection, opts)
31
28
  end
32
29
 
33
- def connection
34
- @connection ||= Net::HTTP.new(host, port)
30
+ def get_metadata(opts={})
31
+ GetMetadataRequest.execute(connection, opts)
35
32
  end
36
33
 
37
- def execute(name, opts={})
38
- request = Request.new(connection, endpoint(name))
39
- request.execute(opts)
34
+ private
35
+
36
+ def config
37
+ self.class.config
40
38
  end
41
39
 
42
- def method_missing(name, *args)
43
- return execute(name, *args) if has_endpoint?(name)
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
- attr_reader :connection # , :endpoint, :http_request
8
+ class << self
9
+ attr_accessor :endpoint
10
+ end
11
+
12
+ attr_reader :connection
11
13
 
12
- # def self.execute(*args)
13
- # request = new(*args)
14
- # yield request if block_given?
15
- # request.execute
16
- # end
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, endpoint)
20
+ def initialize(connection)
19
21
  @connection = connection
20
- @endpoint = endpoint
21
- uri = URI::HTTP.build(host: connection.address, port: connection.port, path: endpoint.path)
22
- super endpoint.request_method.new(uri)
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.0
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