Class: IBMWatson::Conversation::Service

Inherits:
BaseService show all
Defined in:
lib/ibm_watson/conversation/service.rb

Constant Summary collapse

QUERY_VERSION =
"2017-02-03"

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, url, version

Constructor Details

This class inherits a constructor from IBMWatson::BaseService

Instance Method Details

#create_example(workspace_id:, intent:, example:) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/ibm_watson/conversation/service.rb', line 61

def create_example(workspace_id:, intent:, example:)
  handle_timeout do
    params = {
      text: example
    }
    result = post "workspaces/#{workspace_id}/intents/#{intent}/examples?version=#{QUERY_VERSION}", params
    IBMWatson::Conversation::CreateExampleResponse.new(result)
  end
end

#create_workspace(workspace_data:) ⇒ Object



25
26
27
28
29
# File 'lib/ibm_watson/conversation/service.rb', line 25

def create_workspace(workspace_data:)
  handle_timeout do
    upload_workspace('workspaces', workspace_data)
  end
end

#delete_example(workspace_id:, intent:, example:) ⇒ Object



55
56
57
58
59
# File 'lib/ibm_watson/conversation/service.rb', line 55

def delete_example(workspace_id:, intent:, example:)
  handle_timeout do
    delete "workspaces/#{workspace_id}/intents/#{intent}/examples/#{ERB::Util.url_encode(example)}?version=#{QUERY_VERSION}"
  end
end

#delete_workspace(workspace_id:) ⇒ Object



31
32
33
34
35
# File 'lib/ibm_watson/conversation/service.rb', line 31

def delete_workspace(workspace_id:)
  handle_timeout do
    delete "workspaces/#{workspace_id}?version=#{QUERY_VERSION}"
  end
end

#list_workspacesObject



16
17
18
19
20
21
22
23
# File 'lib/ibm_watson/conversation/service.rb', line 16

def list_workspaces
  handle_timeout do
    result = get 'workspaces', { version: QUERY_VERSION }
    result['workspaces'].map do |workspace_json|
      IBMWatson::Conversation::Workspace.new(workspace_json)
    end
  end
end

#message(workspace_id:, input:, context:, alternate_intents: false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ibm_watson/conversation/service.rb', line 43

def message(workspace_id:, input:, context:, alternate_intents: false)
  handle_timeout do
    params = {
      input: { text: input },
      context: context.as_json,
      alternate_intents: alternate_intents
    }
    result = post "workspaces/#{workspace_id}/message?version=#{QUERY_VERSION}", params
    IBMWatson::Conversation::MessageResponse.new(result)
  end
end

#update_workspace(workspace_id:, workspace_data:) ⇒ Object



37
38
39
40
41
# File 'lib/ibm_watson/conversation/service.rb', line 37

def update_workspace(workspace_id:, workspace_data:)
  handle_timeout do
    upload_workspace("workspaces/#{workspace_id}", workspace_data)
  end
end

#workspace(workspace_id:, export: false) ⇒ Object



8
9
10
11
12
13
# File 'lib/ibm_watson/conversation/service.rb', line 8

def workspace(workspace_id:, export: false)
  handle_timeout do
    result = get "workspaces/#{workspace_id}", version: QUERY_VERSION, export: export
    IBMWatson::Conversation::Workspace.new(result)
  end
end