releaseable 0.0.18 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.18
1
+ 0.0.20
@@ -3,23 +3,7 @@ require 'logglier'
3
3
  require 'stringio'
4
4
  require 'timeout'
5
5
  require 'java'
6
-
7
- # Selectively silence verbose JRuby warnings
8
- def suppress_warnings
9
- old_verbose = $VERBOSE
10
- begin
11
- $VERBOSE = nil
12
- yield if block_given?
13
- ensure
14
- # always re-set to old value, even if block raises an exception
15
- $VERBOSE = old_verbose
16
- end
17
- end
18
-
19
- # Avoid OpenSSL failures
20
- suppress_warnings do
21
- OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
22
- end
6
+ require 'releaseable/http' # for OpenSSL settings
23
7
 
24
8
  # Logger extensions
25
9
  class Logger
@@ -49,6 +33,7 @@ class Logger
49
33
  # Something that should be interrupted if it takes too much time...
50
34
  Timeout::timeout(out) { yield }
51
35
  rescue Timeout::Error, Exception => e
36
+ @config[:failsafe].puts e
52
37
  nil
53
38
  end
54
39
 
@@ -68,10 +53,11 @@ class Logger
68
53
  def finalize
69
54
  if handler
70
55
  with_timeout do
71
- trace :failsafe => @config[:failsafe].string if @config[:failsafe].respond_to? :string
72
- sound_alarm
56
+ if @config[:failsafe].respond_to?(:string) && @config[:failsafe].string != ''
57
+ trace :failsafe => @config[:failsafe].string
58
+ end
73
59
  sleep 2
74
- handler.logdev.dev.deliverer.kill
60
+ @handler.logdev.dev.deliverer.kill
75
61
  end
76
62
  end
77
63
  close
@@ -101,10 +87,10 @@ class Logger
101
87
 
102
88
  # Extended handler for fatal errors
103
89
  def handler
104
- return @handler if @handler
90
+ return @handler if @handler && @handler.logdev.dev.deliverer.alive?
105
91
 
106
92
  @handle_init_timeout ||= Time.now
107
- if @handle_fatal_errors && @handle_init_timeout < Time.now
93
+ if @handle_fatal_errors && @handle_init_timeout <= Time.now
108
94
  @handle_init_timeout = Time.now + 5 * 60 # Retry init in 5 minutes
109
95
 
110
96
  with_timeout do
@@ -1,34 +1,8 @@
1
- #require 'httpclient'
2
- require 'net/http'
3
- require 'net/https'
4
- require 'xmlsimple'
5
- require 'json'
1
+ require 'releaseable/http'
6
2
 
7
3
  module Releaseable
8
4
  module GitHub
9
5
 
10
- OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
11
-
12
- def self.post address, data
13
- uri = URI(address)
14
-
15
- server = Net::HTTP.new(uri.host, uri.port)
16
- server.use_ssl = (uri.scheme == 'https')
17
- server.verify_mode = OpenSSL::SSL::VERIFY_NONE if server.use_ssl?
18
-
19
- server.start do |http|
20
- req = Net::HTTP::Post.new(uri.path)
21
- case data
22
- when Hash
23
- req.form_data = data
24
- when Array
25
- req.body = data
26
- req.content_type = 'multipart/form-data'
27
- end
28
- http.request(req)
29
- end
30
- end
31
-
32
6
  def self.upload info = {}
33
7
  info[:login] ||= `git config github.user`.chomp
34
8
  info[:token] ||= `git config github.token`.chomp
@@ -49,14 +23,14 @@ module Releaseable
49
23
 
50
24
  info[:content_type] ||= 'application/octet-stream'
51
25
 
52
- response = post "https://github.com/#{info[:repos]}/downloads",
53
- 'file_size' => File.stat(info[:file]).size,
54
- 'content_type' => info[:content_type],
55
- 'file_name' => info[:name],
56
- 'description' => info[:description] || '',
57
- 'login' => info[:login],
58
- 'token' => info[:token]
59
- #p response.body
26
+ response = HTTP.post "https://github.com/#{info[:repos]}/downloads",
27
+ 'file_size' => File.stat(info[:file]).size,
28
+ 'content_type' => info[:content_type],
29
+ 'file_name' => info[:name],
30
+ 'description' => info[:description] || '',
31
+ 'login' => info[:login],
32
+ 'token' => info[:token]
33
+ p response.body
60
34
  raise "Failed to post file info" unless response.code.to_i == 200 #status == 200
61
35
 
62
36
  upload = JSON.parse(response.body)
@@ -0,0 +1,64 @@
1
+ #require 'httpclient'
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'xmlsimple'
5
+ require 'json'
6
+
7
+ # Selectively silence verbose JRuby warnings
8
+ def suppress_warnings
9
+ old_verbose = $VERBOSE
10
+ begin
11
+ $VERBOSE = nil
12
+ yield if block_given?
13
+ ensure
14
+ # always re-set to old value, even if block raises an exception
15
+ $VERBOSE = old_verbose
16
+ end
17
+ end
18
+
19
+ # Avoid OpenSSL failures
20
+ suppress_warnings { OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE }
21
+
22
+ module Releaseable
23
+ module HTTP
24
+
25
+ def self.post address, data
26
+ uri = URI(address)
27
+ p uri.request_uri
28
+
29
+ server = Net::HTTP.new(uri.host, uri.port)
30
+ server.use_ssl = (uri.scheme == 'https')
31
+ server.verify_mode = OpenSSL::SSL::VERIFY_NONE if server.use_ssl?
32
+
33
+ server.start do |http|
34
+ req = Net::HTTP::Post.new(uri.path)
35
+ case data
36
+ when Hash
37
+ req.form_data = data
38
+ when Array
39
+ req.body = data
40
+ req.content_type = 'multipart/form-data'
41
+ end
42
+ http.request(req)
43
+ end
44
+ end
45
+
46
+ def self.get address, user, pass, query
47
+ uri = URI("#{address}?" + query.map { |k, v| "#{k}=#{URI.encode(v.to_s)}" }.join('&'))
48
+ p uri.request_uri
49
+
50
+ server = Net::HTTP.new(uri.host, uri.port)
51
+ #server.use_ssl = (uri.scheme == 'https')
52
+ #server.verify_mode = OpenSSL::SSL::VERIFY_NONE if server.use_ssl?
53
+
54
+ server.start do |http|
55
+ req = Net::HTTP::Get.new(uri.request_uri)
56
+ req.basic_auth user, pass
57
+
58
+ http.request(req)
59
+ end
60
+ end
61
+
62
+ end # module Loggly
63
+ end # module Releaseable
64
+
@@ -0,0 +1,24 @@
1
+ require 'releaseable/http'
2
+
3
+ module Releaseable
4
+ module Loggly
5
+
6
+ def self.search domain, user, pass, query
7
+
8
+ query = {:q => query} if query.is_a?(String)
9
+
10
+ response = HTTP.get "http://#{domain}.loggly.com/api/search", user, pass,
11
+ query.is_a?(Hash) ? query : {:q => query}
12
+
13
+ parsed = JSON.parse(response.body)
14
+
15
+ if parsed['data']
16
+ parsed['data'].map { |entry| JSON.parse(entry.delete('text')).merge(entry) }
17
+ else
18
+ parsed
19
+ end
20
+ end
21
+
22
+ end # module Loggly
23
+ end # module Releaseable
24
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: releaseable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.18
5
+ version: 0.0.20
6
6
  platform: ruby
7
7
  authors:
8
8
  - arvicco
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-21 00:00:00 Z
13
+ date: 2012-02-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -90,6 +90,8 @@ files:
90
90
  - lib/releaseable.rb
91
91
  - lib/releaseable/extensions.rb
92
92
  - lib/releaseable/github.rb
93
+ - lib/releaseable/http.rb
94
+ - lib/releaseable/loggly.rb
93
95
  - lib/releaseable/sound.rb
94
96
  - lib/releaseable/version.rb
95
97
  - VERSION