Class: CopyleaksApi::CopyleaksProcess
- Inherits:
-
Object
- Object
- CopyleaksApi::CopyleaksProcess
- Defined in:
- lib/copyleaks_api/copyleaks_process.rb
Constant Summary collapse
- STATUSES =
['processing', 'ready', 'allocated', 'finished', 'error', 'deleted'].freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#custom_fields ⇒ Object
Returns the value of attribute custom_fields.
-
#process_id ⇒ Object
Returns the value of attribute process_id.
-
#progress ⇒ Object
Returns the value of attribute progress.
-
#status ⇒ Object
returns status information or reload if no data is specified.
Class Method Summary collapse
-
.create(cloud, hash) ⇒ Object
create CopyleaksProcess based on data got from any create endpoint.
-
.create_from_list(cloud, hash) ⇒ Object
creates CopyleaksProcess based on data got from list endpoint.
-
.create_from_result(cloud, id, result) ⇒ Object
creates CopyleaksProcess based on data got from result endpoint.
-
.create_from_status(cloud, id, hash) ⇒ Object
create CopyleaksProcess based on data got from status endpoint.
Instance Method Summary collapse
-
#delete ⇒ Object
deletes process from API.
-
#initialize(options) ⇒ CopyleaksProcess
constructor
constructor.
-
#processing? ⇒ Boolean
returns true if process status means processing data on server side.
-
#reload ⇒ Object
reload object attributes using status endpoint.
-
#result ⇒ Object
return result data or retrieves from result endpoint if nothing specified.
Constructor Details
#initialize(options) ⇒ CopyleaksProcess
constructor
10 11 12 13 14 15 16 17 18 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 10 def initialize() @cloud = [:cloud] [:cloud, :process_id, :custom_fields, :result, :status, :progress].each do |attr| instance_variable_set("@#{attr}", [attr]) if [attr] end @created_at = DateTime.parse([:created_at]) if [:created_at] @status = STATUSES[[:status_code].to_i + 1] if [:status_code] end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 7 def created_at @created_at end |
#custom_fields ⇒ Object
Returns the value of attribute custom_fields.
7 8 9 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 7 def custom_fields @custom_fields end |
#process_id ⇒ Object
Returns the value of attribute process_id.
7 8 9 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 7 def process_id @process_id end |
#progress ⇒ Object
Returns the value of attribute progress.
7 8 9 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 7 def progress @progress end |
#status ⇒ Object
returns status information or reload if no data is specified
39 40 41 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 39 def status @status end |
Class Method Details
.create(cloud, hash) ⇒ Object
create CopyleaksProcess based on data got from any create endpoint
61 62 63 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 61 def create(cloud, hash) new(cloud: cloud, process_id: hash['ProcessId'], created_at: hash['CreationTimeUTC']) end |
.create_from_list(cloud, hash) ⇒ Object
creates CopyleaksProcess based on data got from list endpoint
76 77 78 79 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 76 def create_from_list(cloud, hash) new(cloud: cloud, process_id: hash['ProcessId'], created_at: hash['CreationTimeUTC'], status: hash['Status'].downcase, custom_fields: hash['CustomFields']) end |
.create_from_result(cloud, id, result) ⇒ Object
creates CopyleaksProcess based on data got from result endpoint
71 72 73 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 71 def create_from_result(cloud, id, result) new(cloud: cloud, process_id: id, result: result) end |
.create_from_status(cloud, id, hash) ⇒ Object
create CopyleaksProcess based on data got from status endpoint
66 67 68 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 66 def create_from_status(cloud, id, hash) new(cloud: cloud, process_id: id, status: hash['Status'].downcase, progress: hash['ProgressPercents']) end |
Instance Method Details
#delete ⇒ Object
deletes process from API
45 46 47 48 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 45 def delete @cloud.delete(process_id) @status = 'deleted' end |
#processing? ⇒ Boolean
returns true if process status means processing data on server side
29 30 31 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 29 def processing? ['ready', 'allocated', 'processing'].include?(@status) end |
#reload ⇒ Object
reload object attributes using status endpoint
51 52 53 54 55 56 57 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 51 def reload response = @cloud.status(process_id, raw: true) @status = response['Status'].downcase @progress = response['ProgressPercents'].to_i @result = nil self end |
#result ⇒ Object
return result data or retrieves from result endpoint if nothing specified
34 35 36 |
# File 'lib/copyleaks_api/copyleaks_process.rb', line 34 def result @result ||= @cloud.result(process_id, raw: true) end |