dynamicdudes-speaking-apps 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -3
- data/VERSION.yml +2 -2
- data/lib/speaking_apps.rb +28 -8
- data/lib/speaking_apps/daemon/control.rb +2 -1
- data/lib/speaking_apps/daemon/remote.rb +2 -1
- data/lib/speaking_apps/message_queue.rb +10 -9
- data/rails/init.rb +1 -1
- data/spec/lib/speaking_apps/message_queue_spec.rb +6 -5
- data/spec/lib/speaking_apps_spec.rb +2 -2
- metadata +11 -3
- data/lib/speaking_apps/config.rb +0 -58
- data/spec/lib/speaking_apps/config_spec.rb +0 -22
data/README.rdoc
CHANGED
@@ -18,10 +18,15 @@ or with Rails >= 2.1:
|
|
18
18
|
== Configuration
|
19
19
|
|
20
20
|
Just before you start sending messages to the http://speakingapps.com API you should configure a few essential things:
|
21
|
-
SpeakingApps
|
21
|
+
SpeakingApps.configure do |config|
|
22
|
+
config.token = 'your_super_secret_token'
|
23
|
+
end
|
22
24
|
|
23
25
|
If you are on Rails you might want to define which environments should be used for remote logging:
|
24
|
-
SpeakingApps
|
26
|
+
SpeakingApps.configure do |config|
|
27
|
+
config.token = 'your_super_secret_token'
|
28
|
+
config.environments = [ 'staging', 'production' ]
|
29
|
+
end
|
25
30
|
|
26
31
|
== Usage
|
27
32
|
|
@@ -44,4 +49,4 @@ and a &block taking version for more readability if you have longer messages:
|
|
44
49
|
* Supported by http://dynamicdudes.com
|
45
50
|
|
46
51
|
|
47
|
-
Copyright (c)
|
52
|
+
Copyright (c) 2009 rubyphunk, speakingapps.com. See LICENSE for details.
|
data/VERSION.yml
CHANGED
data/lib/speaking_apps.rb
CHANGED
@@ -1,22 +1,42 @@
|
|
1
1
|
require 'timeout'
|
2
|
-
require File.dirname(__FILE__) + '/speaking_apps/config'
|
3
2
|
require File.dirname(__FILE__) + '/speaking_apps/message_queue'
|
4
3
|
|
5
4
|
# This is the place to read about the methods that
|
6
5
|
# will help you sending Messages/Logs to the SpeakingApps API Service.
|
7
6
|
#
|
8
|
-
# Please make sure you set the required SpeakingApps
|
7
|
+
# Please make sure you set the required SpeakingApps.configure values.
|
9
8
|
|
10
9
|
module SpeakingApps
|
11
10
|
class << self
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
attr_accessor :token, :environments, :host, :port
|
13
|
+
attr_accessor :environment
|
14
|
+
|
15
|
+
def init(environment = nil) # :nodoc:
|
16
|
+
@environment = environment
|
17
|
+
@host = 'speakingapps.com'
|
18
|
+
@port = 80
|
19
|
+
@environments = [ :production ]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Configure SpeakingApps. Puts this in your initializers
|
23
|
+
#
|
24
|
+
# SpeakingApps.configure do |config|
|
25
|
+
# config.token = '_your_token_goes_here_'
|
26
|
+
# config.environments = [ :development, :production ] # Defaults to [ :production ]
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
def configure # :yields: config
|
30
|
+
yield self
|
31
|
+
|
32
|
+
@environments = @environments.collect { |e| e.to_sym } if @environments
|
33
|
+
|
14
34
|
unless class_variable_defined?(:@@_message_queue)
|
15
|
-
@@_message_queue = SpeakingApps::MessageQueue.new(environment)
|
16
|
-
ensure_existence_of_service_daemon
|
35
|
+
@@_message_queue = SpeakingApps::MessageQueue.new(@environment)
|
36
|
+
ensure_existence_of_service_daemon if @@_message_queue.environment_valid?
|
17
37
|
end
|
18
38
|
end
|
19
|
-
|
39
|
+
|
20
40
|
# Send a Messages. You can optionally assign Tags.
|
21
41
|
#
|
22
42
|
# * <tt>SpeakingApps.log('hello World')</tt>
|
@@ -62,7 +82,7 @@ module SpeakingApps
|
|
62
82
|
end
|
63
83
|
end
|
64
84
|
|
65
|
-
def send_to_app(message)
|
85
|
+
def send_to_app(message) #:nodoc:
|
66
86
|
$stdout.puts message
|
67
87
|
end
|
68
88
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
Daemons.run_proc('speaking-apps', { :dir_mode => :normal, :dir => '/tmp', :multiple => false,:monitor => true}) do
|
2
2
|
path = File.expand_path(File.join(File.dirname(__FILE__), 'queue_service.rb'))
|
3
|
-
|
3
|
+
debug = "-- --debug" if ARGV.delete('--debug')
|
4
|
+
exec "/usr/bin/env ruby #{path} -p 28128 #{debug}"
|
4
5
|
end
|
@@ -36,6 +36,7 @@ module SpeakingApps
|
|
36
36
|
def self.post_to_remote(uri, encoded_post_data)
|
37
37
|
uri = URI.parse(uri)
|
38
38
|
|
39
|
+
debug "Opening connection to #{uri.host}:#{uri.port} / #{uri.path}"
|
39
40
|
http = Net::HTTP.new(uri.host, uri.port)
|
40
41
|
http.use_ssl = false
|
41
42
|
|
@@ -48,7 +49,7 @@ module SpeakingApps
|
|
48
49
|
|
49
50
|
case api_response
|
50
51
|
when Net::HTTPCreated
|
51
|
-
debug "Send message: '#{encoded_post_data}' to #{uri.host}"
|
52
|
+
debug "Send message: '#{encoded_post_data}' to #{uri.host}:#{uri.port}"
|
52
53
|
return API_RESPONSE_SUCCESS
|
53
54
|
else
|
54
55
|
log "SpeakingApps Error: #{ api_response.body if api_response.respond_to?(:body) }"
|
@@ -8,7 +8,7 @@ module SpeakingApps
|
|
8
8
|
attr_accessor :environment
|
9
9
|
|
10
10
|
def initialize(environment = nil)
|
11
|
-
@environment = environment
|
11
|
+
@environment = environment.to_s if environment
|
12
12
|
end
|
13
13
|
|
14
14
|
def add(message, *attr)
|
@@ -17,9 +17,9 @@ module SpeakingApps
|
|
17
17
|
:message => message,
|
18
18
|
:tags => attr,
|
19
19
|
:environment => @environment,
|
20
|
-
:token => SpeakingApps
|
21
|
-
:host => SpeakingApps
|
22
|
-
:port => SpeakingApps
|
20
|
+
:token => SpeakingApps.token,
|
21
|
+
:host => SpeakingApps.host,
|
22
|
+
:port => SpeakingApps.port.to_s
|
23
23
|
})
|
24
24
|
end
|
25
25
|
end
|
@@ -37,7 +37,7 @@ module SpeakingApps
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def store_in_remote_service_queue(message_with_options = {})
|
40
|
-
|
40
|
+
begin
|
41
41
|
Timeout::timeout(2) do
|
42
42
|
hub_url = URI.parse('http://127.0.0.1:28128/messages')
|
43
43
|
response = Net::HTTP.start(hub_url.host, hub_url.port) do |http|
|
@@ -45,13 +45,14 @@ module SpeakingApps
|
|
45
45
|
end
|
46
46
|
return response == Net::HTTPCreated
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
rescue => error
|
49
|
+
puts error
|
50
|
+
return false
|
51
|
+
end
|
51
52
|
end
|
52
53
|
|
53
54
|
def environment_valid? #:nodoc#
|
54
|
-
@environment.nil? || ::SpeakingApps
|
55
|
+
@environment.nil? || ::SpeakingApps.environments.include?(@environment.to_sym)
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
data/rails/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
SpeakingApps.init(RAILS_ENV)
|
1
|
+
SpeakingApps.init(RAILS_ENV)
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require 'lib/speaking_apps
|
2
|
+
require 'lib/speaking_apps'
|
3
3
|
require 'lib/speaking_apps/message_queue'
|
4
4
|
|
5
5
|
describe 'SpeakingApps::MessageQueue' do
|
6
6
|
before(:each) do
|
7
|
-
SpeakingApps
|
8
|
-
|
7
|
+
SpeakingApps.init
|
8
|
+
SpeakingApps.environments = [ :test ]
|
9
|
+
SpeakingApps.token = 'test'
|
9
10
|
@message_queue = SpeakingApps::MessageQueue.new
|
10
|
-
@message_queue.environment =
|
11
|
+
@message_queue.environment = :test
|
11
12
|
@message_queue.stub!(:environment_valid?).and_return(true)
|
12
13
|
end
|
13
14
|
|
@@ -47,6 +48,6 @@ describe 'SpeakingApps::MessageQueue' do
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def message_hash(opts = {})
|
50
|
-
{ :environment=>
|
51
|
+
{ :environment=> 'test', :host=>"speakingapps.com", :port=>"80", :tags=>[], :message=>"", :token=> 'test' }.merge(opts)
|
51
52
|
end
|
52
53
|
end
|
@@ -8,12 +8,12 @@ describe SpeakingApps do
|
|
8
8
|
SpeakingApps.stub!(:message_queue).and_return(@mock_message_queue)
|
9
9
|
end
|
10
10
|
|
11
|
-
describe '#
|
11
|
+
describe '#configure' do
|
12
12
|
it 'should try to load the service daemon' do
|
13
13
|
SpeakingApps.stub!(:class_variable_defined?).and_return(false)
|
14
14
|
@mock_message_queue.stub!(:environment_valid?).and_return(true)
|
15
15
|
SpeakingApps.should_receive(:ensure_existence_of_service_daemon)
|
16
|
-
SpeakingApps.
|
16
|
+
SpeakingApps.configure { |config| config.token = 'Test' }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamicdudes-speaking-apps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rubyphunk
|
@@ -33,6 +33,16 @@ dependencies:
|
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 1.1.3
|
35
35
|
version:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sinatra
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.9.0.4
|
45
|
+
version:
|
36
46
|
description: The official SpeakingApps Gem. Allows your Rails app (or every other Ruby project) to chat with the http://speakingapps.com logging service.
|
37
47
|
email: treas@dynamicdudes.com
|
38
48
|
executables:
|
@@ -42,7 +52,6 @@ extensions: []
|
|
42
52
|
extra_rdoc_files: []
|
43
53
|
|
44
54
|
files:
|
45
|
-
- lib/speaking_apps/config.rb
|
46
55
|
- lib/speaking_apps/daemon/control.rb
|
47
56
|
- lib/speaking_apps/daemon/queue_service.rb
|
48
57
|
- lib/speaking_apps/daemon/remote.rb
|
@@ -55,7 +64,6 @@ files:
|
|
55
64
|
- VERSION.yml
|
56
65
|
- spec/lib
|
57
66
|
- spec/lib/speaking_apps
|
58
|
-
- spec/lib/speaking_apps/config_spec.rb
|
59
67
|
- spec/lib/speaking_apps/daemon
|
60
68
|
- spec/lib/speaking_apps/daemon/queue_service_spec.rb
|
61
69
|
- spec/lib/speaking_apps/daemon/remote_spec.rb
|
data/lib/speaking_apps/config.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module SpeakingApps
|
2
|
-
|
3
|
-
# Use <b>SpeakingApps::Config</b> to setup your http://SpeakingApps.com API access.
|
4
|
-
#
|
5
|
-
# Please note: You must set the token in order to use the API.
|
6
|
-
# Don't know your token? Login to your account on http://youraccount.speakingapps.com (or get a new one),
|
7
|
-
# select your project and open 'Settings'.
|
8
|
-
#
|
9
|
-
# Place the configuration wherever you want. In a Rails app you would typically add these lines
|
10
|
-
# under <tt>config/environment</tt> or <tt>config/initializers/</tt>.
|
11
|
-
|
12
|
-
class Config
|
13
|
-
|
14
|
-
# Configure which Project-Token to use.
|
15
|
-
#
|
16
|
-
# <tt>SpeakingApps::Config.token = 'your-api-token'</tt>
|
17
|
-
def self.token=(new_token)
|
18
|
-
@@_token = new_token
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.token #:nodoc:
|
22
|
-
class_variable_defined?(:@@_token) ? @@_token : nil
|
23
|
-
end
|
24
|
-
|
25
|
-
# Set the environment(s) in which SpeakingApps#log should be active. Defaults to: ['production']
|
26
|
-
#
|
27
|
-
# <tt>SpeakingApps::Config.environments = ['staging', 'production']</tt>
|
28
|
-
def self.environments=(new_environments)
|
29
|
-
@@_environments = new_environments
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.environments #:nodoc:
|
33
|
-
class_variable_defined?(:@@_environments) ? @@_environments : ['production']
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.host=(new_host) #:nodoc:
|
37
|
-
@@_host = new_host
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.host #:nodoc:
|
41
|
-
class_variable_defined?(:@@_host) ? @@_host : 'speakingapps.com'
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.port=(new_port) #:nodoc:
|
45
|
-
@@_port = new_port
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.port #:nodoc:
|
49
|
-
class_variable_defined?(:@@_host) ? @@_port : '80'
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.clear! #:nodoc:
|
53
|
-
class_variables.each do |v|
|
54
|
-
remove_class_variable v.intern rescue true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require 'lib/speaking_apps/config'
|
3
|
-
|
4
|
-
describe SpeakingApps::Config do
|
5
|
-
before(:each) do
|
6
|
-
SpeakingApps::Config.clear!
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should allow setting the token' do
|
10
|
-
SpeakingApps::Config.token = 'test'
|
11
|
-
SpeakingApps::Config.token.should eql('test')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should allow defining environments' do
|
15
|
-
SpeakingApps::Config.environments = ['development', 'production']
|
16
|
-
SpeakingApps::Config.environments.should eql(['development', 'production'])
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should use the default environment "production" if nothing was set' do
|
20
|
-
SpeakingApps::Config.environments.should eql(['production'])
|
21
|
-
end
|
22
|
-
end
|