Class: Coconut::Job

Inherits:
API
  • Object
show all
Defined in:
lib/coconut/job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from API

headers, request

Constructor Details

#initialize(attrs = {}) ⇒ Job

Returns a new instance of Job.



5
6
7
8
9
10
11
12
13
# File 'lib/coconut/job.rb', line 5

def initialize(attrs={})
  @id = attrs["id"]
  @created_at = attrs["created_at"]
  @completed_at = attrs["completed_at"]
  @status = attrs["status"]
  @progress = attrs["progress"]
  @errors = attrs["errors"]
  @output_urls = attrs["output_urls"]
end

Instance Attribute Details

#completed_atObject (readonly)

Returns the value of attribute completed_at.



3
4
5
# File 'lib/coconut/job.rb', line 3

def completed_at
  @completed_at
end

#created_atObject (readonly)

Returns the value of attribute created_at.



3
4
5
# File 'lib/coconut/job.rb', line 3

def created_at
  @created_at
end

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/coconut/job.rb', line 3

def errors
  @errors
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/coconut/job.rb', line 3

def id
  @id
end

#output_urlsObject (readonly)

Returns the value of attribute output_urls.



3
4
5
# File 'lib/coconut/job.rb', line 3

def output_urls
  @output_urls
end

#progressObject (readonly)

Returns the value of attribute progress.



3
4
5
# File 'lib/coconut/job.rb', line 3

def progress
  @progress
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/coconut/job.rb', line 3

def status
  @status
end

Class Method Details

.apply_settings(job) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/coconut/job.rb', line 28

def self.apply_settings(job)
  if notification = Coconut.notification
    job[:notification] ||= {}
    job[:notification].merge!(notification)
  end

  if storage = Coconut.storage
    job[:storage] ||= {}
    job[:storage].merge!(storage)
  end

  return job
end

.create(job, options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/coconut/job.rb', line 20

def self.create(job, options={})
  resp = API.request(:post, "/jobs", options.merge({
    json: apply_settings(job)
  }))

  return Job.new(resp)
end

.retrieve(job_id, options = {}) ⇒ Object



15
16
17
18
# File 'lib/coconut/job.rb', line 15

def self.retrieve(job_id, options={})
  resp = API.request(:get, "/jobs/#{job_id}", options)
  return Job.new(resp)
end