class Octogate::Client
Attributes
event[R]
Public Class Methods
new(event)
click to toggle source
# File lib/octogate/client.rb, line 9 def initialize(event) @event = event end
Public Instance Methods
request(target)
click to toggle source
# File lib/octogate/client.rb, line 21 def request(target) uri = URI(target.url) options = {url: target.url} options.merge!(ssl_options) if uri.scheme == "https" conn = build_connection(options, target.username, target.password) params = target.params.is_a?(Proc) ? target.instance_exec(event, &target.params) : target.params case target.http_method when :get Octogate::TransferRequest::GET.new(conn) .do_request(url: uri.path, params: params) when :post Octogate::TransferRequest::POST.new(conn) .do_request(url: uri.path, params: params, parameter_type: target.parameter_type) end sent_event = Octogate::SentEvent.build(event, target, params) Octogate.add_sent(sent_event) end
request_to_targets()
click to toggle source
# File lib/octogate/client.rb, line 13 def request_to_targets Octogate.config.targets.each do |target_name, t| if match_target?(t) request(t) end end end
Private Instance Methods
build_connection(options, username = nil, password = nil)
click to toggle source
# File lib/octogate/client.rb, line 59 def build_connection(options, username = nil, password = nil) conn = Faraday.new(options) do |faraday| faraday.request :url_encoded faraday.response :logger if ENV["RACK_ENV"] == "development" || ENV["RACK_ENV"] == "production" faraday.adapter Faraday.default_adapter end conn.basic_auth(username, password) if username && password conn end
match_target?(target)
click to toggle source
# File lib/octogate/client.rb, line 47 def match_target?(target) condition = event.default_condition && target.include_event?(event) case target.match when Proc condition && target.instance_exec(event, &target.match) when nil condition else condition && !!target.match end end
ssl_options()
click to toggle source
# File lib/octogate/client.rb, line 69 def ssl_options if Octogate.config.ssl_verify Octogate.config.ca_file ? {ssl: {ca_file: Octogate.config.ca_file}} : {} else {ssl: {verify: false}} end end