Class: Octogate::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/octogate/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Client

Returns a new instance of Client.



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

def initialize(event)
  @event = event
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



7
8
9
# File 'lib/octogate/client.rb', line 7

def event
  @event
end

Instance Method Details

#request(target) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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_targetsObject



13
14
15
16
17
18
19
# 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