Class: Restet::Client
- Inherits:
-
Object
- Object
- Restet::Client
- Defined in:
- lib/restet/client.rb,
lib/restet/client/extraction_params.rb
Defined Under Namespace
Classes: ExtractionParams
Instance Method Summary collapse
- #build_request(file, params) ⇒ Object
- #extract(file) {|params| ... } ⇒ Object
-
#initialize(uri) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(uri) ⇒ Client
Returns a new instance of Client.
7 8 9 |
# File 'lib/restet/client.rb', line 7 def initialize(uri) @uri = uri end |
Instance Method Details
#build_request(file, params) ⇒ Object
20 21 22 23 |
# File 'lib/restet/client.rb', line 20 def build_request(file, params) upload_io = UploadIO.new(file, 'application/pdf') Net::HTTP::Post::Multipart.new(@uri.path, :pdf => upload_io, :extraction => params.to_json) end |
#extract(file) {|params| ... } ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/restet/client.rb', line 11 def extract(file) params = ExtractionParams.new(file) yield params if block_given? Net::HTTP.start(@uri.host, @uri.port) do |http| response = http.request build_request(file, params) return JSON.parse(response.body, :symbolize_keys => true) end end |