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.



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

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

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#encodingObject

Returns the value of attribute encoding.



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

def encoding
  @encoding
end

#payloadObject

Returns the value of attribute payload.



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

def payload
  @payload
end

#secret_tokenObject

Returns the value of attribute secret_token.



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

def secret_token
  @secret_token
end

Instance Method Details

#send_event(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



24
25
26
27
# File 'lib/load_runner/client.rb', line 24

def send_event(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.



30
31
32
33
34
# File 'lib/load_runner/client.rb', line 30

def send_payload(event, payload)
  @payload = payload.is_a?(String) ? payload : payload.to_json
  @payload = URI.encode_www_form(payload: @payload) if encoding == :form
  self.class.post "", body: @payload, headers: headers(event)
end