Class: Loadrunner::Client
- Inherits:
-
Object
- Object
- Loadrunner::Client
- Includes:
- HTTParty
- Defined in:
- lib/loadrunner/client.rb
Overview
Send simulated GitHub events to any webhook server
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#host ⇒ Object
Returns the value of attribute host.
-
#host_path ⇒ Object
Returns the value of attribute host_path.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#secret_token ⇒ Object
Returns the value of attribute secret_token.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#send_event(event = :push, opts = {}) ⇒ Object
Send a simulated event using a shorthand syntax.
-
#send_payload(event, payload) ⇒ Object
Send a simulated event.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/loadrunner/client.rb', line 11 def initialize(opts={}) @secret_token = opts[:secret_token] @encoding = opts[:encoding] || :json base_url = opts[:base_url] || 'http://localhost:3000' base_url = "http://#{base_url}" unless base_url =~ /^http/ url_parts = URI.parse base_url @host_path = url_parts.path url_parts.path = '' @host = url_parts.to_s self.class.base_uri host end |
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
9 10 11 |
# File 'lib/loadrunner/client.rb', line 9 def encoding @encoding end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/loadrunner/client.rb', line 9 def host @host end |
#host_path ⇒ Object
Returns the value of attribute host_path.
9 10 11 |
# File 'lib/loadrunner/client.rb', line 9 def host_path @host_path end |
#payload ⇒ Object
Returns the value of attribute payload.
9 10 11 |
# File 'lib/loadrunner/client.rb', line 9 def payload @payload end |
#secret_token ⇒ Object
Returns the value of attribute secret_token.
9 10 11 |
# File 'lib/loadrunner/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 exampleref/heads/branchname
) -
branch
: branch name -
tag
: tag name
33 34 35 36 |
# File 'lib/loadrunner/client.rb', line 33 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.
39 40 41 42 43 |
# File 'lib/loadrunner/client.rb', line 39 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 host_path, body: @payload, headers: headers(event) end |