Class: DocomoNlu::Management::BotLog
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- DocomoNlu::Management::BotLog
show all
- Defined in:
- lib/docomo_nlu/management/bot_log.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
check_response, headers, #id_from_response, instantiate_collection, instantiate_record, #login, #logout, #static_headers
Class Method Details
.download(prefix_options, bot_id, params = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/docomo_nlu/management/bot_log.rb', line 39
def download(prefix_options, bot_id, params = {})
conn = Faraday.new(url: site.to_s, ssl: { verify: false }) do |builder|
builder.adapter :net_http
end
conn.["Authorization"] = access_token
response = conn.get("#{collection_path(prefix_options)}?botId=#{bot_id}&#{params.to_query}")
if check_response(response)
return Tempfile.open(["docomo-nlu", ".zip"]) do |f|
f.binmode
f.write response.body
f
end
end
nil
end
|
.unzip(file) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/docomo_nlu/management/bot_log.rb', line 56
def unzip(file)
::Zip::File.open(file.path) do |zf|
zf.each do |entry|
next unless entry.file?
name = entry.name
body = entry.get_input_stream.read.split(/\R/)
yield name, body if block_given?
end
end
end
|
Instance Method Details
#all ⇒ Object
11
12
13
|
# File 'lib/docomo_nlu/management/bot_log.rb', line 11
def all
Rails.logger.debug "You shoud use 'download' method"
end
|
#download(bot_id, params = {}) ⇒ Object
23
24
25
26
|
# File 'lib/docomo_nlu/management/bot_log.rb', line 23
def download(bot_id, params = {})
attributes[:file] = self.class.download(prefix_options, bot_id, params.slice(:start, :end))
attributes[:file]
end
|
28
29
30
31
32
33
34
35
36
|
# File 'lib/docomo_nlu/management/bot_log.rb', line 28
def
return unless attributes[:file]
logs = []
self.class.unzip(attributes[:file]) do |_name, body|
logs = body.map {|b| JSON.parse(b) }
end
logs
end
|
#find ⇒ Object
15
16
17
|
# File 'lib/docomo_nlu/management/bot_log.rb', line 15
def find
Rails.logger.debug "You shoud use 'download' method"
end
|
#where ⇒ Object
19
20
21
|
# File 'lib/docomo_nlu/management/bot_log.rb', line 19
def where
Rails.logger.debug "You shoud use 'download' method"
end
|