Class: Chatpdf::Client
- Inherits:
-
Object
- Object
- Chatpdf::Client
- Includes:
- Actionable
- Defined in:
- lib/chatpdf/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.chatpdf.com/v1".freeze
Instance Method Summary collapse
- #api_key_or_raise ⇒ Object
- #endpoint(path) ⇒ Object
- #headers ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #request(path, options = {}) ⇒ Object
- #upload_file(path, options = {}) ⇒ Object
Methods included from Actionable
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/chatpdf/client.rb', line 9 def initialize @api_key = api_key_or_raise end |
Instance Method Details
#api_key_or_raise ⇒ Object
37 38 39 40 |
# File 'lib/chatpdf/client.rb', line 37 def api_key_or_raise raise Chatpdf::InvalidConfiguration, "Chatpdf is not configured" if Chatpdf.configuration.nil? Chatpdf.configuration.api_key || raise(Chatpdf::InvalidConfiguration, "API key is not set") end |
#endpoint(path) ⇒ Object
29 30 31 |
# File 'lib/chatpdf/client.rb', line 29 def endpoint(path) BASE_URL + path end |
#headers ⇒ Object
33 34 35 |
# File 'lib/chatpdf/client.rb', line 33 def headers { "x-api-key" => @api_key, "Content-Type" => "application/json" } end |
#request(path, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/chatpdf/client.rb', line 13 def request(path, = {}) HTTParty.post( endpoint(path), headers: headers, body: [:body].to_json ) end |
#upload_file(path, options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/chatpdf/client.rb', line 21 def upload_file(path, = {}) HTTParty.post( endpoint(path), headers: { "x-api-key" => @api_key }, body: [:body] ) end |