Module: NexosisApi::Client::Imports

Included in:
NexosisApi::Client
Defined in:
lib/nexosis_api/client/imports.rb

Overview

Imports-based API operations

Instance Method Summary collapse

Instance Method Details

#import_from_s3(dataset_name, bucket_name, path, region = "us-east-1", column_metadata = []) ⇒ NexosisApi::ImportsResponse

Import a file from AWS s3 as your dataset

Parameters:

  • dataset_name (String)

    the name to give to the new dataset or existing dataset to which this data will be upserted

  • bucket_name (String)

    the AWS S3 bucket name in which the path will be found

  • path (String)

    the path within the bucket (usually file name)

  • region (String) (defaults to: "us-east-1")

    the region in which your bucket exists. Defaults to us-east-1

  • column_metadata (Array of NexosisApi::DatasetColumn) (defaults to: [])

    description of each column in target dataset. Optional.

Returns:

See Also:


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nexosis_api/client/imports.rb', line 35

def import_from_s3(dataset_name, bucket_name, path, region = "us-east-1",  = [])
    raise ArgumentError "dataset_name was not provided and is not optional " unless dataset_name.to_s.empty? == false
    raise ArgumentError "bucket_name was not provided and is not optional " unless bucket_name.to_s.empty? == false
    raise ArgumentError "path was not provided and is not optional " unless path.to_s.empty? == false
    
    s3_import_url = "/imports/s3"
    column_json = DatasetColumn.to_json()
    body = {
        "dataSetName" => dataset_name,
        "bucket" => bucket_name,
        "path" => path,
        "region" => region,
        "columns" => column_json
    }
    response = self.class.post(s3_import_url, :headers => @headers, :body => body.to_json)
    if(response.success?)
        NexosisApi::ImportsResponse.new(response.parsed_response)
    else
       raise HttpException.new("There was a problem importing from s3: #{response.code}.", "uploading dataset from s3 #{dataset_name}" ,response)
			    end
end

#list_importsArray of NexosisApi::ImportsResponse

List all existing import requests

Returns:


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nexosis_api/client/imports.rb', line 12

def list_imports
    imports_url = "/imports"
    response = self.class.get(imports_url, :headers => @headers)
    if(response.success?)
        items = []
        response.parsed_response["items"].each do |i|
            items << NexosisApi::ImportsResponse.new(i)
        end
        items
    else
       raise HttpException.new("There was a problem getting the imports: #{response.code}.", "uploading dataset from s3 #{dataset_name}" ,response)
			    end
end

#retrieve_import(import_id) ⇒ NexosisApi::ImportsResponse

Get s3 response back from import created previously. Presumably to check status.

Examples:

get S3 import

NexosisApi.client.retrieve_import('740dca2a-b488-4322-887e-fa473b1caa54')

Parameters:

  • import_id (String)

    The id returned from a previous request to import

Returns:


63
64
65
66
67
68
69
70
71
72
# File 'lib/nexosis_api/client/imports.rb', line 63

def retrieve_import(import_id)
    raise ArgumentError "import_id was not provided and is not optional " unless import_id.to_s.empty? == false
    imports_url = "/imports/#{import_id}"
    response = self.class.get(imports_url, :headers => @headers)
    if(response.success?)
        NexosisApi::ImportsResponse.new(response.parsed_response)
    else
       raise HttpException.new("There was a problem getting the import #{response.code}.", "requesting an import #{import_id}" ,response)
			    end
end