Class: InformantCommon::Event::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/informant-common/event/base.rb

Direct Known Subclasses

AgentInfo, FormSubmission

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authorization_header_valueObject



12
13
14
# File 'lib/informant-common/event/base.rb', line 12

def self.authorization_header_value
  @authorization_header_value ||= "Token token=\"#{InformantCommon::Config.api_token}\""
end

.endpointObject



4
5
6
# File 'lib/informant-common/event/base.rb', line 4

def self.endpoint
  raise 'Must implement'
end

.net_http_start_argumentsObject



26
27
28
# File 'lib/informant-common/event/base.rb', line 26

def self.net_http_start_arguments
  @net_http_start_arguments ||= [endpoint.host, endpoint.port, use_ssl: endpoint.scheme == 'https']
end

Instance Method Details

#authorization_header_valueObject



16
17
18
# File 'lib/informant-common/event/base.rb', line 16

def authorization_header_value
  self.class.authorization_header_value
end

#endpointObject



8
9
10
# File 'lib/informant-common/event/base.rb', line 8

def endpoint
  self.class.endpoint
end

#net_http_start_argumentsObject



30
31
32
# File 'lib/informant-common/event/base.rb', line 30

def net_http_start_arguments
  self.class.net_http_start_arguments
end

#post_requestObject



20
21
22
23
24
# File 'lib/informant-common/event/base.rb', line 20

def post_request
  Net::HTTP::Post.new(endpoint,
                      'Authorization' => authorization_header_value,
                      'Content-Type' => 'application/json').tap { |r| r.body = to_json }
end