ratchetio 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -28,6 +28,36 @@ To confirm that it worked, run:
28
28
 
29
29
  This will raise an exception within a test request; if it works, you'll see a stacktrace in the console, and the exception will appear in the Ratchet.io dashboard.
30
30
 
31
+ ## Manually reporting exceptions and messages
32
+
33
+ To report a caught exception to Ratchet, simply call `Ratchetio.report_exception`:
34
+
35
+ begin
36
+ foo = bar
37
+ rescue Exception => e
38
+ Ratchetio.report_exception(e)
39
+ end
40
+
41
+ If you're reporting an exception in the context of a request and are in a controller, you can pass along the same request and person context as the global exception handler, like so:
42
+
43
+ begin
44
+ foo = bar
45
+ rescue Exception => e
46
+ Ratchetio.report_exception(e, ratchetio_request_data, ratchetio_person_data)
47
+ end
48
+
49
+ You can also log individual messages:
50
+
51
+ # logs at the 'warning' level. all levels: debug, info, warning, error, critical
52
+ Ratchetio.report_message("Unexpected input", "warning")
53
+
54
+ # default level is "info"
55
+ Ratchetio.report_message("Login successful")
56
+
57
+ # can also include additional data as a hash in the final param
58
+ Ratchetio.report_message("Login successful", "info", :user => @user)
59
+
60
+
31
61
  ## Person tracking
32
62
 
33
63
  Ratchet will send information about the current user (called a "person" in Ratchet parlance) along with each error report, when available. This works by trying the `current_user` and `current_member` controller methods. The return value should be an object with an `id` property and, optionally, `username` and `email` properties.
@@ -12,7 +12,7 @@ module Ratchetio
12
12
  controller = env['action_controller.instance']
13
13
  request_data = controller.try(:ratchetio_request_data)
14
14
  person_data = controller.try(:ratchetio_person_data)
15
- Ratchetio.report_request_exception(env, exception, request_data, person_data)
15
+ Ratchetio.report_exception(exception, request_data, person_data)
16
16
  rescue Exception => exc
17
17
  # TODO use logger here?
18
18
  puts "[Ratchet.io] Exception while reporting exception to Ratchet.io: "
@@ -1,3 +1,3 @@
1
1
  module Ratchetio
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/ratchetio.rb CHANGED
@@ -19,7 +19,45 @@ module Ratchetio
19
19
  @configuration ||= Configuration.new
20
20
  end
21
21
 
22
- def report_request_exception(env, exception, request_data, person_data)
22
+ def report_exception(exception, request_data={}, person_data={})
23
+ begin
24
+ data = exception_data(exception)
25
+ if request_data
26
+ data[:request] = request_data
27
+ end
28
+ if person_data
29
+ data[:person] = person_data
30
+ end
31
+
32
+ payload = build_payload(data)
33
+ send_payload(payload)
34
+ rescue
35
+ logger.error "[Ratchet.io] Error reporting exception to Ratchet.io"
36
+ end
37
+ end
38
+
39
+ def report_message(message, level="info", extra_data={})
40
+ begin
41
+ data = base_data(level)
42
+
43
+ data[:body] = {
44
+ :message => {
45
+ :body => message.to_s
46
+ }
47
+ }
48
+ data[:body][:message].merge!(extra_data)
49
+ data[:server] = server_data
50
+
51
+ payload = build_payload(data)
52
+ send_payload(payload)
53
+ rescue
54
+ logger.error "[Ratchet.io] Error reporting message to Ratchet.io"
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def exception_data(exception)
23
61
  data = base_data
24
62
 
25
63
  # parse backtrace
@@ -43,19 +81,10 @@ module Ratchetio
43
81
  }
44
82
 
45
83
  data[:server] = server_data
46
- data[:request] = request_data
47
- data[:person] = person_data
48
-
49
- payload = build_payload(data)
50
- send_payload(payload)
51
- end
52
-
53
- def report_message()
54
- # TODO
84
+
85
+ data
55
86
  end
56
87
 
57
- private
58
-
59
88
  def logger
60
89
  configuration.logger
61
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratchetio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-17 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rails plugin to catch and send exceptions to Ratchet.io
15
15
  email: