Class: AmpelExtase::JenkinsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ampel_extase/jenkins_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ JenkinsClient

Returns a new instance of JenkinsClient.



8
9
10
11
# File 'lib/ampel_extase/jenkins_client.rb', line 8

def initialize(url)
  url = URI.parse(url.to_s) unless URI::HTTP === url
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/ampel_extase/jenkins_client.rb', line 13

def url
  @url
end

Instance Method Details

#api_url(*path) ⇒ Object



15
16
17
# File 'lib/ampel_extase/jenkins_client.rb', line 15

def api_url(*path)
  [ @url, *path, 'api', 'json' ].compact * '/'
end

#fetch(url = api_url) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/ampel_extase/jenkins_client.rb', line 19

def fetch(url = api_url)
  puts "Fetching #{url.to_s.inspect}."
  JSON open(url).read
rescue => e
  e.message << " for #{url.inspect}"
  raise
end

#fetch_build(type) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/ampel_extase/jenkins_client.rb', line 27

def fetch_build(type)
  url = if sym = type.ask_and_send(:to_sym)
          key = sym.to_s.camelize(:lower)
          key[0, 1] = key[0, 1].downcase
          api_url(key)
        else
          api_url(type)
        end
  fetch url
end