zumobi 0.0.2

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/lib/zumobi.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "zumobi/exception_handler"
2
+ require "zumobi/notifications_logger"
3
+ require "zumobi/notifier"
4
+ require "zumobi/version"
5
+
6
+ module Zumobi
7
+
8
+
9
+
10
+ end
@@ -0,0 +1,38 @@
1
+ require 'right_aws'
2
+
3
+ module Zumobi
4
+
5
+ class ExceptionHandler
6
+
7
+ # Network-related errors we'll skip...
8
+ EXCLUDED_EXCEPTIONS = [
9
+ Curl::Err::ConnectionFailedError.name,
10
+ Curl::Err::GotNothingError.name,
11
+ Curl::Err::HostResolutionError.name,
12
+ Curl::Err::PartialFileError.name,
13
+ Curl::Err::RecvError.name,
14
+ Curl::Err::TimeoutError.name,
15
+ Errno::ECONNRESET.name,
16
+ Errno::EHOSTUNREACH.name,
17
+ Errno::ETIMEDOUT.name,
18
+ Net::HTTPFatalError.name,
19
+ Net::HTTPServerException.name,
20
+ RightAws::AwsError.name,
21
+ Timeout::Error.name ]
22
+
23
+ def self.method_missing(name, *args, &block)
24
+ if [:debug, :info, :warn, :error, :fatal].include?(name)
25
+ e = args[0]
26
+ unless EXCLUDED_EXCEPTIONS.include?(e.class.name)
27
+ # Note: Rails doesn't log the stacktrace... it's quite annoying
28
+ Rails.logger.send(name, e.message + "\n" + e.backtrace.join("\n"), &block)
29
+
30
+ # Send to Airbrake
31
+ Airbrake.notify(e) if Object.const_defined?(:Airbrake)
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,17 @@
1
+ module Zumobi
2
+
3
+ class NotificationsLogger < Logger
4
+
5
+ def initialize
6
+ super( "#{Rails.root}/log/notifications_#{Rails.env}.log" )
7
+ self.level = Rails.logger.level
8
+ end
9
+
10
+ def format_message(severity, timestamp, progname, msg)
11
+ time = I18n.localize(timestamp.in_time_zone("Pacific Time (US & Canada)"), :format => :short)
12
+ "#{time} PST: #{msg}\n"
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,29 @@
1
+ module Zumobi
2
+
3
+ class Notifier
4
+
5
+ attr_accessor :logger
6
+
7
+ def initialize
8
+ @logger = Zumobi::NotificationsLogger.new
9
+ end
10
+
11
+ def broadcast(notification)
12
+ config = SimpleConfig.for(:ua)
13
+ if (config.application_key.blank? || config.application_secret.blank? || config.master_secret.blank?)
14
+ raise "You must include a simple config :ua config with :application_key, :application_secret and :master_secret for this application."
15
+ end
16
+ Urbanairship.application_key = config.application_key
17
+ Urbanairship.application_secret = config.application_secret
18
+ Urbanairship.master_secret = config.master_secret
19
+ Urbanairship.logger = @logger
20
+ Urbanairship.request_timeout = 15
21
+ response = Urbanairship.broadcast_push(notification)
22
+ @logger.info notification.to_json
23
+ rescue Exception => e
24
+ ExceptionHandler.error e
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ module Zumobi
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zumobi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Alx Dark
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-03-06 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: curb
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rails
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: right_aws
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: airbrake
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 15
71
+ segments:
72
+ - 3
73
+ - 1
74
+ - 6
75
+ version: 3.1.6
76
+ type: :runtime
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: urbanairship
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 2
89
+ - 3
90
+ - 0
91
+ version: 2.3.0
92
+ type: :runtime
93
+ version_requirements: *id005
94
+ description: Cross-app notification and exception handling support
95
+ email:
96
+ - alx.dark@zumobi.com
97
+ executables: []
98
+
99
+ extensions: []
100
+
101
+ extra_rdoc_files: []
102
+
103
+ files:
104
+ - lib/zumobi/exception_handler.rb
105
+ - lib/zumobi/notifications_logger.rb
106
+ - lib/zumobi/notifier.rb
107
+ - lib/zumobi/version.rb
108
+ - lib/zumobi.rb
109
+ homepage: http://www.zumobi.com/
110
+ licenses: []
111
+
112
+ post_install_message:
113
+ rdoc_options: []
114
+
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.24
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Some core utilities for Zumobi's suite of applications.
142
+ test_files: []
143
+