Class: Codescout::Runner::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/codescout/runner/client.rb', line 7

def initialize(url)
  @url = url
end

Instance Method Details

#connectionObject



34
35
36
37
38
39
# File 'lib/codescout/runner/client.rb', line 34

def connection
  @connection ||= Faraday.new(@url) do |c|
    c.use(Faraday::Request::UrlEncoded)
    c.adapter(Faraday.default_adapter)
  end
end

#fetch_push(token) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/codescout/runner/client.rb', line 11

def fetch_push(token)
  response = connection.get("/worker/push/#{token}")
  json = JSON.load(response.body)
  obj = Hashie::Mash.new(json)

  if obj.error
    raise Codescout::Runner::ClientError, obj.error
  end

  obj

rescue JSON::ParserError => err
  raise Codescout::Runner::ClientError, err.message
rescue Faraday::ConnectionFailed => err
  raise Codescout::Runner::ClientError, err.message
end

#send_payload(token, payload) ⇒ Object



28
29
30
31
32
# File 'lib/codescout/runner/client.rb', line 28

def send_payload(token, payload)
  connection.post("/worker/payload/#{token}", payload) do |c|
    c.headers["Content-Type"] = "text/plain"
  end
end