class Teamcity

Attributes

authentication[R]
host[R]
port[R]

Public Class Methods

new(host, port, options = {}) click to toggle source
# File lib/teamcity-rest-client.rb, line 168
def initialize host, port, options = {}
  @host, @port = host, port
  if options[:user] && options[:password]
    @authentication = TeamcityRestClient::HttpBasicAuthentication.new(host, port, options.delete(:user), options.delete(:password), options)
  else
    @authentication = TeamcityRestClient::Open.new(host, port, options)
  end
end

Public Instance Methods

build_types() click to toggle source
# File lib/teamcity-rest-client.rb, line 190
def build_types
  doc(get('/app/rest/buildTypes')).elements.collect('//buildType') do |e| 
    TeamcityRestClient::BuildType.new(self, e.av("id"), e.av("name"), url(e.av("href")), e.av('projectName'), e.av('projectId'), e.av('webUrl'))
  end
end
builds(options = {}) click to toggle source
# File lib/teamcity-rest-client.rb, line 196
def builds options = {}
  doc(get('/app/rest/builds', options).gsub(/&buildTypeId/,'&buildTypeId')).elements.collect('//build') do |e|
    TeamcityRestClient::Build.new(self, e.av('id'), e.av('number'), e.av('status').to_sym, e.av('buildTypeId'), e.av_or('startDate', ''), url(e.av('href')), e.av('webUrl'))
  end
end
project(spec) click to toggle source
# File lib/teamcity-rest-client.rb, line 177
def project spec
  field = spec =~ /project\d+/ ? :id : :name  
  project = projects.find { |p| p.send(field) == spec }
  raise "Sorry, cannot find project with name or id '#{spec}'" unless project
  project
end
projects() click to toggle source
# File lib/teamcity-rest-client.rb, line 184
def projects
  doc(get('/app/rest/projects')).elements.collect('//project') do |e| 
    TeamcityRestClient::Project.new(self, e.av("name"), e.av("id"), url(e.av("href")))
  end
end
to_s() click to toggle source
# File lib/teamcity-rest-client.rb, line 202
def to_s
  "Teamcity @ #{url("/")}"
end

Private Instance Methods

doc(string) click to toggle source
# File lib/teamcity-rest-client.rb, line 207
def doc string
  REXML::Document.new string
end
get(path, params = {}) click to toggle source
# File lib/teamcity-rest-client.rb, line 211
def get path, params = {}
  result = @authentication.get(path, params)
  raise "Teamcity returned html, perhaps you need to use authentication??" if result =~ /.*<html.*<\/html>.*/im
  result
end
url(path) click to toggle source
# File lib/teamcity-rest-client.rb, line 217
def url path
  @authentication.url(path)
end