apphunk 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/apphunk.gemspec +8 -7
- data/lib/apphunk.rb +2 -2
- data/lib/apphunk/proxy.rb +16 -14
- data/spec/apphunk/proxy_spec.rb +12 -27
- metadata +60 -20
- data/lib/apphunk/remote.rb +0 -29
- data/lib/apphunk/remote/result.rb +0 -15
data/Rakefile
CHANGED
@@ -6,13 +6,14 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "apphunk"
|
8
8
|
gem.summary = %Q{A library that send's messages to Apphunk.com}
|
9
|
-
gem.description = %Q{Apphunk is a library that allows your applications
|
9
|
+
gem.description = %Q{Apphunk is a library that allows your applications to send messages to Apphunk.com}
|
10
10
|
gem.email = "andreas@apphunk.com"
|
11
11
|
gem.homepage = "http://apphunk.com"
|
12
12
|
gem.authors = ["Andreas Wolff"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
14
|
gem.add_development_dependency "yard", ">= 0"
|
15
15
|
gem.add_dependency "json"
|
16
|
+
gem.add_dependency "postbox", ">= 0.2.0"
|
16
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
18
|
end
|
18
19
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/apphunk.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{apphunk}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andreas Wolff"]
|
12
|
-
s.date = %q{2010-
|
13
|
-
s.description = %q{Apphunk is a library that allows your applications
|
12
|
+
s.date = %q{2010-06-30}
|
13
|
+
s.description = %q{Apphunk is a library that allows your applications to send messages to Apphunk.com}
|
14
14
|
s.email = %q{andreas@apphunk.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
@@ -31,8 +31,6 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/apphunk/config.rb",
|
32
32
|
"lib/apphunk/logger.rb",
|
33
33
|
"lib/apphunk/proxy.rb",
|
34
|
-
"lib/apphunk/remote.rb",
|
35
|
-
"lib/apphunk/remote/result.rb",
|
36
34
|
"rails/init.rb",
|
37
35
|
"spec/apphunk/proxy_spec.rb",
|
38
36
|
"spec/apphunk_spec.rb",
|
@@ -42,7 +40,7 @@ Gem::Specification.new do |s|
|
|
42
40
|
s.homepage = %q{http://apphunk.com}
|
43
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
44
42
|
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = %q{1.3.
|
43
|
+
s.rubygems_version = %q{1.3.7}
|
46
44
|
s.summary = %q{A library that send's messages to Apphunk.com}
|
47
45
|
s.test_files = [
|
48
46
|
"spec/apphunk/proxy_spec.rb",
|
@@ -54,19 +52,22 @@ Gem::Specification.new do |s|
|
|
54
52
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
53
|
s.specification_version = 3
|
56
54
|
|
57
|
-
if Gem::Version.new(Gem::
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
56
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
59
57
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
60
58
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
59
|
+
s.add_runtime_dependency(%q<postbox>, [">= 0.2.0"])
|
61
60
|
else
|
62
61
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
63
62
|
s.add_dependency(%q<yard>, [">= 0"])
|
64
63
|
s.add_dependency(%q<json>, [">= 0"])
|
64
|
+
s.add_dependency(%q<postbox>, [">= 0.2.0"])
|
65
65
|
end
|
66
66
|
else
|
67
67
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
68
68
|
s.add_dependency(%q<yard>, [">= 0"])
|
69
69
|
s.add_dependency(%q<json>, [">= 0"])
|
70
|
+
s.add_dependency(%q<postbox>, [">= 0.2.0"])
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
data/lib/apphunk.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'postbox'
|
2
3
|
|
3
4
|
module Apphunk
|
4
5
|
|
5
6
|
autoload :Config, 'apphunk/config'
|
6
7
|
autoload :Logger, 'apphunk/logger'
|
7
8
|
autoload :Proxy, 'apphunk/proxy'
|
8
|
-
autoload :Remote, 'apphunk/remote'
|
9
9
|
|
10
10
|
class << self
|
11
11
|
|
@@ -108,4 +108,4 @@ module Apphunk
|
|
108
108
|
|
109
109
|
end
|
110
110
|
|
111
|
-
Apphunk.init_defaults
|
111
|
+
Apphunk.init_defaults
|
data/lib/apphunk/proxy.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'ostruct'
|
3
2
|
|
4
3
|
module Apphunk
|
5
4
|
module Proxy
|
6
5
|
class << self
|
7
6
|
|
8
|
-
PROXY_API_URL = "http://127.0.0.1:8212/api/messages"
|
9
|
-
|
10
7
|
def send_message_to_apphunkd(message, options)
|
11
8
|
if options[:environments] && options[:environment] && !options[:environments].include?(options[:environment])
|
12
9
|
return false
|
13
10
|
end
|
14
11
|
|
15
12
|
payload = prepare_payload(message, options)
|
16
|
-
|
17
|
-
return
|
13
|
+
url = generate_api_messages_url(payload[:token])
|
14
|
+
return Postbox.post(url, payload) do |result|
|
15
|
+
process_response(result)
|
16
|
+
end
|
18
17
|
end
|
19
18
|
|
20
19
|
def prepare_payload(message, options)
|
@@ -28,19 +27,22 @@ module Apphunk
|
|
28
27
|
end
|
29
28
|
|
30
29
|
def process_response(result)
|
31
|
-
if result.
|
32
|
-
|
33
|
-
return true
|
34
|
-
else
|
35
|
-
Apphunk::Logger.error "The Apphunkd-Proxy couldn't store the message: #{result.response.code} / #{result.response.body}"
|
36
|
-
return false
|
37
|
-
end
|
30
|
+
if result.success == true
|
31
|
+
return true
|
38
32
|
else
|
39
|
-
Apphunk::Logger.error "
|
33
|
+
Apphunk::Logger.error "Could not store message: #{result.response}"
|
40
34
|
return false
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def generate_api_messages_url(token)
|
42
|
+
path = "v1/#{token}/messages"
|
43
|
+
"http://api.apphunk.com/#{path}"
|
44
|
+
end
|
45
|
+
|
44
46
|
end
|
45
47
|
end
|
46
|
-
end
|
48
|
+
end
|
data/spec/apphunk/proxy_spec.rb
CHANGED
@@ -4,12 +4,13 @@ describe Apphunk::Proxy do
|
|
4
4
|
describe 'send_message_to_apphunkd_proxy' do
|
5
5
|
before(:each) do
|
6
6
|
@opts = { :tags => 'test', :token => 'secret' }
|
7
|
-
|
7
|
+
@payload = { :token => 'secret' }
|
8
8
|
Apphunk::Proxy.stub!(:process_response).and_return(true)
|
9
|
+
Postbox.stub!(:post)
|
9
10
|
end
|
10
11
|
|
11
12
|
it 'should prepare the payload' do
|
12
|
-
Apphunk::Proxy.should_receive(:prepare_payload).with("My Message", @opts)
|
13
|
+
Apphunk::Proxy.should_receive(:prepare_payload).with("My Message", @opts).and_return(@payload)
|
13
14
|
Apphunk::Proxy.send_message_to_apphunkd("My Message", @opts)
|
14
15
|
end
|
15
16
|
|
@@ -21,17 +22,12 @@ describe Apphunk::Proxy do
|
|
21
22
|
|
22
23
|
context 'posting' do
|
23
24
|
before(:each) do
|
24
|
-
@payload = {
|
25
|
+
@payload = { :prepared => "payload", :token => "secret" }
|
25
26
|
Apphunk::Proxy.stub!(:prepare_payload).and_return(@payload)
|
26
27
|
end
|
27
28
|
|
28
|
-
it 'should post the payload
|
29
|
-
|
30
|
-
Apphunk::Proxy.send_message_to_apphunkd("My Message", @opts)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should allow the post to only take 3 seconds to finish' do
|
34
|
-
Apphunk::Remote.should_receive(:post).with(anything, anything, 3)
|
29
|
+
it 'should post the payload' do
|
30
|
+
Postbox.should_receive(:post).with('http://api.apphunk.com/v1/secret/messages', @payload)
|
35
31
|
Apphunk::Proxy.send_message_to_apphunkd("My Message", @opts)
|
36
32
|
end
|
37
33
|
end
|
@@ -39,28 +35,17 @@ describe Apphunk::Proxy do
|
|
39
35
|
|
40
36
|
describe 'process_response' do
|
41
37
|
before(:each) do
|
42
|
-
@result =
|
43
|
-
@result.response = mock('Response')
|
44
|
-
Apphunk::Remote.stub!(:post).and_return(@result)
|
38
|
+
@result = OpenStruct.new
|
45
39
|
end
|
46
40
|
|
47
41
|
it 'should return true if the Proxy return 201, created' do
|
48
|
-
@result.
|
49
|
-
@result
|
50
|
-
Apphunk::Proxy.process_response(@result)
|
42
|
+
@result.success = true
|
43
|
+
Apphunk::Proxy.process_response(@result).should be_true
|
51
44
|
end
|
52
45
|
|
53
46
|
it 'should output the failure and return false if the Proxy doesn not return 201' do
|
54
|
-
@result.
|
55
|
-
|
56
|
-
@result.response.stub!(:body).and_return("Not found.")
|
57
|
-
Apphunk::Logger.should_receive(:error).with(/Not found/)
|
58
|
-
Apphunk::Proxy.process_response(@result)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should output the failure and return false if the connection to the proxy failed' do
|
62
|
-
@result.status = :connection_error
|
63
|
-
Apphunk::Logger.should_receive(:error).with(/Connection Error/)
|
47
|
+
@result.success = false
|
48
|
+
Apphunk::Logger.should_receive(:error).with(/not store/)
|
64
49
|
Apphunk::Proxy.process_response(@result)
|
65
50
|
end
|
66
51
|
end
|
@@ -70,7 +55,7 @@ describe Apphunk::Proxy do
|
|
70
55
|
@opts = { :token => 'secret', :environment => 'development', :tags => 'test', :trails => { :user => '5' } }
|
71
56
|
end
|
72
57
|
|
73
|
-
it 'should create
|
58
|
+
it 'should create a Hash, containing the message and extracted options' do
|
74
59
|
payload = Apphunk::Proxy.prepare_payload("My Message", @opts)
|
75
60
|
payload[:message].should == "My Message"
|
76
61
|
payload[:token].should == "secret"
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apphunk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Andreas Wolff
|
@@ -9,40 +15,70 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-06-30 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
23
34
|
version: 1.2.9
|
24
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: yard
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
33
48
|
version: "0"
|
34
|
-
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
35
51
|
- !ruby/object:Gem::Dependency
|
36
52
|
name: json
|
37
|
-
|
38
|
-
|
39
|
-
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
40
56
|
requirements:
|
41
57
|
- - ">="
|
42
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
43
62
|
version: "0"
|
44
|
-
|
45
|
-
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: postbox
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 23
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
- 2
|
77
|
+
- 0
|
78
|
+
version: 0.2.0
|
79
|
+
type: :runtime
|
80
|
+
version_requirements: *id004
|
81
|
+
description: Apphunk is a library that allows your applications to send messages to Apphunk.com
|
46
82
|
email: andreas@apphunk.com
|
47
83
|
executables: []
|
48
84
|
|
@@ -66,8 +102,6 @@ files:
|
|
66
102
|
- lib/apphunk/config.rb
|
67
103
|
- lib/apphunk/logger.rb
|
68
104
|
- lib/apphunk/proxy.rb
|
69
|
-
- lib/apphunk/remote.rb
|
70
|
-
- lib/apphunk/remote/result.rb
|
71
105
|
- rails/init.rb
|
72
106
|
- spec/apphunk/proxy_spec.rb
|
73
107
|
- spec/apphunk_spec.rb
|
@@ -83,21 +117,27 @@ rdoc_options:
|
|
83
117
|
require_paths:
|
84
118
|
- lib
|
85
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
86
121
|
requirements:
|
87
122
|
- - ">="
|
88
123
|
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
89
127
|
version: "0"
|
90
|
-
version:
|
91
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
92
130
|
requirements:
|
93
131
|
- - ">="
|
94
132
|
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
95
136
|
version: "0"
|
96
|
-
version:
|
97
137
|
requirements: []
|
98
138
|
|
99
139
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.3.
|
140
|
+
rubygems_version: 1.3.7
|
101
141
|
signing_key:
|
102
142
|
specification_version: 3
|
103
143
|
summary: A library that send's messages to Apphunk.com
|
data/lib/apphunk/remote.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'timeout'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
module Apphunk
|
6
|
-
module Remote
|
7
|
-
|
8
|
-
autoload :Result, 'apphunk/remote/result'
|
9
|
-
|
10
|
-
class << self
|
11
|
-
|
12
|
-
def post(url, payload = {}, post_timeout = 30)
|
13
|
-
begin
|
14
|
-
Timeout.timeout(post_timeout) do
|
15
|
-
uri = URI.parse(url)
|
16
|
-
result = Remote::Result.new(:response => Net::HTTP.post_form(uri, payload))
|
17
|
-
result.status = :ok
|
18
|
-
return result
|
19
|
-
end
|
20
|
-
rescue SocketError, Errno::ECONNREFUSED
|
21
|
-
Remote::Result.new(:status => :connection_error)
|
22
|
-
rescue Timeout::Error
|
23
|
-
Remote::Result.new(:status => :timeout)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|