Class: RemoteTranslationLoader::Fetchers::S3Fetcher

Inherits:
BaseFetcher
  • Object
show all
Defined in:
lib/remote_translation_loader/fetchers/s3_fetcher.rb

Instance Method Summary collapse

Methods inherited from BaseFetcher

#format_for, #parse

Constructor Details

#initialize(bucket, s3_client: nil) ⇒ S3Fetcher

Returns a new instance of S3Fetcher.



6
7
8
9
# File 'lib/remote_translation_loader/fetchers/s3_fetcher.rb', line 6

def initialize(bucket, s3_client: nil)
  @bucket = bucket
  @s3_client_override = s3_client
end

Instance Method Details

#fetch(key) ⇒ Object



11
12
13
14
15
16
# File 'lib/remote_translation_loader/fetchers/s3_fetcher.rb', line 11

def fetch(key)
  response = s3_client.get_object(bucket: @bucket, key: key)
  parse(response.body.read, format: format_for(key))
rescue Aws::S3::Errors::ServiceError => e
  raise FetchError, "Failed to fetch #{key} from S3 bucket #{@bucket}: #{e.message}"
end