Class: Tc4r::Client
- Inherits:
-
Object
- Object
- Tc4r::Client
- Defined in:
- lib/tc4r/client.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #base_url ⇒ Object
- #build(bt, number) ⇒ Object
- #build_type(bt) ⇒ Object
- #build_types ⇒ Object
- #download_file(bt, number, file, options = {}) ⇒ Object
- #download_url(path) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #merge_options(options) ⇒ Object
- #progress_bar ⇒ Object
- #query_builds(bt, options = {}) ⇒ Object
- #rest_url(path) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tc4r/client.rb', line 13 def initialize( = {}) = { :server => 'localhost', :port => 8111, :username => nil, :password => nil, :transport => :http } = .merge() @server = [:server] @port = [:port] @username = [:username] @password = [:password] @transport = [:transport] end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/tc4r/client.rb', line 10 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/tc4r/client.rb', line 8 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
7 8 9 |
# File 'lib/tc4r/client.rb', line 7 def server @server end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
11 12 13 |
# File 'lib/tc4r/client.rb', line 11 def transport @transport end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/tc4r/client.rb', line 9 def username @username end |
Instance Method Details
#base_url ⇒ Object
29 30 31 |
# File 'lib/tc4r/client.rb', line 29 def base_url @base_url ||= "#{transport}://#{server}:#{port}/httpAuth" end |
#build(bt, number) ⇒ Object
70 71 72 73 |
# File 'lib/tc4r/client.rb', line 70 def build(bt,number) build = Nestful.get rest_url("buildTypes/id:#{bt}/builds/number:#{number}") , ( :format => :json ) Tc4r::Build.new(Tc4r::Helpers.sym_score(build), self) end |
#build_type(bt) ⇒ Object
54 55 56 57 |
# File 'lib/tc4r/client.rb', line 54 def build_type(bt) build_type = Nestful.get rest_url("buildTypes/id:#{bt}") , ( :format => :json ) BuildType.new(Tc4r::Helpers.sym_score(build_type), self) end |
#build_types ⇒ Object
47 48 49 50 51 52 |
# File 'lib/tc4r/client.rb', line 47 def build_types bts = Nestful.get rest_url('buildTypes') , ( :format => :json ) bts['buildType'].collect do |bt| BuildType.new(Tc4r::Helpers.sym_score(bt), self) end end |
#download_file(bt, number, file, options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tc4r/client.rb', line 75 def download_file(bt,number,file, = {}) = {:with_progress => true, :destination => File.("./#{File.basename(file)}")} = .merge() download_parameters = {:buffer => true} download_parameters[:buffer_binmode] = true if [:with_progress] download_parameters[:progress] = end build = build(bt,number) f = Nestful.get download_url("#{bt}/#{build.id}:id/#{file}"), ( download_parameters ) f.close FileUtils.mv(f.path,[:destination]) end |
#download_url(path) ⇒ Object
37 38 39 |
# File 'lib/tc4r/client.rb', line 37 def download_url(path) "#{base_url}/repository/download/#{path}" end |
#merge_options(options) ⇒ Object
41 42 43 44 45 |
# File 'lib/tc4r/client.rb', line 41 def () { :user => username, :password => password, :auth_type => :basic }.merge() end |
#progress_bar ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/tc4r/client.rb', line 92 def Proc.new do |conn, total, size| @progress ||= Commander::UI::ProgressBar.new total, :title => "Downloading Build", :complete_message => "File download complete" @last_pct ||= 0 current_pct = ((size.to_f/total.to_f)*100).floor @progress.instance_variable_set('@step',size) if current_pct != @last_pct @progress.show @last_pct = current_pct end if @progress.finished? @progress = nil end end end |
#query_builds(bt, options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tc4r/client.rb', line 59 def query_builds(bt, = {}) parameters = {} parameters[:status] = 'SUCCESS' if [:status] == :success parameters[:status] = 'ERROR' if [:status] == :error parameters[:tag] = [:tag] if [:tag] builds = Nestful.get rest_url("buildTypes/id:#{bt}/builds") , ( :format => :json, :params => parameters ) builds['build'].collect do |build| Build.new(Tc4r::Helpers.sym_score(build),self) end end |
#rest_url(path) ⇒ Object
33 34 35 |
# File 'lib/tc4r/client.rb', line 33 def rest_url(path) "#{base_url}/app/rest/#{path}" end |