class Toxiproxy::Toxic
Attributes
attributes[RW]
name[R]
proxy[R]
stream[R]
toxicity[RW]
type[R]
Public Class Methods
new(attrs)
click to toggle source
# File lib/toxiproxy/toxic.rb, line 6 def initialize(attrs) raise "Toxic type is required" unless attrs[:type] @type = attrs[:type] @stream = attrs[:stream] || 'downstream' @name = attrs[:name] || "#{@type}_#{@stream}" @proxy = attrs[:proxy] @toxicity = attrs[:toxicity] || 1.0 @attributes = attrs[:attributes] || {} end
Public Instance Methods
as_json()
click to toggle source
# File lib/toxiproxy/toxic.rb, line 39 def as_json { name: name, type: type, stream: stream, toxicity: toxicity, attributes: attributes, }.to_json end
destroy()
click to toggle source
# File lib/toxiproxy/toxic.rb, line 32 def destroy request = Net::HTTP::Delete.new("/proxies/#{proxy.name}/toxics/#{name}") response = Toxiproxy.http_request(request) Toxiproxy.assert_response(response) self end
save()
click to toggle source
# File lib/toxiproxy/toxic.rb, line 16 def save request = Net::HTTP::Post.new("/proxies/#{proxy.name}/toxics") request["Content-Type"] = "application/json" request.body = as_json response = Toxiproxy.http_request(request) Toxiproxy.assert_response(response) json = JSON.parse(response.body) @attributes = json['attributes'] @toxicity = json['toxicity'] self end