class Bamboo::Client
Attributes
host[RW]
Public Class Methods
new(host)
click to toggle source
# File lib/bamboo/client.rb, line 7 def initialize(host) @host = host @uri = URI(host) @http = Net::HTTP.new(@uri.host, @uri.port) @http.use_ssl = @uri.is_a?(URI::HTTPS) @http.start # for keep-alive end
Public Instance Methods
apps()
click to toggle source
@returns Array<Hash>
# File lib/bamboo/client.rb, line 34 def apps state.fetch('Apps') end
create_service(id, definition)
click to toggle source
# File lib/bamboo/client.rb, line 16 def create_service(id, definition) post('/api/services', { 'Id' => id }.merge(definition)) end
delete_service(id)
click to toggle source
# File lib/bamboo/client.rb, line 24 def delete_service(id) delete(service_path(id)) true end
get_service(id)
click to toggle source
# File lib/bamboo/client.rb, line 29 def get_service(id) state.fetch('Services')[id] end
services()
click to toggle source
@returns Array<Hash>
# File lib/bamboo/client.rb, line 39 def services state.fetch('Services').values end
state()
click to toggle source
# File lib/bamboo/client.rb, line 43 def state get('/api/state') end
update_service(id, definition)
click to toggle source
# File lib/bamboo/client.rb, line 20 def update_service(id, definition) put(service_path(id), { 'Id' => id }.merge(definition)) end
Private Instance Methods
delete(path)
click to toggle source
# File lib/bamboo/client.rb, line 63 def delete(path) request Net::HTTP::Delete.new(path) end
get(path)
click to toggle source
# File lib/bamboo/client.rb, line 71 def get(path) request Net::HTTP::Get.new(path) end
handle_response(response)
click to toggle source
# File lib/bamboo/client.rb, line 94 def handle_response(response) case response when Net::HTTPSuccess parse_response(response) else raise InvalidResponseError, response end end
parse_response(response)
click to toggle source
# File lib/bamboo/client.rb, line 103 def parse_response(response) case body = response.body when 'null' then nil when String then JSON.parse(body) end end
post(path, body)
click to toggle source
# File lib/bamboo/client.rb, line 59 def post(path, body) request Net::HTTP::Post.new(path), body end
put(path, body)
click to toggle source
# File lib/bamboo/client.rb, line 67 def put(path, body) request Net::HTTP::Put.new(path), body end
request(req, body = nil)
click to toggle source
# File lib/bamboo/client.rb, line 79 def request(req, body = nil) req.body = case body when String then body else JSON.generate(body) end if req.request_body_permitted? req.content_type = 'application/json' if @uri.user || @uri.password req.basic_auth(@uri.user, @uri.password) end handle_response @http.request(req) end
service_path(id)
click to toggle source
# File lib/bamboo/client.rb, line 75 def service_path(id) File.join('/api/services', id.to_s.gsub('/','%252F')) end