Class: Ecoportal::API::V2::S3

Inherits:
Object
  • Object
show all
Extended by:
Common::BaseClass
Defined in:
lib/ecoportal/api/v2/s3.rb,
lib/ecoportal/api/v2/s3/data.rb,
lib/ecoportal/api/v2/s3/files.rb,
lib/ecoportal/api/v2/s3/upload.rb,
lib/ecoportal/api/v2/s3/files/poll.rb,
lib/ecoportal/api/v2/s3/files/poll_status.rb,
lib/ecoportal/api/v2/s3/files/batch_upload.rb

Defined Under Namespace

Classes: CredentialsGetFailed, Data, Files, MissingLocalFile, Upload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Schemas

Returns an instance object ready to make schema api requests.

Parameters:

  • client (Ecoportal::API::Common::Client)

    a Ecoportal::API::Common::Client object that holds the configuration of the api connection.



19
20
21
# File 'lib/ecoportal/api/v2/s3.rb', line 19

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientEcoportal::API::Common::Client (readonly)

a Ecoportal::API::Common::Client object that holds the configuration of the api connection.

Returns:

  • (Ecoportal::API::Common::Client)

    the current value of client



5
6
7
# File 'lib/ecoportal/api/v2/s3.rb', line 5

def client
  @client
end

Instance Method Details

#dataEcoportal::API::V2::S3::Data

Gets the S3 credentials to upload files



25
26
27
28
29
30
31
32
33
# File 'lib/ecoportal/api/v2/s3.rb', line 25

def data
  response = client.get("/s3/data")
  body     = body_data(response.body)

  return data_class.new(body) if response.success?

  msg = "Could not get S3 credentials - Error #{response.status}: #{body}"
  raise CredentialsGetFailed, msg
end

#filesFiles

Obtain specific object for eP file api requests.

Returns:

  • (Files)

    an instance object ready to make eP file api requests.



48
49
50
# File 'lib/ecoportal/api/v2/s3.rb', line 48

def files
  files_class.new(client, s3_api: self)
end

#upload_file(file, credentials: data, &block) ⇒ Hash, NilClass

Returns with the s3_file_reference on success, and nil otherwise.

Parameters:

Returns:

  • (Hash, NilClass)

    with the s3_file_reference on success, and nil otherwise

Raises:



38
39
40
41
42
43
44
# File 'lib/ecoportal/api/v2/s3.rb', line 38

def upload_file(file, credentials: data, &block)
  msg = "The file '#{file}' does not exist"
  raise MissingLocalFile, msg unless File.exist?(file)

  credentials ||= data
  Upload.new(credentials, file: file).upload!(&block)
end