Class: Appsignal::Transmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/transmitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, action, api_key, logger = nil) ⇒ Transmitter

Returns a new instance of Transmitter.



11
12
13
14
15
# File 'lib/appsignal/transmitter.rb', line 11

def initialize(endpoint, action, api_key, logger=nil)
  @endpoint = endpoint
  @action = action
  @api_key = api_key
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



9
10
11
# File 'lib/appsignal/transmitter.rb', line 9

def action
  @action
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



9
10
11
# File 'lib/appsignal/transmitter.rb', line 9

def api_key
  @api_key
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



9
10
11
# File 'lib/appsignal/transmitter.rb', line 9

def endpoint
  @endpoint
end

Instance Method Details

#transmit(payload) ⇒ Object



27
28
29
# File 'lib/appsignal/transmitter.rb', line 27

def transmit(payload)
  http_client.request(http_post(payload)).code
end

#uriObject



17
18
19
20
21
22
23
24
25
# File 'lib/appsignal/transmitter.rb', line 17

def uri
  @uri ||= URI("#{@endpoint}/#{@action}").tap do |uri|
    uri.query = Rack::Utils.build_query({
      :api_key => api_key,
      :hostname => Socket.gethostname,
      :gem_version => Appsignal::VERSION
    })
  end
end