Sha256: b226565e8d026d83398ae7144219d65fa3cc926137b5b1def0060f26508f2845

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module DocomoNlu
  module Management
    class Entry < Base
      self.element_name = ""
      self.prefix = "/management/v2.6/projects/:project_id/bots/:bot_id/:method"

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

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

      def status
        self.class.check_status(prefix_options)
      end

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

        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
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
docomo-nlu-0.4.0 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.8 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.7 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.6 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.5 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.4 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.2 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.1 lib/docomo_nlu/management/entry.rb
docomo-nlu-0.3.0 lib/docomo_nlu/management/entry.rb