Class: RaygunClient::HTTP::Post

Inherits:
Object
  • Object
show all
Includes:
Configure, Dependency, Log::Dependency, Settings::Setting, Telemetry::Dependency
Defined in:
lib/raygun_client/http/post.rb

Direct Known Subclasses

Substitute::Post

Defined Under Namespace

Modules: LogText, Substitute, Telemetry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/raygun_client/http/post.rb', line 13

def data
  @data
end

Class Method Details

.build(connection: nil) ⇒ Object



17
18
19
20
21
# File 'lib/raygun_client/http/post.rb', line 17

def self.build(connection: nil)
  instance = new
  RaygunClient::Settings.set(instance)
  instance
end

.call(data) ⇒ Object



23
24
25
26
# File 'lib/raygun_client/http/post.rb', line 23

def self.call(data)
  instance = build
  instance.(data)
end

.hostObject



41
42
43
# File 'lib/raygun_client/http/post.rb', line 41

def self.host
  'api.raygun.io'
end

.pathObject



45
46
47
# File 'lib/raygun_client/http/post.rb', line 45

def self.path
  '/entries'
end

.register_telemetry_sink(post) ⇒ Object



61
62
63
64
65
# File 'lib/raygun_client/http/post.rb', line 61

def self.register_telemetry_sink(post)
  sink = Telemetry.sink
  post.telemetry.register(sink)
  sink
end

.uriObject



49
50
51
# File 'lib/raygun_client/http/post.rb', line 49

def self.uri
  @uri ||= URI::HTTPS.build(:host => host, :path => path)
end

Instance Method Details

#call(data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/raygun_client/http/post.rb', line 28

def call(data)
  logger.trace { "Posting to Raygun" }
  json_text = Transform::Write.(data, :json)

  response = http_post(json_text)

  telemetry.record(:posted, Telemetry::Data.new(data, response))

  logger.info { "Posted to Raygun (#{LogText::Posted.(data, response)})" }

  response
end

#http_post(request_body) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/raygun_client/http/post.rb', line 53

def http_post(request_body)
  uri = self.class.uri

  response = Net::HTTP.post(uri, request_body, { 'X-ApiKey' => api_key })

  response
end