Class: You::Client
- Inherits:
-
Object
- Object
- You::Client
- Defined in:
- lib/you/client.rb
Constant Summary collapse
- SMART_API_BASE_URL =
"https://chat-api.you.com".freeze
- SEARCH_API_BASE_URL =
"https://api.ydc-index.io".freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#initial_wait_time ⇒ Object
Returns the value of attribute initial_wait_time.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
Instance Method Summary collapse
-
#initialize(api_key: nil, max_retries: 3, initial_wait_time: 1) ⇒ Client
constructor
A new instance of Client.
-
#news(query:, **params) ⇒ Object
NEWS Endpoint (GET).
- #rag(query:, **params) ⇒ Object
-
#research(query:, chat_id: nil) ⇒ Object
RESEARCH Endpoint.
-
#search(query:, **params) ⇒ Object
SEARCH Endpoint (GET).
-
#smart(query:, chat_id: nil, instructions: nil) ⇒ Object
SMART Endpoint.
Constructor Details
#initialize(api_key: nil, max_retries: 3, initial_wait_time: 1) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 |
# File 'lib/you/client.rb', line 13 def initialize(api_key: nil, max_retries: 3, initial_wait_time: 1) @api_key = api_key || ENV["YOU_API_KEY"] raise You::Error, "No API key provided. Set YOU_API_KEY env or pass api_key." unless @api_key @max_retries = max_retries @initial_wait_time = initial_wait_time end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/you/client.rb', line 11 def api_key @api_key end |
#initial_wait_time ⇒ Object
Returns the value of attribute initial_wait_time.
11 12 13 |
# File 'lib/you/client.rb', line 11 def initial_wait_time @initial_wait_time end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
11 12 13 |
# File 'lib/you/client.rb', line 11 def max_retries @max_retries end |
Instance Method Details
#news(query:, **params) ⇒ Object
NEWS Endpoint (GET)
38 39 40 |
# File 'lib/you/client.rb', line 38 def news(query:, **params) get("#{SEARCH_API_BASE_URL}/news", {query: query}.merge(params)) end |
#rag(query:, **params) ⇒ Object
42 43 44 |
# File 'lib/you/client.rb', line 42 def rag(query:, **params) get("#{SEARCH_API_BASE_URL}/rag", {query: query}.merge(params)) end |
#research(query:, chat_id: nil) ⇒ Object
RESEARCH Endpoint
28 29 30 |
# File 'lib/you/client.rb', line 28 def research(query:, chat_id: nil) post("#{SMART_API_BASE_URL}/research", {query: query, chat_id: chat_id}.compact) end |
#search(query:, **params) ⇒ Object
SEARCH Endpoint (GET)
33 34 35 |
# File 'lib/you/client.rb', line 33 def search(query:, **params) get("#{SEARCH_API_BASE_URL}/search", {query: query}.merge(params)) end |
#smart(query:, chat_id: nil, instructions: nil) ⇒ Object
SMART Endpoint
23 24 25 |
# File 'lib/you/client.rb', line 23 def smart(query:, chat_id: nil, instructions: nil) post("#{SMART_API_BASE_URL}/smart", {query: query, chat_id: chat_id, instructions: instructions}.compact) end |