Class: EasyManageClient::Downloader

Inherits:
Core
  • Object
show all
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

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_uriObject



37
38
39
40
# File 'lib/easy_manage_client/downloader.rb', line 37

def compiled_version_uri
  '/api/projects/by_reference/' +
    ::EasyManageClient.configuration(profile).compile_id.to_s
end

#latest_version_uriObject



42
43
44
# File 'lib/easy_manage_client/downloader.rb', line 42

def latest_version_uri
  '/api/projects/latest_compiled_version'
end

#performObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/easy_manage_client/downloader.rb', line 16

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



28
29
30
31
32
33
34
35
# File 'lib/easy_manage_client/downloader.rb', line 28

def perform!
  perform
  unless success
    raise ::EasyManageClient::DownloadProcessFailed, response[:message]
  end

  true
end

#prepare_file_path_to_downloadObject



52
53
54
55
56
# File 'lib/easy_manage_client/downloader.rb', line 52

def prepare_file_path_to_download
  folder = ::EasyManageClient.configuration(profile).download_folder
  extension = ::EasyManageClient.configuration(profile).extension
  File.join(folder, "#{response[:reference]}.#{extension}")
end

#request_uriObject



6
7
8
9
10
11
12
13
14
# File 'lib/easy_manage_client/downloader.rb', line 6

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_folderObject



46
47
48
49
50
# File 'lib/easy_manage_client/downloader.rb', line 46

def write_to_folder
  File.open(prepare_file_path_to_download, 'w') do |file|
    file.write(response[:content])
  end
end