Class: LoadRunner::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/load_runner/client.rb

Overview

Send simulated GitHub events to any webhook server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/load_runner/client.rb', line 10

def initialize(opts={})
  @secret_token = opts[:secret_token]
  @base_url = opts[:base_url] || 'localhost:3000'
  self.class.base_uri base_url
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



8
9
10
# File 'lib/load_runner/client.rb', line 8

def base_url
  @base_url
end

#payloadObject

Returns the value of attribute payload.



8
9
10
# File 'lib/load_runner/client.rb', line 8

def payload
  @payload
end

#secret_tokenObject

Returns the value of attribute secret_token.



8
9
10
# File 'lib/load_runner/client.rb', line 8

def secret_token
  @secret_token
end

Instance Method Details

#send(event = :push, opts = {}) ⇒ Object

Send a simulated event using a shorthand syntax. opts can contain any of these:

  • repo: repository name

  • ref: ref ID (for example ref/heads/branchname)

  • branch: branch name

  • tag: tag name



22
23
24
25
# File 'lib/load_runner/client.rb', line 22

def send(event=:push, opts={})
  payload = build_payload opts
  send_payload event, payload
end

#send_payload(event, payload) ⇒ Object

Send a simulated event. Payload can be a hash or a JSON string.



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

def send_payload(event, payload)
  @payload = payload.is_a?(String) ? payload : payload.to_json
  headers = headers event
  self.class.post "/payload", body: @payload, headers: headers
end