Class: LimitedRed::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/limited_red/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, out = STDOUT, adapter = nil, thread_pool = ThreadPool) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
9
10
11
12
# File 'lib/limited_red/client.rb', line 3

def initialize(config, out = STDOUT, adapter = nil, thread_pool = ThreadPool)
  @config ||= config
  @out = out
  @username = @config['username']
  @api_key = @config['api key']
  @project_id = "#{@username}/#{@config['project name']}"
    
  @adapter = adapter || LimitedRed::Adapter::HttParty.new(@config)
  @thread_pool = thread_pool
end

Instance Method Details

#find_failing_featuresObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/limited_red/client.rb', line 46

def find_failing_features
  raise "No project name was found in params: #{@config.inspect}" if @project_id.nil?

  begin
    response = @adapter.get("/#{@project_id}/features/fails")
  rescue
    puts "[Limited Red] Unable to reach www.limited-red.com. No tests will be recorded."
    return []
  end

  if response.nil? || response.empty? || error?(response)
    return []
  else
    response.body.split(" ")
  end
end

#log_build(build_id, data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/limited_red/client.rb', line 34

def log_build(build_id, data)
  data[:build_id] = build_id
  data = data.merge({:user => @username, 
                     :version => LimitedRed::Version::STRING,
                     :build_id => build_id, :token => token_for(data)})
    
  @thread_pool.with_a_thread_run do
    response = @adapter.post("/#{@project_id}/builds", :body => data)
    log(response) if response && error?(response)
  end
end

#log_fail_result(build_id, data) ⇒ Object



14
15
16
# File 'lib/limited_red/client.rb', line 14

def log_fail_result(build_id, data)
  log_result(build_id, data.merge(:pass => 'false'))
end

#log_pass_result(build_id, data) ⇒ Object



18
19
20
# File 'lib/limited_red/client.rb', line 18

def log_pass_result(build_id, data)
  log_result(build_id, data.merge(:pass => 'true'))
end

#log_result(build_id, data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/limited_red/client.rb', line 22

def log_result(build_id, data)
  data[:result] = @adapter.encode_and_compress(data[:result])
  data = data.merge({:user => @username, 
                     :version => LimitedRed::Version::STRING,
                     :token => token_for(data.merge(:build_id => build_id))})

  @thread_pool.with_a_thread_run do
    response = @adapter.post("/#{@project_id}/builds/#{build_id}/results", :body => data)
    log(response) if error?(response)
  end
end