docomo-nlu 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +32 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +198 -0
- data/README.md +38 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docomo-nlu.gemspec +37 -0
- data/lib/docomo-nlu.rb +11 -0
- data/lib/docomo-nlu/config.rb +25 -0
- data/lib/docomo-nlu/management.rb +28 -0
- data/lib/docomo-nlu/management/account.rb +32 -0
- data/lib/docomo-nlu/management/aiml_base.rb +126 -0
- data/lib/docomo-nlu/management/base.rb +87 -0
- data/lib/docomo-nlu/management/bot.rb +18 -0
- data/lib/docomo-nlu/management/config.rb +25 -0
- data/lib/docomo-nlu/management/default_predicate.rb +15 -0
- data/lib/docomo-nlu/management/map.rb +10 -0
- data/lib/docomo-nlu/management/multipart_base.rb +82 -0
- data/lib/docomo-nlu/management/ng_word.rb +10 -0
- data/lib/docomo-nlu/management/ok_word.rb +10 -0
- data/lib/docomo-nlu/management/organization.rb +23 -0
- data/lib/docomo-nlu/management/organization_member.rb +15 -0
- data/lib/docomo-nlu/management/predicate_name.rb +15 -0
- data/lib/docomo-nlu/management/project.rb +16 -0
- data/lib/docomo-nlu/management/project_member.rb +15 -0
- data/lib/docomo-nlu/management/property.rb +10 -0
- data/lib/docomo-nlu/management/provider.rb +17 -0
- data/lib/docomo-nlu/management/scenario.rb +18 -0
- data/lib/docomo-nlu/management/scenario_project.rb +10 -0
- data/lib/docomo-nlu/management/scenario_util.rb +30 -0
- data/lib/docomo-nlu/management/set.rb +10 -0
- data/lib/docomo-nlu/management/task_project.rb +20 -0
- data/lib/docomo-nlu/spontaneous.rb +8 -0
- data/lib/docomo-nlu/spontaneous/dialogue.rb +58 -0
- data/lib/docomo-nlu/spontaneous/registration.rb +58 -0
- data/lib/docomo-nlu/version.rb +5 -0
- data/lib/generators/docomo_nlu/install/install_generator.rb +11 -0
- data/lib/generators/templates/template.rb +7 -0
- data/vcr/vcr_cassettes/account/count.yml +42 -0
- data/vcr/vcr_cassettes/account/create.yml +44 -0
- data/vcr/vcr_cassettes/account/delete.yml +38 -0
- data/vcr/vcr_cassettes/account/index.yml +43 -0
- data/vcr/vcr_cassettes/account/show.yml +43 -0
- data/vcr/vcr_cassettes/account/update.yml +41 -0
- data/vcr/vcr_cassettes/baes/login.yml +44 -0
- data/vcr/vcr_cassettes/base/login.yml +44 -0
- data/vcr/vcr_cassettes/base/login_400.yml +42 -0
- data/vcr/vcr_cassettes/base/logout.yml +40 -0
- data/vcr/vcr_cassettes/base/logout_400.yml +40 -0
- data/vcr/vcr_cassettes/bot/create.yml +43 -0
- data/vcr/vcr_cassettes/bot/create_conflict.yml +45 -0
- data/vcr/vcr_cassettes/bot/delete.yml +38 -0
- data/vcr/vcr_cassettes/bot/deploy.yml +164 -0
- data/vcr/vcr_cassettes/bot/download_aiml.yml +51 -0
- data/vcr/vcr_cassettes/bot/download_archive.yml +43 -0
- data/vcr/vcr_cassettes/bot/download_dat.yml +43 -0
- data/vcr/vcr_cassettes/bot/index.yml +43 -0
- data/vcr/vcr_cassettes/bot/index_not_found.yml +42 -0
- data/vcr/vcr_cassettes/bot/show.yml +43 -0
- data/vcr/vcr_cassettes/bot/upload_aiml.yml +51 -0
- data/vcr/vcr_cassettes/bot/upload_archive.yml +46 -0
- data/vcr/vcr_cassettes/bot/upload_dat.yml +46 -0
- data/vcr/vcr_cassettes/config/delete.yml +38 -0
- data/vcr/vcr_cassettes/config/index.yml +120 -0
- data/vcr/vcr_cassettes/config/update.yml +42 -0
- data/vcr/vcr_cassettes/default_predicate/create.yml +42 -0
- data/vcr/vcr_cassettes/default_predicate/delete.yml +38 -0
- data/vcr/vcr_cassettes/default_predicate/index.yml +120 -0
- data/vcr/vcr_cassettes/default_predicate/index_not_found.yml +120 -0
- data/vcr/vcr_cassettes/default_predicate/update.yml +40 -0
- data/vcr/vcr_cassettes/map/create.yml +45 -0
- data/vcr/vcr_cassettes/map/create_400.yml +48 -0
- data/vcr/vcr_cassettes/map/delete.yml +38 -0
- data/vcr/vcr_cassettes/map/index_all.yml +43 -0
- data/vcr/vcr_cassettes/map/index_find.yml +43 -0
- data/vcr/vcr_cassettes/map/index_where.yml +43 -0
- data/vcr/vcr_cassettes/map/save.yml +45 -0
- data/vcr/vcr_cassettes/map/save_400.yml +48 -0
- data/vcr/vcr_cassettes/map/show_find.yml +43 -0
- data/vcr/vcr_cassettes/map/show_where.yml +43 -0
- data/vcr/vcr_cassettes/organization/create.yml +44 -0
- data/vcr/vcr_cassettes/organization/delete.yml +38 -0
- data/vcr/vcr_cassettes/organization/index.yml +42 -0
- data/vcr/vcr_cassettes/organization/show.yml +42 -0
- data/vcr/vcr_cassettes/organization/update.yml +40 -0
- data/vcr/vcr_cassettes/organization_member/create.yml +42 -0
- data/vcr/vcr_cassettes/organization_member/delete.yml +38 -0
- data/vcr/vcr_cassettes/organization_member/index.yml +42 -0
- data/vcr/vcr_cassettes/organization_member/index_404.yml +42 -0
- data/vcr/vcr_cassettes/organization_member/index_not_found.yml +42 -0
- data/vcr/vcr_cassettes/predicate_name/create.yml +42 -0
- data/vcr/vcr_cassettes/predicate_name/delete.yml +38 -0
- data/vcr/vcr_cassettes/predicate_name/index.yml +42 -0
- data/vcr/vcr_cassettes/predicate_name/index_all.yml +42 -0
- data/vcr/vcr_cassettes/predicate_name/index_find.yml +42 -0
- data/vcr/vcr_cassettes/predicate_name/index_where.yml +42 -0
- data/vcr/vcr_cassettes/project/create.yml +44 -0
- data/vcr/vcr_cassettes/project/create_conflict.yml +44 -0
- data/vcr/vcr_cassettes/project/delete.yml +38 -0
- data/vcr/vcr_cassettes/project/index.yml +227 -0
- data/vcr/vcr_cassettes/project/show.yml +43 -0
- data/vcr/vcr_cassettes/project_member/create.yml +42 -0
- data/vcr/vcr_cassettes/project_member/delete.yml +38 -0
- data/vcr/vcr_cassettes/project_member/index.yml +42 -0
- data/vcr/vcr_cassettes/project_member/index_403.yml +40 -0
- data/vcr/vcr_cassettes/project_member/index_not_found.yml +42 -0
- data/vcr/vcr_cassettes/provider/create.yml +44 -0
- data/vcr/vcr_cassettes/provider/delete.yml +38 -0
- data/vcr/vcr_cassettes/provider/index.yml +42 -0
- data/vcr/vcr_cassettes/provider/show.yml +42 -0
- data/vcr/vcr_cassettes/scenario/create.yml +42 -0
- data/vcr/vcr_cassettes/scenario/create_conflict.yml +44 -0
- data/vcr/vcr_cassettes/scenario/delete.yml +38 -0
- data/vcr/vcr_cassettes/scenario/deploy.yml +164 -0
- data/vcr/vcr_cassettes/scenario/download_aiml.yml +51 -0
- data/vcr/vcr_cassettes/scenario/index.yml +42 -0
- data/vcr/vcr_cassettes/scenario/index_not_found.yml +42 -0
- data/vcr/vcr_cassettes/scenario/show.yml +42 -0
- data/vcr/vcr_cassettes/scenario/update.yml +40 -0
- data/vcr/vcr_cassettes/scenario/upload.yml +51 -0
- data/vcr/vcr_cassettes/scenario/upload_aiml.yml +51 -0
- data/vcr/vcr_cassettes/scenario/upload_archive.yml +46 -0
- data/vcr/vcr_cassettes/scenario/upload_dat.yml +46 -0
- data/vcr/vcr_cassettes/set/create.yml +45 -0
- data/vcr/vcr_cassettes/set/create_400.yml +48 -0
- data/vcr/vcr_cassettes/set/delete.yml +38 -0
- data/vcr/vcr_cassettes/set/index_all.yml +42 -0
- data/vcr/vcr_cassettes/set/index_find.yml +42 -0
- data/vcr/vcr_cassettes/set/index_where.yml +42 -0
- data/vcr/vcr_cassettes/set/save.yml +45 -0
- data/vcr/vcr_cassettes/set/save_400.yml +48 -0
- data/vcr/vcr_cassettes/set/show_find.yml +43 -0
- data/vcr/vcr_cassettes/set/show_where.yml +43 -0
- metadata +336 -0
data/lib/docomo-nlu.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'docomo-nlu/version'
|
4
|
+
require 'docomo-nlu/config'
|
5
|
+
require 'activeresource'
|
6
|
+
require 'faraday'
|
7
|
+
|
8
|
+
module DocomoNlu
|
9
|
+
autoload :Spontaneous, 'docomo-nlu/spontaneous'
|
10
|
+
autoload :Management, 'docomo-nlu/management'
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/configurable'
|
4
|
+
module DocomoNlu
|
5
|
+
def self.configure
|
6
|
+
yield @config ||= DocomoNlu::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.config
|
10
|
+
@config
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
include ActiveSupport::Configurable
|
15
|
+
config_accessor :nlu_host
|
16
|
+
config_accessor :nlu_version
|
17
|
+
config_accessor :admin_access_token
|
18
|
+
end
|
19
|
+
|
20
|
+
configure do |config|
|
21
|
+
config.nlu_host = 'http://nlu-external-dev-977165653.ap-northeast-1.elb.amazonaws.com'
|
22
|
+
config.nlu_version = 'v2.2'
|
23
|
+
config.admin_access_token = 'NLP f68518ed5a40907ec6b754caeaadc32b0af4920f69955c22749e38e17946ea57'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DocomoNlu
|
4
|
+
module Management
|
5
|
+
autoload :Account, 'docomo-nlu/management/account'
|
6
|
+
autoload :AIMLBase, 'docomo-nlu/management/aiml_base'
|
7
|
+
autoload :Base, 'docomo-nlu/management/base'
|
8
|
+
autoload :Bot, 'docomo-nlu/management/bot'
|
9
|
+
autoload :Config, 'docomo-nlu/management/config'
|
10
|
+
autoload :DefaultPredicate, 'docomo-nlu/management/default_predicate'
|
11
|
+
autoload :MultipartBase, 'docomo-nlu/management/multipart_base'
|
12
|
+
autoload :Map, 'docomo-nlu/management/map'
|
13
|
+
autoload :NGWord, 'docomo-nlu/management/ng_word'
|
14
|
+
autoload :OKWord, 'docomo-nlu/management/ok_word'
|
15
|
+
autoload :OrganizationMember, 'docomo-nlu/management/organization_member'
|
16
|
+
autoload :Organization, 'docomo-nlu/management/organization'
|
17
|
+
autoload :PredicateName, 'docomo-nlu/management/predicate_name'
|
18
|
+
autoload :ProjectMember, 'docomo-nlu/management/project_member'
|
19
|
+
autoload :Project, 'docomo-nlu/management/project'
|
20
|
+
autoload :Property, 'docomo-nlu/management/property'
|
21
|
+
autoload :Provider, 'docomo-nlu/management/provider'
|
22
|
+
autoload :ScenarioProject, 'docomo-nlu/management/scenario_project'
|
23
|
+
autoload :ScenarioUtil, 'docomo-nlu/management/scenario_util'
|
24
|
+
autoload :Scenario, 'docomo-nlu/management/scenario'
|
25
|
+
autoload :Set, 'docomo-nlu/management/set'
|
26
|
+
autoload :TaskProject, 'docomo-nlu/management/task_project'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DocomoNlu
|
4
|
+
module Management
|
5
|
+
class Account < Base
|
6
|
+
self.element_name = 'accounts'
|
7
|
+
self.prefix = "/management/#{DocomoNlu.config.nlu_version}/"
|
8
|
+
|
9
|
+
# Parameter for create
|
10
|
+
# {
|
11
|
+
# "accountName": "your account name",
|
12
|
+
# "password": "your account password",
|
13
|
+
# "description": "account description",
|
14
|
+
# "authorization": 2,
|
15
|
+
# "enable": true
|
16
|
+
# }
|
17
|
+
|
18
|
+
def self.count
|
19
|
+
response_body = JSON.parse(connection.get("#{prefix}#{element_name}/count", headers).body)
|
20
|
+
response_body['count']
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_json(options = {})
|
24
|
+
attributes.delete('accountId')
|
25
|
+
attributes.delete('createDate')
|
26
|
+
attributes.delete('loginDate')
|
27
|
+
attributes.delete('id')
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# download([:aiml,:dat,:archive],scenarioId)
|
4
|
+
# GET /{projectId}/bots/{botId}/aiml/{scenarioId}
|
5
|
+
# GET /{projectId}/bots/{botId}/dat
|
6
|
+
# GET /{projectId}/bots/{botId}/archive
|
7
|
+
|
8
|
+
# upload([:aiml,:dat,:archive],filepath)
|
9
|
+
# /{projectId}/bots/{botId}/aiml
|
10
|
+
# /{projectId}/bots/{botId}/dat
|
11
|
+
# /{projectId}/bots/{botId}/archive
|
12
|
+
|
13
|
+
# Not supported
|
14
|
+
# GET /{projectId}/bots/{botId}/archive/aiml
|
15
|
+
|
16
|
+
require 'tempfile'
|
17
|
+
module DocomoNlu
|
18
|
+
module Management
|
19
|
+
class AIMLBase < Base
|
20
|
+
def download(extra_path = '')
|
21
|
+
prefix_options[:bot_id] ||= botId
|
22
|
+
@attributes[:file] = self.class.download(prefix_options, extra_path).file
|
23
|
+
end
|
24
|
+
|
25
|
+
def upload(file)
|
26
|
+
prefix_options[:bot_id] ||= botId
|
27
|
+
self.class.upload(file, prefix_options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def compile
|
31
|
+
prefix_options[:bot_id] ||= botId
|
32
|
+
self.class.compile(prefix_options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def transfer
|
36
|
+
prefix_options[:bot_id] ||= botId
|
37
|
+
self.class.deploy_request(prefix_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def deploy
|
41
|
+
prefix_options[:bot_id] ||= botId
|
42
|
+
self.class.deploy(prefix_options)
|
43
|
+
end
|
44
|
+
|
45
|
+
class << self
|
46
|
+
def download(prefix_options, extra_path = '')
|
47
|
+
conn = Faraday.new(url: site.to_s, ssl: { verify: false }) do |builder|
|
48
|
+
builder.adapter :net_http
|
49
|
+
end
|
50
|
+
conn.headers['Authorization'] = access_token
|
51
|
+
response = conn.get("#{FileModel.collection_path(prefix_options)}/#{extra_path}")
|
52
|
+
|
53
|
+
if check_response(response)
|
54
|
+
instantiate_record({}, prefix_options).tap do |record|
|
55
|
+
record.file = Tempfile.open(['docomo-nlu', ".#{prefix_options[:method].to_s.gsub(/archive/, 'zip')}"]) do |f|
|
56
|
+
f.write response.body
|
57
|
+
f
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def upload(file, prefix_options)
|
64
|
+
conn = Faraday.new(url: site.to_s, ssl: { verify: false }) do |builder|
|
65
|
+
builder.request :multipart # マルチパートでデータを送信
|
66
|
+
builder.request :url_encoded
|
67
|
+
builder.adapter :net_http
|
68
|
+
end
|
69
|
+
conn.headers['Authorization'] = access_token
|
70
|
+
params = {
|
71
|
+
uploadFile: Faraday::UploadIO.new(file.path, 'text/plain')
|
72
|
+
}
|
73
|
+
response = conn.put FileModel.collection_path(prefix_options), params
|
74
|
+
check_response(response)
|
75
|
+
end
|
76
|
+
|
77
|
+
def compile(prefix_options)
|
78
|
+
return if deploy_request(:compile, prefix_options) != ''
|
79
|
+
end
|
80
|
+
|
81
|
+
def transfer(prefix_options)
|
82
|
+
return if deploy_request(:transfer, prefix_options) != ''
|
83
|
+
end
|
84
|
+
|
85
|
+
def deploy_request(method, prefix_options)
|
86
|
+
response_body = JSON.parse(connection.post(Scenario.element_path(method, prefix_options), '', headers).body)
|
87
|
+
# Sometimes, API returns wrong url, replace correct path.
|
88
|
+
URI.parse(response_body['statusUri']).path.gsub!(/NLPManagementAPI/, "management/#{DocomoNlu.config.nlu_version}")
|
89
|
+
end
|
90
|
+
|
91
|
+
def deploy(prefix_options)
|
92
|
+
# compile and status check
|
93
|
+
compile_status = false
|
94
|
+
check_path = deploy_request(:compile, prefix_options)
|
95
|
+
while check_path && compile_status != 'Completed'
|
96
|
+
sleep(0.2)
|
97
|
+
compile_status = check_status(:compile, check_path)
|
98
|
+
raise ActiveResource::ServerError if %w[ErrorFinish NotCompiled].include?(compile_status)
|
99
|
+
end
|
100
|
+
|
101
|
+
# transfer and status check
|
102
|
+
transfer_status = false
|
103
|
+
check_path = deploy_request(:transfer, prefix_options)
|
104
|
+
while check_path && transfer_status != 'Completed'
|
105
|
+
sleep(0.2)
|
106
|
+
transfer_status = check_status(:transfer, check_path)
|
107
|
+
raise ActiveResource::ServerError if %w[ErrorFinish NotTransfered].include?(transfer_status)
|
108
|
+
end
|
109
|
+
true
|
110
|
+
end
|
111
|
+
|
112
|
+
def check_status(method, path)
|
113
|
+
case method
|
114
|
+
when :compile then JSON.parse(connection.get(path, headers).body)['status']
|
115
|
+
when :transfer then JSON.parse(connection.get(path, headers).body)['transferStatusResponses'][0]['status']
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class FileModel < Base
|
121
|
+
self.element_name = ''
|
122
|
+
self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/:method"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DocomoNlu
|
4
|
+
module Management
|
5
|
+
class Base < ActiveResource::Base
|
6
|
+
## For Dynamically generated headers via http://rmosolgo.github.io/blog/2014/02/05/dynamically-generated-headers-for-activeresource-requests/
|
7
|
+
cattr_accessor :static_headers
|
8
|
+
cattr_accessor :access_token
|
9
|
+
|
10
|
+
## Dynamic headers
|
11
|
+
self.static_headers = headers
|
12
|
+
|
13
|
+
## Admin Accesstoken
|
14
|
+
self.access_token = DocomoNlu.config.admin_access_token
|
15
|
+
|
16
|
+
## Setting Endpoint.
|
17
|
+
self.site = DocomoNlu.config.nlu_host
|
18
|
+
|
19
|
+
## Remove format in path (remove .json)
|
20
|
+
self.include_format_in_path = false
|
21
|
+
|
22
|
+
## Setting Format
|
23
|
+
self.format = :json
|
24
|
+
|
25
|
+
## Get NLPManagement's AccessToken.
|
26
|
+
def login(accountName, password)
|
27
|
+
request_body = { accountName: accountName, password: password }.to_json
|
28
|
+
response_body = JSON.parse(connection.post("/management/#{DocomoNlu.config.nlu_version}/login", request_body, self.class.headers).body)
|
29
|
+
self.access_token = response_body['accessToken']
|
30
|
+
end
|
31
|
+
|
32
|
+
## Delete NLPManagement's AccessToken.
|
33
|
+
def logout
|
34
|
+
res = connection.get("/management/#{DocomoNlu.config.nlu_version}/logout", self.class.headers) if access_token.present?
|
35
|
+
raise ActiveResource::BadRequest, 'Invalid access token' unless res
|
36
|
+
|
37
|
+
self.access_token = nil
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
## Override. Insert generated id to parameter 'id' after save or create
|
42
|
+
def id_from_response(response)
|
43
|
+
ActiveSupport::JSON.decode(response.body)["#{self.class.to_s.split('::').last.downcase!}Id"] if response.body.present?
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
def instantiate_collection(collection, original_params = {}, prefix_options = {})
|
48
|
+
if collection.is_a?(Hash)
|
49
|
+
collection = if collection.empty? || collection.first[1].nil?
|
50
|
+
[]
|
51
|
+
else
|
52
|
+
[collection]
|
53
|
+
end
|
54
|
+
elsif collection[0].is_a?(String)
|
55
|
+
collection = [{ params: collection }]
|
56
|
+
end
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
def instantiate_record(record, prefix_options = {})
|
61
|
+
record = record[0] if record.is_a?(Array)
|
62
|
+
resource_id = record["#{to_s.split('::').last.downcase!}Id"]
|
63
|
+
record['id'] = resource_id if resource_id
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
67
|
+
def headers
|
68
|
+
new_headers = static_headers.clone
|
69
|
+
new_headers['Authorization'] = access_token
|
70
|
+
new_headers
|
71
|
+
end
|
72
|
+
|
73
|
+
def check_response(response)
|
74
|
+
case response.status
|
75
|
+
when 400 then raise ActiveResource::BadRequest, response
|
76
|
+
when 401 then raise ActiveResource::UnauthorizedAccess, response
|
77
|
+
when 403 then raise ActiveResource::ForbiddenAccess, response
|
78
|
+
when 404 then raise ActiveResource::ResourceNotFound, response
|
79
|
+
when 409 then raise ActiveResource::ResourceConflict, response
|
80
|
+
when 503 then raise ActiveResource::ServerError, response
|
81
|
+
when 200..204 then true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DocomoNlu
|
4
|
+
module Management
|
5
|
+
class Bot < AIMLBase
|
6
|
+
self.element_name = 'bots'
|
7
|
+
self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/"
|
8
|
+
|
9
|
+
# Parameter for create
|
10
|
+
# {
|
11
|
+
# "botId": "botid",
|
12
|
+
# "scenarioProjectId", "DSU",
|
13
|
+
# "language": "ja-JP",
|
14
|
+
# "description": "hello"
|
15
|
+
# }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DocomoNlu
|
4
|
+
module Management
|
5
|
+
class Config < Base
|
6
|
+
self.element_name = 'configs'
|
7
|
+
self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
|
8
|
+
|
9
|
+
# {
|
10
|
+
# "dialogTimeout": 300,
|
11
|
+
# "replyTimeout": 300,
|
12
|
+
# "xxxxUrl": "http://xxx",
|
13
|
+
# "yyyyUrl": "http://xxx",
|
14
|
+
# "sensitiveInfo": "aa.bb, ccc.ddd...",
|
15
|
+
# "sraix" : [true|false],
|
16
|
+
# "taskServerUrl": "http://xxx"
|
17
|
+
# }
|
18
|
+
|
19
|
+
def destroy(keys)
|
20
|
+
self.id = keys.join(',')
|
21
|
+
super()
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DocomoNlu
|
4
|
+
module Management
|
5
|
+
class DefaultPredicate < Base
|
6
|
+
self.element_name = 'defaultPredicates'
|
7
|
+
self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
|
8
|
+
|
9
|
+
def destroy(keys)
|
10
|
+
self.id = keys.join(',')
|
11
|
+
super()
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
module DocomoNlu
|
5
|
+
module Management
|
6
|
+
class MultipartBase < Base
|
7
|
+
def save
|
8
|
+
self.class.create(attributes[:file], prefix_options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy
|
12
|
+
self.id = try(:category)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def create(file, prefix_options)
|
18
|
+
check_prefix_options(prefix_options)
|
19
|
+
raise ActiveResource::BadRequest, '' unless file.instance_of?(File)
|
20
|
+
|
21
|
+
upload(file, prefix_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def find(*arguments)
|
25
|
+
scope = arguments.slice!(0)
|
26
|
+
options = arguments.slice!(0) || {}
|
27
|
+
|
28
|
+
prefix_options, = split_options(options[:params])
|
29
|
+
check_prefix_options(prefix_options)
|
30
|
+
|
31
|
+
case scope
|
32
|
+
when :all then download(nil, prefix_options)
|
33
|
+
else download(scope, prefix_options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def where(clauses = {})
|
38
|
+
raise ArgumentError, "expected a clauses Hash, got #{clauses.inspect}" unless clauses.is_a? Hash
|
39
|
+
category = clauses[:category]
|
40
|
+
find(category, params: clauses)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def download(category = nil, prefix_options)
|
46
|
+
extention = category.blank? ? '.zip' : '.map'
|
47
|
+
|
48
|
+
conn = Faraday.new(url: site.to_s, ssl: { verify: false }) do |builder|
|
49
|
+
builder.adapter :net_http
|
50
|
+
end
|
51
|
+
conn.headers['Authorization'] = access_token
|
52
|
+
|
53
|
+
response = conn.get(element_path(category, prefix_options))
|
54
|
+
|
55
|
+
if check_response(response)
|
56
|
+
instantiate_record({}, prefix_options).tap do |record|
|
57
|
+
record.file = Tempfile.open(['docomo-nlu', extention]) do |f|
|
58
|
+
f.write response.body
|
59
|
+
f
|
60
|
+
end
|
61
|
+
record.category = category
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def upload(file, prefix_options)
|
67
|
+
conn = Faraday.new(url: site.to_s, ssl: { verify: false }) do |builder|
|
68
|
+
builder.request :multipart # マルチパートでデータを送信
|
69
|
+
builder.request :url_encoded
|
70
|
+
builder.adapter :net_http
|
71
|
+
end
|
72
|
+
conn.headers['Authorization'] = access_token
|
73
|
+
params = {
|
74
|
+
uploadFile: Faraday::UploadIO.new(file.path, 'text/plain')
|
75
|
+
}
|
76
|
+
response = conn.put collection_path(prefix_options), params
|
77
|
+
check_response(response)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|