Class: Ecoportal::API::V2::S3
- Inherits:
-
Object
- Object
- Ecoportal::API::V2::S3
- 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
-
#client ⇒ Ecoportal::API::Common::Client
readonly
a
Ecoportal::API::Common::Client
object that holds the configuration of the api connection.
Instance Method Summary collapse
-
#data ⇒ Ecoportal::API::V2::S3::Data
Gets the S3 credentials to upload files.
-
#files ⇒ Files
Obtain specific object for eP file api requests.
-
#initialize(client) ⇒ Schemas
constructor
An instance object ready to make schema api requests.
-
#upload_file(file, credentials: data, &block) ⇒ Hash, NilClass
With the s3_file_reference on success, and
nil
otherwise.
Constructor Details
#initialize(client) ⇒ Schemas
Returns an instance object ready to make schema api requests.
19 20 21 |
# File 'lib/ecoportal/api/v2/s3.rb', line 19 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Ecoportal::API::Common::Client (readonly)
a Ecoportal::API::Common::Client
object that holds the configuration of the api connection.
5 6 7 |
# File 'lib/ecoportal/api/v2/s3.rb', line 5 def client @client end |
Instance Method Details
#data ⇒ Ecoportal::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 |
#files ⇒ Files
Obtain specific object for 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.
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 |