hockeybrake 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ .DS_Store
4
+ .DS_Store?
5
+ ._*
6
+ .Spotlight-V100
7
+ .Trashes
8
+ Icon?
9
+ ehthumbs.db
10
+ Thumbs.db
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hockeybrake.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hockeybrake (0.0.1)
5
+ airbrake (>= 3.1.2)
6
+ multipart-post (>= 1.1.5)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.8)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ airbrake (3.1.2)
15
+ activesupport
16
+ builder
17
+ builder (3.0.0)
18
+ i18n (0.6.1)
19
+ multi_json (1.3.6)
20
+ multipart-post (1.1.5)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ hockeybrake!
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # HockeyBrake
2
+
3
+ An extension for the amazing airbrake gem which routes crash reports to HockeyApp
4
+
5
+ ## Installation
6
+
7
+ Add this to your Gemfile
8
+ ```ruby
9
+ gem 'airbrake'
10
+ gem 'hockeybrake', :git => 'git://github.com/dei79/hockeybrake.git'
11
+ ```
12
+
13
+ Execute the following command for your Rails app
14
+ ```shell
15
+ rails g hockeybrake
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ Update hockeybrake.rb in config/initializers
21
+
22
+ ## Contributing
23
+
24
+ * Fork the project
25
+ * Fix the issue
26
+ * Create pull request on github
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hockeybrake/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hockeybrake"
7
+ s.version = HockeyBrake::VERSION
8
+ s.authors = ["Dirk Eisenberg"]
9
+ s.email = ["dirk.eisenberg@gmail.com"]
10
+ s.homepage = 'http://rubygems.org/gems/hockeybrake'
11
+ s.summary = %q{An extension for the amazing airbrake gem which routes crash reports to HockeyApp}
12
+ s.description = %q{An extension for the amazing airbrake gem which routes crash reports to HockeyApp}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency(%q<airbrake>, [">= 3.1.2"])
20
+ s.add_runtime_dependency(%q<multipart-post>, [">= 1.1.5"])
21
+ end
@@ -0,0 +1,7 @@
1
+ class HockeybrakeGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_initializer_file
5
+ copy_file "initializer.rb", "config/initializers/hockeybrake.rb"
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ Airbrake.configure do |config|
2
+ # comment out if sending exceptions in the development environment
3
+ # is needed as well
4
+ # config.development_environments.delete("development")
5
+ end
6
+
7
+ HockeyBrake.configure do |config|
8
+
9
+ # the bundle id
10
+ config.app_bundle_id= "###YOUR BUNDLE IDENTIFIER FROM HOCKEYAPP###"
11
+
12
+ # The application ID in hockey app
13
+ config.app_id="###YOUR APP SECRET###"
14
+
15
+ # The application version, you can use the different environments
16
+ # as version, otherwise use the name of your version
17
+ config.app_version="#{Rails.env}"
18
+
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'hockeybrake/configuration'
2
+ require 'hockeybrake/hockey_log'
3
+ require 'hockeybrake/hockey_sender'
4
+ require 'hockeybrake/hockey_sender_injector'
5
+
6
+ module HockeyBrake
7
+
8
+ class << self
9
+
10
+ def configure
11
+ # receive the configuration
12
+ yield(configuration)
13
+ end
14
+
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module HockeyBrake
2
+ class Configuration
3
+
4
+ # The application bundle id
5
+ attr_accessor :app_bundle_id
6
+
7
+ # The app id of the application
8
+ attr_accessor :app_id
9
+
10
+ # The app version
11
+ attr_accessor :app_version
12
+
13
+ # The service url
14
+ def hockey_url
15
+ "https://rink.hockeyapp.net/api/2/apps/#{app_id}/crashes/upload"
16
+ end
17
+
18
+ # convert to hash
19
+ def to_hash
20
+ h = Hash.new
21
+ h[:app_id] = self.app_id
22
+ h[:app_version] = self.app_version
23
+ h[:hockey_url] = self.hockey_url
24
+ h
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # This class converts the given Airbrake XML data to the log format of the HockeyApp server
3
+ #
4
+ module HockeyBrake
5
+ class HockeyLog
6
+
7
+ #
8
+ # Generates a string which can be sent to the hockey service
9
+ #
10
+ def self.generate(data)
11
+ # the output
12
+ output = ""
13
+
14
+ # generate our time string
15
+ dtstr = Time.now.strftime("%a %b %d %H:%M:%S %Z %Y")
16
+
17
+ # write the header so that we have something to send
18
+ output += "Package: #{HockeyBrake.configuration.app_bundle_id}\n"
19
+ output += "Version: #{HockeyBrake.configuration.app_version}\n"
20
+ output += "Date: #{dtstr}\n"
21
+
22
+ # add the optional values if possible
23
+ begin
24
+ output += "Android: #{RUBY_PLATFORM}\n"
25
+ output += "Model: Ruby #{RUBY_VERSION} Rails #{Rails.version}\n"
26
+ rescue
27
+ # nothing to do
28
+ end
29
+
30
+ # add the empty line
31
+ output += "\n"
32
+
33
+ # parse the XML and convert them to the HockeyApp format
34
+ begin
35
+ # xml parser
36
+ crashData = Hash.from_xml(data)
37
+
38
+ # write the first line
39
+ output += "#{crashData['notice']['error']['class']}: #{crashData['notice']['error']['message']}\n"
40
+
41
+ # parse the lines
42
+ lines = crashData['notice']['error']['backtrace']['line']
43
+ lines.each do |line|
44
+ class_name = File.basename(line['file'], ".rb").classify
45
+ output += " at #{class_name}##{line['method']}(#{line['file']}:#{line['number']})\n"
46
+ end
47
+ rescue
48
+ # nothing to do
49
+ end
50
+
51
+ # return the output
52
+ output
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,63 @@
1
+ # using multipart post
2
+ require 'net/http/post/multipart'
3
+
4
+ module HockeyBrake
5
+ # Sends out the notice to HockeyApp
6
+ class HockeySender < Airbrake::Sender
7
+
8
+ # initialize the sender
9
+ def initialize
10
+ super(Airbrake.configuration.to_hash)
11
+ end
12
+
13
+ # Sends the notice data off to HockeyApp for processing.
14
+ #
15
+ # @param [String] data The XML notice to be sent off
16
+ def send_to_airbrake(data)
17
+
18
+ # generate the log
19
+ logstr = HockeyLog.generate(data)
20
+
21
+ # store the data into temp file
22
+ file = Tempfile.new('hockey-exception')
23
+ file.write(logstr)
24
+ file.close
25
+
26
+ # buidl the url
27
+ url = URI.parse(HockeyBrake.configuration.hockey_url)
28
+
29
+ # send the request
30
+ response = begin
31
+ File.open(file.path) do |log|
32
+
33
+ req = Net::HTTP::Post::Multipart.new url.path,
34
+ "log" => UploadIO.new(log, 'application/octet-stream', "log.txt")
35
+ Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
36
+ http.request(req)
37
+ end
38
+ end
39
+ rescue *HTTP_ERRORS => e
40
+ log :error, "Unable to contact the HockeyApp server. HTTP Error=#{e}"
41
+ nil
42
+ end
43
+
44
+ # remove the file
45
+ file.unlink
46
+
47
+ case response
48
+ when Net::HTTPSuccess then
49
+ log :info, "Success: #{response.class}", response
50
+ else
51
+ log :error, "Failure: #{response.class}", response
52
+ end
53
+
54
+ if response && response.respond_to?(:body)
55
+ error_id = response.body.match(%r{<id[^>]*>(.*?)</id>})
56
+ error_id[1] if error_id
57
+ end
58
+ rescue => e
59
+ log :error, "[HockeyBrake::HockeySender#send_to_airbrake] Cannot send notification. Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
60
+ nil
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,14 @@
1
+ module HockeyBrake
2
+ module HockeySenderInjector
3
+ def override_send_to_airbrake(data)
4
+ HockeyBrake::HockeySender.new().send_to_airbrake(data)
5
+ end
6
+ end
7
+ end
8
+
9
+ module Airbrake
10
+ class Sender
11
+ include HockeyBrake::HockeySenderInjector
12
+ alias_method :send_to_airbrake, :override_send_to_airbrake
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module HockeyBrake
2
+ VERSION = "0.0.2"
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hockeybrake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dirk Eisenberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: airbrake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: multipart-post
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.5
46
+ description: An extension for the amazing airbrake gem which routes crash reports
47
+ to HockeyApp
48
+ email:
49
+ - dirk.eisenberg@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - README.md
58
+ - hockeybrake.gemspec
59
+ - lib/generators/hockeybrake/hockeybrake_generator.rb
60
+ - lib/generators/hockeybrake/templates/initializer.rb
61
+ - lib/hockeybrake.rb
62
+ - lib/hockeybrake/configuration.rb
63
+ - lib/hockeybrake/hockey_log.rb
64
+ - lib/hockeybrake/hockey_sender.rb
65
+ - lib/hockeybrake/hockey_sender_injector.rb
66
+ - lib/hockeybrake/version.rb
67
+ homepage: http://rubygems.org/gems/hockeybrake
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.23
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: An extension for the amazing airbrake gem which routes crash reports to HockeyApp
91
+ test_files: []