Class: Unstructured::Client
- Inherits:
-
Object
- Object
- Unstructured::Client
- Defined in:
- lib/unstructured/client.rb
Constant Summary collapse
- SERVER_URL =
"https://api.unstructured.io"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key_auth ⇒ Object
readonly
Returns the value of attribute api_key_auth.
-
#server_url ⇒ Object
readonly
Returns the value of attribute server_url.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(server_url: nil, api_key_auth: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #partition(file_path, params = {}, headers: {}) ⇒ Object
Constructor Details
#initialize(server_url: nil, api_key_auth: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 |
# File 'lib/unstructured/client.rb', line 13 def initialize(server_url: nil, api_key_auth: nil, adapter: Faraday.default_adapter, stubs: nil) @server_url = server_url || SERVER_URL @api_key_auth = api_key_auth @adapter = adapter @stubs = stubs end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
11 12 13 |
# File 'lib/unstructured/client.rb', line 11 def adapter @adapter end |
#api_key_auth ⇒ Object (readonly)
Returns the value of attribute api_key_auth.
11 12 13 |
# File 'lib/unstructured/client.rb', line 11 def api_key_auth @api_key_auth end |
#server_url ⇒ Object (readonly)
Returns the value of attribute server_url.
11 12 13 |
# File 'lib/unstructured/client.rb', line 11 def server_url @server_url end |
Instance Method Details
#connection ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/unstructured/client.rb', line 20 def connection @connection ||= Faraday.new do |conn| conn.url_prefix = server_url conn.request :multipart conn.response :json, content_type: "application/json" conn.adapter adapter, @stubs conn.headers["unstructured-api-key"] = api_key_auth if api_key_auth end end |
#inspect ⇒ Object
40 41 42 |
# File 'lib/unstructured/client.rb', line 40 def inspect "#<#{self.class.name} server_url=#{server_url.inspect}>" end |
#partition(file_path, params = {}, headers: {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/unstructured/client.rb', line 30 def partition(file_path, params = {}, headers: {}) ChunkCollection.from_response handle_response(connection.post( "/general/v0/general", default_params.merge(params).merge({ files: files(file_path) }), headers )) end |