Class: GoApiClient::Job

Inherits:
Object
  • Object
show all
Includes:
Helpers::SimpleAttributesSupport
Defined in:
lib/go_api_client/job.rb

Constant Summary collapse

PROPERTIES =
{
  :duration   => :cruise_job_duration,
  :result     => :cruise_job_result,
  :scheduled  => :cruise_timestamp_01_scheduled,
  :assigned   => :cruise_timestamp_02_assigned,
  :preparing  => :cruise_timestamp_03_preparing,
  :building   => :cruise_timestamp_04_building,
  :completing => :cruise_timestamp_05_completing,
  :completed  => :cruise_timestamp_06_completed,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, attributes = {}) ⇒ Job

Returns a new instance of Job.



20
21
22
23
# File 'lib/go_api_client/job.rb', line 20

def initialize(root, attributes={})
  @root = root
  super(attributes)
end

Instance Attribute Details

#artifactsObject

Returns the value of attribute artifacts.



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

def artifacts
  @artifacts
end

#artifacts_uriObject

Returns the value of attribute artifacts_uri.



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

def artifacts_uri
  @artifacts_uri
end

#console_log_urlObject

Returns the value of attribute console_log_url.



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

def console_log_url
  @console_log_url
end

#http_fetcherObject

Returns the value of attribute http_fetcher.



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

def http_fetcher
  @http_fetcher
end

#identifierObject

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.from(url, attributes = {}) ⇒ Object



26
27
28
29
30
# File 'lib/go_api_client/job.rb', line 26

def from(url, attributes = {})
  attributes[:http_fetcher] ||= GoApiClient::HttpFetcher.new
  doc = Nokogiri::XML(attributes[:http_fetcher].get!(url))
  self.new(doc.root, attributes).parse!
end

Instance Method Details

#parse!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/go_api_client/job.rb', line 33

def parse!
  self.artifacts_uri = @root.xpath("./artifacts").first.attributes["baseUri"].value
  self.url           = href_from(@root.xpath("./link[@rel='self']"))
  self.identifier    = @root.xpath('./id').first.content
  self.name          = @root.attributes['name'].value
  self.artifacts     = @root.xpath("./artifacts/artifact").collect do |artifact_element|
                        Artifact.from(self.artifacts_uri, artifact_element)
                      end
  
  PROPERTIES.each do |variable, property_name|
    property_value = @root.xpath("./properties/property[@name='#{property_name}']").first.content rescue nil

    next if property_value.nil? || property_value.empty?

    if property_name =~ /timestamp/
      property_value = Time.parse(property_value).utc
    elsif property_value =~ /^\d+$/
      property_value = property_value.to_i
    end
    self.send("#{variable}=", property_value)
  end

  @root = nil
  self
end