Class: Appsignal::Transmitter
- Inherits:
-
Object
- Object
- Appsignal::Transmitter
- Defined in:
- lib/appsignal/transmitter.rb
Constant Summary collapse
- CONTENT_TYPE =
'application/json; charset=UTF-8'.freeze
- CONTENT_ENCODING =
'gzip'.freeze
- CA_FILE_PATH =
File.(File.join(__FILE__, '../../../resources/cacert.pem'))
- HTTP_ERRORS =
[ EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EINVAL, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Timeout::Error, OpenSSL::SSL::SSLError ]
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(action, config = Appsignal.config) ⇒ Transmitter
constructor
A new instance of Transmitter.
- #transmit(payload) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(action, config = Appsignal.config) ⇒ Transmitter
Returns a new instance of Transmitter.
27 28 29 30 |
# File 'lib/appsignal/transmitter.rb', line 27 def initialize(action, config=Appsignal.config) @action = action @config = config end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
25 26 27 |
# File 'lib/appsignal/transmitter.rb', line 25 def action @action end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
25 26 27 |
# File 'lib/appsignal/transmitter.rb', line 25 def config @config end |
Instance Method Details
#transmit(payload) ⇒ Object
44 45 46 47 |
# File 'lib/appsignal/transmitter.rb', line 44 def transmit(payload) Appsignal.logger.debug "Transmitting payload to #{uri}" http_client.request(http_post(payload)).code end |
#uri ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/appsignal/transmitter.rb', line 32 def uri @uri ||= URI("#{config[:endpoint]}/#{action}").tap do |uri| uri.query = ::Rack::Utils.build_query({ :api_key => config[:push_api_key], :name => config[:name], :environment => config.env, :hostname => Socket.gethostname, :gem_version => Appsignal::VERSION }) end end |