Class: Mode::Sdk::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/mode/sdk/upload.rb

Overview

Represents a Mode Upload containing raw CSV with no header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, options = {}) ⇒ Mode::Sdk::Upload

Construct a new Upload instance

Parameters:

  • content (String, #read)

    the content

  • options (optional, Hash) (defaults to: {})

    hash of options

Options Hash (options):

  • :content_size (Integer)

    the size of the provided content


20
21
22
23
# File 'lib/mode/sdk/upload.rb', line 20

def initialize(content, options = {})
  @content = content
  @options = options
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content


8
9
10
# File 'lib/mode/sdk/upload.rb', line 8

def content
  @content
end

#optionsObject (readonly)

Returns the value of attribute options


8
9
10
# File 'lib/mode/sdk/upload.rb', line 8

def options
  @options
end

Instance Method Details

#createMode::Sdk::Client::Response

Create the Upload through the Mode API

Returns:


29
30
31
32
33
34
35
36
# File 'lib/mode/sdk/upload.rb', line 29

def create
  @create ||= Mode::Sdk::Client.post(
    collection_path,
    content,
    content_type: 'application/csv',
    content_length: content_length,
    expect: [201])
end

#tokenString

The unique token assigned to the upload

Returns:

  • (String)

    the token


42
43
44
# File 'lib/mode/sdk/upload.rb', line 42

def token
  create.body.fetch('token')
end