Class: DocomoNlu::Management::Entry

Inherits:
Base
  • Object
show all
Defined in:
lib/docomo_nlu/management/entry.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

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ Entry

Returns a new instance of Entry.



9
10
11
12
# File 'lib/docomo_nlu/management/entry.rb', line 9

def initialize(attributes = {}, persisted = false)
  super(attributes, persisted)
  prefix_options[:method] = "entry"
end

Class Method Details

.check_status(prefix_options) ⇒ Object



23
24
25
# File 'lib/docomo_nlu/management/entry.rb', line 23

def check_status(prefix_options)
  JSON.parse(connection.get("#{collection_path(prefix_options)}/status", headers).body)
end

.upload(file, prefix_options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/docomo_nlu/management/entry.rb', line 27

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.headers["Authorization"] = access_token
  params = {
    uploadFile: Faraday::UploadIO.new(file.path, "text/plain"),
  }
  response = conn.post collection_path(prefix_options), params
  check_response(response)
end

Instance Method Details

#saveObject



14
15
16
# File 'lib/docomo_nlu/management/entry.rb', line 14

def save
  self.class.upload(attributes[:file], prefix_options)
end

#statusObject



18
19
20
# File 'lib/docomo_nlu/management/entry.rb', line 18

def status
  self.class.check_status(prefix_options)
end