Class: Circus::ActStoreClient

Inherits:
Object
  • Object
show all
Defined in:
lib/circus/actstore_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, logger) ⇒ ActStoreClient

Returns a new instance of ActStoreClient.



3
4
5
6
# File 'lib/circus/actstore_client.rb', line 3

def initialize(root, logger)
  @root = root
  @logger = logger
end

Instance Method Details

#upload_act(fn) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/circus/actstore_client.rb', line 8

def upload_act(fn)
  actname = File.basename(fn)
  upload_url = "#{@root}/#{actname}"
  
  @logger.info "Uploading to #{upload_url}"
  uri = URI.parse(upload_url)
  
  res = Net::HTTP.start(uri.host, uri.port) do |http|
    req = Net::HTTP::Put.new(uri.request_uri)
    req.body = File.read(fn)
    req.content_type = 'application/binary'
    
    http.request req
  end
  unless res.is_a? Net::HTTPSuccess
    @logger.error "FAILED: Act Upload"
    @logger.error "  Status:   #{res.code}"
    @logger.error "  Response: #{res.body}"
    return false
  end
end