Module: TreasureData::API::Import

Included in:
TreasureData::API
Defined in:
lib/td/client/api/import.rb

Instance Method Summary collapse

Instance Method Details

#import(db, table, format, stream, size, unique_id = nil) ⇒ Float

Returns elapsed time.

Parameters:

  • db (String)
  • table (String)
  • format (String)
  • stream (String, StringIO)
  • size (Fixnum)
  • unique_id (String) (defaults to: nil)

Returns:

  • (Float)

    elapsed time



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/td/client/api/import.rb', line 15

def import(db, table, format, stream, size, unique_id=nil)
  if unique_id
    path = "/v3/table/import_with_id/#{e db}/#{e table}/#{unique_id}/#{format}"
  else
    path = "/v3/table/import/#{e db}/#{e table}/#{format}"
  end
  opts = {}
  if @host == DEFAULT_ENDPOINT
    opts[:host] = DEFAULT_IMPORT_ENDPOINT
  elsif @host == TreasureData::API::OLD_ENDPOINT # backward compatibility
    opts[:host] = 'api-import.treasure-data.com'
    opts[:ssl] = false
  end
  code, body, res = put(path, stream, size, opts)
  if code[0] != ?2
    raise_error("Import failed", res)
  end
  return true
end