exception_notification-parser 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exception_notification-parser.gemspec +27 -0
- data/lib/exception_notification/parser.rb +16 -0
- data/lib/exception_notification/parser/struct.rb +117 -0
- data/lib/exception_notification/parser/subject.rb +32 -0
- data/lib/exception_notification/parser/version.rb +5 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d919354e7f5b991b57d0fb8db32d704c87d9233
|
4
|
+
data.tar.gz: 5ac631962ced872ef01fa5c52640b6ea37626b8d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 07547f71da4d0a5320ac2d918f52c1f8a0b0bb47f34140a09f7e0bad02e24ae0713783ae0b8f0943114c0be29bf8de07580b1680a24fd37468b532ad81aed02e
|
7
|
+
data.tar.gz: f256ec909d04054e92730d4ab8c3438889f4654929ee150205581f09ca23be756ad436e4621f0e07ecfc6ed341f28635662c308b92f6984cdaaad1c6cb41ea7b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# ExceptionNotification::Parser
|
2
|
+
|
3
|
+
https://rubygems.org/gems/exception_notification outputed mail parser.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'exception_notification-parser'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
mail_raw = File.read('./mail') # body with header
|
21
|
+
|
22
|
+
# case 1
|
23
|
+
struct = ExceptionNotification::Parser.parse(mail_raw: mail_raw)
|
24
|
+
|
25
|
+
# case 2
|
26
|
+
mail = Mail.new(mail_raw)
|
27
|
+
body = mail.body.decoded.toutf8
|
28
|
+
struct = ExceptionNotification::Parser.parse(body: body, subject: mail.suject)
|
29
|
+
```
|
30
|
+
|
31
|
+
### accessible list
|
32
|
+
```
|
33
|
+
subject.exception_class_name
|
34
|
+
subject.action_name
|
35
|
+
subject.controller
|
36
|
+
|
37
|
+
request_url
|
38
|
+
request_http_method
|
39
|
+
request_ip_address
|
40
|
+
request_timestamp
|
41
|
+
requist_rails_root
|
42
|
+
requist_parameters # hash
|
43
|
+
session_id
|
44
|
+
session_data # hash
|
45
|
+
environment_content_length
|
46
|
+
environment_content_type
|
47
|
+
environment_http_host
|
48
|
+
environment_http_user_agent
|
49
|
+
environment_remote_addr
|
50
|
+
environment_request_path
|
51
|
+
environment_request_uri
|
52
|
+
environment_request_method
|
53
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "exception_notification/parser"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'exception_notification/parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "exception_notification-parser"
|
8
|
+
spec.version = ExceptionNotification::Parser::VERSION
|
9
|
+
spec.authors = ["jiikko"]
|
10
|
+
spec.email = ["n905i.1214@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{exception_notification parser..}
|
13
|
+
spec.description = %q{exception_notification parser.}
|
14
|
+
spec.homepage = "https://github.com/jiikko/exception_notification-parser"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "mail"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'mail'
|
3
|
+
require 'kconv'
|
4
|
+
require "exception_notification/parser/version"
|
5
|
+
require "exception_notification/parser/struct"
|
6
|
+
require "exception_notification/parser/subject"
|
7
|
+
|
8
|
+
module ExceptionNotification
|
9
|
+
module Parser
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
def self.parse(body: nil, mail_raw: nil, subject: nil)
|
13
|
+
Struct.new(body: body, mail_raw: mail_raw, subject: subject)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module ExceptionNotification::Parser
|
2
|
+
class Struct
|
3
|
+
attr_reader :body
|
4
|
+
|
5
|
+
def initialize(body: nil, mail_raw: nil, subject: nil)
|
6
|
+
mail = nil
|
7
|
+
@body =
|
8
|
+
if mail_raw
|
9
|
+
mail = Mail.new(mail_raw)
|
10
|
+
mail.body.decoded.toutf8
|
11
|
+
else
|
12
|
+
body
|
13
|
+
end
|
14
|
+
@subject = subject || mail && mail.subject
|
15
|
+
end
|
16
|
+
|
17
|
+
def subject
|
18
|
+
Subject.new(@subject)
|
19
|
+
end
|
20
|
+
|
21
|
+
def has_subject?
|
22
|
+
!!@subject
|
23
|
+
end
|
24
|
+
|
25
|
+
def request_url
|
26
|
+
find(/URL[ ]*: (.*)$/)
|
27
|
+
end
|
28
|
+
|
29
|
+
def request_http_method
|
30
|
+
find_label('HTTP Method')
|
31
|
+
end
|
32
|
+
|
33
|
+
def request_ip_address
|
34
|
+
find_label('IP address')
|
35
|
+
end
|
36
|
+
|
37
|
+
def request_timestamp
|
38
|
+
Time.parse(find_label('Timestamp')) if find_label('Timestamp')
|
39
|
+
end
|
40
|
+
|
41
|
+
def requist_rails_root
|
42
|
+
find_label('Rails root')
|
43
|
+
end
|
44
|
+
|
45
|
+
def requist_parameters
|
46
|
+
find_label_for_hash(:Parameters)
|
47
|
+
end
|
48
|
+
|
49
|
+
def session_id
|
50
|
+
find_label('session id').gsub('"', '')
|
51
|
+
end
|
52
|
+
|
53
|
+
def session_data
|
54
|
+
find_label_for_hash(:data)
|
55
|
+
end
|
56
|
+
|
57
|
+
def environment_content_length
|
58
|
+
find_label(:CONTENT_LENGTH).to_i
|
59
|
+
end
|
60
|
+
|
61
|
+
def environment_content_type
|
62
|
+
find_label(:CONTENT_TYPE)
|
63
|
+
end
|
64
|
+
|
65
|
+
def environment_http_host
|
66
|
+
find_label(:HTTP_HOST)
|
67
|
+
end
|
68
|
+
|
69
|
+
def environment_http_user_agent
|
70
|
+
find_label(:HTTP_USER_AGENT)
|
71
|
+
end
|
72
|
+
|
73
|
+
def environment_remote_addr
|
74
|
+
find_label(:REMOTE_ADDR)
|
75
|
+
end
|
76
|
+
|
77
|
+
def environment_request_path
|
78
|
+
find_label(:REQUEST_PATH)
|
79
|
+
end
|
80
|
+
|
81
|
+
def environment_request_uri
|
82
|
+
find_label(:REQUEST_URI)
|
83
|
+
end
|
84
|
+
|
85
|
+
def environment_request_method
|
86
|
+
find_label(:REQUEST_METHOD)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def find(regexp)
|
92
|
+
@body =~ regexp
|
93
|
+
$1 || raise(ExceptionNotification::Parser::Error, 'parse failed')
|
94
|
+
end
|
95
|
+
|
96
|
+
def find_label(name)
|
97
|
+
name_to_s = name.to_s
|
98
|
+
if has_key?(name_to_s)
|
99
|
+
find(/#{name_to_s} *: (.+?)$/)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def find_label_for_hash(name)
|
104
|
+
data = {}
|
105
|
+
lines = find(/ *\* #{name} *: {(.*?)}$/m)
|
106
|
+
lines.split(',').each do |line|
|
107
|
+
splited = line.gsub('"', '').strip.split('=>')
|
108
|
+
data[splited[0]] = splited[1]
|
109
|
+
end
|
110
|
+
data
|
111
|
+
end
|
112
|
+
|
113
|
+
def has_key?(name)
|
114
|
+
@body.include?(name)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ExceptionNotification::Parser::Subject
|
2
|
+
attr_reader \
|
3
|
+
:action_name,
|
4
|
+
:controller_name,
|
5
|
+
:email_prefix,
|
6
|
+
:exception_class_name
|
7
|
+
|
8
|
+
def initialize(subject)
|
9
|
+
@subject = subject
|
10
|
+
if %r!^([^ ]+) \(([^)]+)\)!m =~ subject
|
11
|
+
@email_predix = $1
|
12
|
+
@controller_name = nil
|
13
|
+
@action_name = nil
|
14
|
+
@exception_class_name = $2
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
if %r!([^ ]+) ([^#]+?)#(\w+) \(([^\)]+?)\)!m =~ subject
|
19
|
+
@email_prefix = $1
|
20
|
+
@controller_name = $2
|
21
|
+
@action_name = $3
|
22
|
+
@exception_class_name = $4
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
raise('no match pattaern subject!')
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
@subject
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exception_notification-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiikko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mail
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: exception_notification parser.
|
84
|
+
email:
|
85
|
+
- n905i.1214@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- exception_notification-parser.gemspec
|
99
|
+
- lib/exception_notification/parser.rb
|
100
|
+
- lib/exception_notification/parser/struct.rb
|
101
|
+
- lib/exception_notification/parser/subject.rb
|
102
|
+
- lib/exception_notification/parser/version.rb
|
103
|
+
homepage: https://github.com/jiikko/exception_notification-parser
|
104
|
+
licenses: []
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: exception_notification parser..
|
126
|
+
test_files: []
|
127
|
+
has_rdoc:
|