sms-logparser 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93e212f0f77154778e786a79367f9cd82c9cee3b
4
- data.tar.gz: 49e41a9246a1ed98d9b758879229c35e05155142
3
+ metadata.gz: 9e27a12723425509ba68cdaf5ff40b2e8cf0c8f7
4
+ data.tar.gz: 1f28ec67759effb560f95eb20dd9746f3c6c1438
5
5
  SHA512:
6
- metadata.gz: d556599ab90dfa6c382b2f49ce55c184b11f168133777ce86580361dccf38b7080a79c56a05e05c54db63162fd154270e4f6ada22c94025a291abccbbc3dbd96
7
- data.tar.gz: 053425917166b1b60cb82b2744e2df956a97c1a5950be1fa53c6ce5f1e52ad5fa04d360982165693b8673b36a5fe0670083de5643bb08a069b20dbceecd76d0f
6
+ metadata.gz: cf90a38a56e49ed5b20fb8befcefd91b0b898d165287cdecbbbca99d471b4247dface8454799606ca2861001dc8f7d99fabe10aa9b03649afd104ffd6c8c9c89
7
+ data.tar.gz: 0020bd4587d6588753694888c0dc84b4fa6d053b71c1b8dabd0ac959bb778f9d5b28456f94b9e0ec4f8f70553a8df3d3b806697871fd536429a54c720cf9c6a8
@@ -81,7 +81,7 @@ module SmsLogparser
81
81
  if data
82
82
  requests = api.send(data)
83
83
  state[:match_count] += 1
84
- verbose_parser_output(data, requests, entry) if options[:verbose]
84
+ verbose_parser_output(data, requests, entry['ID']) if options[:verbose]
85
85
  end
86
86
  end
87
87
  state[:last_event_id] = entry['ID']
@@ -155,9 +155,9 @@ module SmsLogparser
155
155
  end
156
156
 
157
157
  no_commands do
158
- def verbose_parser_output(data, requests, entry)
158
+ def verbose_parser_output(data, requests, entry_id)
159
159
  say "ID:\t", :cyan
160
- say entry['ID']
160
+ say entry_id
161
161
  say "URL:\t", :cyan
162
162
  say requests.map {|req| "#{req[:url]}#{req[:uri]} (Status: #{req[:status] || 'n/a'})"}.join("\n\t")
163
163
  say "Data:\t", :cyan
@@ -78,15 +78,12 @@ module SmsLogparser
78
78
 
79
79
  def get_entries(options={})
80
80
  last_id = options[:last_id] || get_last_parse_id
81
- if options[:limit]
82
- max_id = last_id + options[:limit] + 1
83
- else
84
- max_id = get_last_event_id
85
- end
81
+ max_id, query_limit = get_query_limits(last_id, options[:limit])
86
82
  while last_id < max_id
87
- entries = select_entries(last_id)
83
+ entries = select_entries(last_id, query_limit)
88
84
  yield entries
89
- last_id = entries.to_a[-1]['ID']
85
+ entries = entries.to_a
86
+ last_id = entries.size > 0 ? entries[-1]['ID'] : max_id
90
87
  end
91
88
  end
92
89
 
@@ -99,11 +96,25 @@ module SmsLogparser
99
96
 
100
97
  private
101
98
 
102
- def select_entries(last_id)
103
- client.query("SELECT * FROM SystemEvents\
99
+ def get_query_limits(last_id, user_limit = nil)
100
+ if user_limit
101
+ max_id = last_id + user_limit
102
+ if @query_limit > user_limit
103
+ query_limit = user_limit
104
+ end
105
+ else
106
+ max_id = get_last_event_id
107
+ end
108
+ [max_id, query_limit || @query_limit]
109
+ end
110
+
111
+ def select_entries(offset, max_entries = @query_limit)
112
+ client.query(
113
+ "SELECT * FROM SystemEvents\
104
114
  WHERE `FromHost` like '#{@host_filter}'\
105
115
  ORDER BY ID ASC\
106
- LIMIT #{last_id},#{@query_limit};")
116
+ LIMIT #{offset},#{max_entries};"
117
+ )
107
118
  end
108
119
 
109
120
  def get_last_event_id
@@ -1,3 +1,3 @@
1
1
  module SmsLogparser
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
data/spec/api_spec.rb CHANGED
@@ -20,10 +20,10 @@ describe SmsLogparser::Api do
20
20
  :traffic_type => 'TRAFFIC_WEBCAST',
21
21
  :visitor_type => 'VISITORS_WEBCAST'
22
22
  }
23
- urls = @api.send(data)
24
- urls.size.must_equal 2
25
- urls[0].must_match /\/1\/2\/3\/TRAFFIC_WEBCAST\/128$/
26
- urls[1].must_match /\/1\/2\/3\/VISITORS_WEBCAST\/1$/
23
+ requests = @api.send(data)
24
+ requests.size.must_equal 2
25
+ requests[0][:uri].must_match /\/1\/2\/3\/TRAFFIC_WEBCAST\/128$/
26
+ requests[1][:uri].must_match /\/1\/2\/3\/VISITORS_WEBCAST\/1$/
27
27
  end
28
28
 
29
29
  it "does not send traffic for m3u8 files" do
@@ -37,9 +37,9 @@ describe SmsLogparser::Api do
37
37
  :traffic_type => 'TRAFFIC_MOBILE',
38
38
  :visitor_type => 'VISITORS_MOBILE'
39
39
  }
40
- urls = @api.send(data)
41
- urls.size.must_equal 1
42
- urls[0].must_match /\/100\/200\/300\/VISITORS_MOBILE\/1$/
40
+ requests = @api.send(data)
41
+ requests.size.must_equal 1
42
+ requests[0][:uri].must_match /\/100\/200\/300\/VISITORS_MOBILE\/1$/
43
43
  end
44
44
 
45
45
  it "does not send visitor info if no visitor_type" do
@@ -52,9 +52,9 @@ describe SmsLogparser::Api do
52
52
  :user_agent => 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0',
53
53
  :traffic_type => 'TRAFFIC_MOBILE',
54
54
  }
55
- urls = @api.send(data)
56
- urls.size.must_equal 1
57
- urls[0].must_match /\/101\/202\/303\/TRAFFIC_MOBILE\/48$/
55
+ requests = @api.send(data)
56
+ requests.size.must_equal 1
57
+ requests[0][:uri].must_match /\/101\/202\/303\/TRAFFIC_MOBILE\/48$/
58
58
  end
59
59
 
60
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms-logparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - niwo