Class: MotionAI::Client
- Inherits:
-
Object
- Object
- MotionAI::Client
- Defined in:
- lib/motion-ai/client.rb
Constant Summary collapse
- API_ENDPOINT =
'https://api.motion.ai/1.0'- GET_CONVERSATIONS_API_PATH =
'/getConversations'- MESSAGE_BOT_API_PATH =
'/messageBot'
Instance Attribute Summary collapse
-
#bot_id ⇒ Object
Returns the value of attribute bot_id.
Instance Method Summary collapse
- #get_conversations(params = {}) ⇒ Object
-
#initialize(api_key, bot_id) ⇒ Client
constructor
A new instance of Client.
- #message_bot(params = {}) ⇒ Object
Constructor Details
#initialize(api_key, bot_id) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 |
# File 'lib/motion-ai/client.rb', line 14 def initialize(api_key, bot_id) @api_key = api_key @bot_id = bot_id @http = Faraday.new(url: API_ENDPOINT) do |conn| conn.response :json, content_type: /\bjson$/ conn.adapter Faraday.default_adapter end end |
Instance Attribute Details
#bot_id ⇒ Object
Returns the value of attribute bot_id.
12 13 14 |
# File 'lib/motion-ai/client.rb', line 12 def bot_id @bot_id end |
Instance Method Details
#get_conversations(params = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/motion-ai/client.rb', line 37 def get_conversations(params = {}) params[:key] = @api_key required = [:key] required.each do |param| unless params.key? param raise "Required param #{param} not present" end end @http.get URI.join(API_ENDPOINT, GET_CONVERSATIONS_API_PATH), params end |
#message_bot(params = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/motion-ai/client.rb', line 23 def (params = {}) params[:key] = @api_key params[:bot] = @bot_id required = [:bot, :msg, :session, :key] required.each do |param| unless params.key? param raise "Required param #{param} not present" end end @http.get URI.join(API_ENDPOINT, MESSAGE_BOT_API_PATH), params end |