Class: DataValidation::Job
- Inherits:
-
Object
- Object
- DataValidation::Job
- Defined in:
- lib/data_validation/job.rb
Instance Attribute Summary collapse
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #done? ⇒ Boolean
- #get(slug) ⇒ Object
-
#initialize(api, list) ⇒ Job
constructor
A new instance of Job.
Constructor Details
#initialize(api, list) ⇒ Job
Returns a new instance of Job.
17 18 19 20 21 |
# File 'lib/data_validation/job.rb', line 17 def initialize(api, list) @api = api @list = list @slug = nil end |
Instance Attribute Details
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
3 4 5 |
# File 'lib/data_validation/job.rb', line 3 def slug @slug end |
Class Method Details
.create(api, list) ⇒ Object
5 6 7 8 9 |
# File 'lib/data_validation/job.rb', line 5 def self.create(api, list) job = DataValidation::Job.new(api, list) job.create job end |
.get(api, list, slug) ⇒ Object
11 12 13 14 15 |
# File 'lib/data_validation/job.rb', line 11 def self.get(api, list, slug) job = DataValidation::Job.new(api, list) job.get(slug) job end |
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/data_validation/job.rb', line 23 def create response = @api.post("list/#{@list.slug}/job/") if @api.valid_response?(response) raw = JSON.parse(response.body) raw_job = raw["job"][0] @slug = raw_job["slug"] else p response raise DataValidation::Error, "could not create job for list #{@list.slug}" end end |
#done? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/data_validation/job.rb', line 39 def done? response = @api.get("list/#{@list.slug}/job/#{@slug}/") if @api.valid_response?(response) raw = JSON.parse(response.body) raw_job = raw["job"][0] raw_pct = raw_job["pct_complete"] return raw_pct == 100 else raise DataValidationError, "could not check job progress for list #{@list.slug}, job #{@job.slug}" end end |
#get(slug) ⇒ Object
35 36 37 |
# File 'lib/data_validation/job.rb', line 35 def get(slug) @slug = slug end |