Class: Chatbase::HttpService
- Inherits:
-
Object
- Object
- Chatbase::HttpService
- Defined in:
- lib/chatbase/http_service.rb
Instance Attribute Summary collapse
-
#agent_key ⇒ Object
Returns the value of attribute agent_key.
-
#agent_name ⇒ Object
Returns the value of attribute agent_name.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(agent_key: nil) ⇒ HttpService
constructor
A new instance of HttpService.
- #request_post(data) ⇒ Object
Constructor Details
#initialize(agent_key: nil) ⇒ HttpService
Returns a new instance of HttpService.
5 6 7 8 |
# File 'lib/chatbase/http_service.rb', line 5 def initialize(agent_key: nil) @agent_key = agent_key || Chatbase.agent_key @agent_name = agent_name || Chatbase.agent_name end |
Instance Attribute Details
#agent_key ⇒ Object
Returns the value of attribute agent_key.
3 4 5 |
# File 'lib/chatbase/http_service.rb', line 3 def agent_key @agent_key end |
#agent_name ⇒ Object
Returns the value of attribute agent_name.
3 4 5 |
# File 'lib/chatbase/http_service.rb', line 3 def agent_name @agent_name end |
Instance Method Details
#connection ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/chatbase/http_service.rb', line 10 def connection @connection ||= begin Faraday.new(:url => 'https://chatbase.com/api/message') do |faraday| faraday.response :json, :content_type => /\bjson$/ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end end |
#request_post(data) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/chatbase/http_service.rb', line 19 def request_post(data) connection.post do |req| req.headers['Content-Type'] = 'application/json' req.body = {'api_key': agent_key, 'agent_name': agent_name}.merge(data).to_json end end |