Class: DocomoNlu::Management::OKNGBase
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- DocomoNlu::Management::OKNGBase
show all
- Defined in:
- lib/docomo_nlu/management/ok_ng_base.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
.all(options = {}) ⇒ Object
27
28
29
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 27
def all(options = {})
find(options)
end
|
.create(file, prefix_options) ⇒ Object
22
23
24
25
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 22
def create(file, prefix_options)
check_prefix_options(prefix_options)
upload(file, prefix_options)
end
|
.download(prefix_options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 41
def download(prefix_options = {})
conn = Faraday.new(url: site.to_s, ssl: { verify: false }) do |builder|
builder.adapter :net_http
end
conn.["Authorization"] = access_token
response = conn.get(element_path(nil, prefix_options))
if check_response(response)
return instantiate_record({}, prefix_options).tap do |record|
record.file = Tempfile.open(["docomo-nlu", extention]) do |f|
f.write response.body.force_encoding("UTF-8")
f
end
end
end
nil
end
|
.find(options) ⇒ Object
31
32
33
34
35
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 31
def find(options)
prefix_options, = split_options(options[:params])
check_prefix_options(prefix_options)
download(prefix_options)
end
|
.upload(file, prefix_options) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 60
def upload(file, prefix_options)
conn = Faraday.new(url: site.to_s, ssl: { verify: false }) do |builder|
builder.request :multipart
builder.request :url_encoded
builder.adapter :net_http
end
conn.["Authorization"] = access_token
params = {
uploadFile: Faraday::UploadIO.new(file.path, "text/plain"),
}
response = conn.put collection_path(prefix_options), params
check_response(response)
end
|
.where(clauses = {}) ⇒ Object
37
38
39
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 37
def where(clauses = {})
find(params: clauses)
end
|
Instance Method Details
#destroy ⇒ Object
13
14
15
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 13
def destroy
super
end
|
#download ⇒ Object
17
18
19
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 17
def download
self.file = self.class.download(prefix_options).file
end
|
#save ⇒ Object
9
10
11
|
# File 'lib/docomo_nlu/management/ok_ng_base.rb', line 9
def save
self.class.create(attributes[:file], prefix_options)
end
|