Class: EasyManageClient::Downloader
- Defined in:
- lib/easy_manage_client/downloader.rb
Overview
Downloader
Instance Attribute Summary
Attributes inherited from Core
#connection, #profile, #response, #success
Instance Method Summary collapse
-
#compiled_version_uri ⇒ Object
Returns request uri from specified version.
-
#latest_version_uri ⇒ Object
Returns request uri for latest version.
-
#perform ⇒ Object
Call api, handle response, perform all actions according to success.
-
#perform! ⇒ Object
CRASH! If unsuccessful.
-
#prepare_file_path_to_download ⇒ Object
Prepares a file path from the specified extension and download folder.
-
#request_uri ⇒ Object
It decides which api endpoint to use and returns this endpoit.
-
#write_to_folder ⇒ Object
Write content to download folder.
Methods inherited from Core
#generate_bearer_token, #handle_response, #headers, #initialize, #params
Constructor Details
This class inherits a constructor from EasyManageClient::Core
Instance Method Details
#compiled_version_uri ⇒ Object
Returns request uri from specified version.
43 44 45 46 |
# File 'lib/easy_manage_client/downloader.rb', line 43 def compiled_version_uri '/api/projects/by_reference/' + ::EasyManageClient.configuration(profile).compile_id.to_s end |
#latest_version_uri ⇒ Object
Returns request uri for latest version.
49 50 51 |
# File 'lib/easy_manage_client/downloader.rb', line 49 def latest_version_uri '/api/projects/latest_compiled_version' end |
#perform ⇒ Object
Call api, handle response, perform all actions according to success. Method returns true or false.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/easy_manage_client/downloader.rb', line 19 def perform # make api call and handle response super # If success is not true, stop operation and return false. return false unless success # Download data to the relevant location. write_to_folder true end |
#perform! ⇒ Object
CRASH! If unsuccessful.
32 33 34 35 36 37 38 39 40 |
# File 'lib/easy_manage_client/downloader.rb', line 32 def perform! perform unless success raise ::EasyManageClient::DownloadProcessFailed, response[:message] end # Everything is OK. true end |
#prepare_file_path_to_download ⇒ Object
Prepares a file path from the specified extension and download folder.
61 62 63 64 65 |
# File 'lib/easy_manage_client/downloader.rb', line 61 def prepare_file_path_to_download folder = ::EasyManageClient.configuration(profile).download_folder file_extension = ::EasyManageClient.configuration(profile).file_extension File.join(folder, "#{response[:reference]}.#{file_extension}") end |
#request_uri ⇒ Object
It decides which api endpoint to use and returns this endpoit.
7 8 9 10 11 12 13 14 15 |
# File 'lib/easy_manage_client/downloader.rb', line 7 def request_uri # if version not specified, use latest uri if ::EasyManageClient.configuration(profile).compile_id.nil? return latest_version_uri end # generate compiled_version_uri compiled_version_uri end |
#write_to_folder ⇒ Object
Write content to download folder.
54 55 56 57 58 |
# File 'lib/easy_manage_client/downloader.rb', line 54 def write_to_folder File.open(prepare_file_path_to_download, 'w') do |file| file.write(response[:content]) end end |