apphunk 0.1.1 → 0.3.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.
@@ -0,0 +1 @@
1
+ var search_data = {"index":{"searchIndex":["apphunk","config","logger","proxy","remote","result","config()","error()","log()","log_with_options()","new()","post()","prepare_payload()","process_response()","send_message_to_apphunkd()","license","readme.rdoc","apphunk.rb","config.rb","logger.rb","proxy.rb","remote.rb","result.rb"],"longSearchIndex":["lib/apphunk.rb","apphunk","apphunk","apphunk","apphunk","apphunk::remote","apphunk","apphunk::logger","apphunk","apphunk","apphunk::remote::result","apphunk::remote","apphunk::proxy","apphunk::proxy","apphunk::proxy","files/license.html","files/readme_rdoc.html","files/lib/apphunk_rb.html","files/lib/apphunk/config_rb.html","files/lib/apphunk/logger_rb.html","files/lib/apphunk/proxy_rb.html","files/lib/apphunk/remote_rb.html","files/lib/apphunk/remote/result_rb.html"],"info":[["Apphunk","lib/apphunk.rb","classes/Apphunk.html"," < ","",1],["Config","Apphunk","classes/Apphunk/Config.html"," < ","Used to configure the behaviour of Apphunk and its outgoing messages. Each option can be overriden by",1],["Logger","Apphunk","classes/Apphunk/Logger.html"," < ","",1],["Proxy","Apphunk","classes/Apphunk/Proxy.html"," < ","",1],["Remote","Apphunk","classes/Apphunk/Remote.html"," < ","",1],["Result","Apphunk::Remote","classes/Apphunk/Remote/Result.html"," < Object","",1],["config","Apphunk","classes/Apphunk.html#M000008","(&block)","Set runtime configuration options Yields Apphunk::Config which can be used to set configuration options",2],["error","Apphunk::Logger","classes/Apphunk/Logger.html#M000000","(message)","",2],["log","Apphunk","classes/Apphunk.html#M000006","(message, options = {})","Sends a +message+ to your remote inbox at apphunk.com * <tt>message</tt> - The body of the message *",2],["log_with_options","Apphunk","classes/Apphunk.html#M000007","(options = {}, &block)","Send messages with predefined options in a block Yields the Apphunk module which can be used to send",2],["new","Apphunk::Remote::Result","classes/Apphunk/Remote/Result.html#M000004","(opts = {})","",2],["post","Apphunk::Remote","classes/Apphunk/Remote.html#M000005","(url, payload = {}, post_timeout = 30)","",2],["prepare_payload","Apphunk::Proxy","classes/Apphunk/Proxy.html#M000002","(message, options)","",2],["process_response","Apphunk::Proxy","classes/Apphunk/Proxy.html#M000003","(result)","",2],["send_message_to_apphunkd","Apphunk::Proxy","classes/Apphunk/Proxy.html#M000001","(message, options)","",2],["LICENSE","files/LICENSE.html","files/LICENSE.html","","Copyright (c) 2009 Andreas Wolff Permission is hereby granted, free of charge, to any person obtaining",3],["README.rdoc","files/README_rdoc.html","files/README_rdoc.html","","= apphunk A library that send's messages to the remote logging service apphunk.com. == Note on Patches/Pull",3],["apphunk.rb","files/lib/apphunk_rb.html","files/lib/apphunk_rb.html","","",3],["config.rb","files/lib/apphunk/config_rb.html","files/lib/apphunk/config_rb.html","","",3],["logger.rb","files/lib/apphunk/logger_rb.html","files/lib/apphunk/logger_rb.html","","",3],["proxy.rb","files/lib/apphunk/proxy_rb.html","files/lib/apphunk/proxy_rb.html","","",3],["remote.rb","files/lib/apphunk/remote_rb.html","files/lib/apphunk/remote_rb.html","","",3],["result.rb","files/lib/apphunk/remote/result_rb.html","files/lib/apphunk/remote/result_rb.html","","",3]]}}
data/doc/panel/tree.js ADDED
@@ -0,0 +1 @@
1
+ var tree = [["","","files",[["LICENSE","files/LICENSE.html","",[]],["README.rdoc","files/README_rdoc.html","",[]],["","","lib",[["","","apphunk",[["config.rb","files/lib/apphunk/config_rb.html","",[]],["logger.rb","files/lib/apphunk/logger_rb.html","",[]],["proxy.rb","files/lib/apphunk/proxy_rb.html","",[]],["","","remote",[["result.rb","files/lib/apphunk/remote/result_rb.html","",[]]]],["remote.rb","files/lib/apphunk/remote_rb.html","",[]]]],["apphunk.rb","files/lib/apphunk_rb.html","",[]]]]]],["Apphunk","classes/Apphunk.html","",[["Config","classes/Apphunk/Config.html","",[]],["Logger","classes/Apphunk/Logger.html","",[]],["Proxy","classes/Apphunk/Proxy.html","",[]],["Remote","classes/Apphunk/Remote.html","",[["Result","classes/Apphunk/Remote/Result.html"," < Object",[]]]]]]]
@@ -0,0 +1,54 @@
1
+ module Apphunk
2
+
3
+ # Used to configure the behaviour of Apphunk and its outgoing messages. Each option can be overriden by Apphunk.log's +option+ parameter.
4
+ # If Apphunk is used as part of a Rails application, the configuration should go to +config/initializers/apphunk.rb+.
5
+ #
6
+ # *Note*: The configuration must be set using Apphunk.config as shown in the example below.
7
+ #
8
+ # ==== Example
9
+ # Apphunk.config do |config|
10
+ # config.token = "secret_project_token"
11
+ # end
12
+ #
13
+ module Config
14
+ class << self
15
+
16
+ # The current environment. Automatically retrieved if Apphunk is running as part of a Rails app.
17
+ #
18
+ # ==== Example
19
+ # config.environment = 'production'
20
+ #
21
+ attr_accessor :environment
22
+
23
+ # A list of allowed environments. Apphunk will only send messages if Apphunk::Config.environment is part of these allowed environments.
24
+ # *Note*: This step is skipped if Apphunk::Config.environment is +empty+.
25
+ #
26
+ # ==== Example
27
+ # config.environments = %w(production staging)
28
+ #
29
+ attr_accessor :environments
30
+
31
+ # A list of tags to be send with each message.
32
+ #
33
+ # ==== Example
34
+ # config.tags = 'each, message, will, get, these, tags'
35
+ #
36
+ attr_accessor :tags
37
+
38
+ # The token as provided by apphunk.com. Used to authenticate a message request.
39
+ #
40
+ # ==== Example
41
+ # config.token = 'secrect_project_token'
42
+ #
43
+ attr_accessor :token
44
+
45
+ # A list of trails to be send with each message.
46
+ #
47
+ # ==== Example
48
+ # config.trails = { :product => 'Car', :country => 'Germany' }
49
+ #
50
+ attr_accessor :trails
51
+
52
+ end
53
+ end
54
+ end
@@ -1,11 +1,19 @@
1
1
  module Apphunk
2
2
  module Logger
3
3
  class << self
4
-
4
+
5
5
  def error(message)
6
- puts "[Apphunk] Error: #{message}"
6
+ message = "[Apphunk] Error: #{message}"
7
+ case
8
+ when Rails && Rails.logger
9
+ Rails.logger.error(message)
10
+ when RAILS_DEFAULT_LOGGER
11
+ RAILS_DEFAULT_LOGGER.error(message)
12
+ else
13
+ puts(message)
14
+ end
7
15
  end
8
-
16
+
9
17
  end
10
18
  end
11
- end
19
+ end
data/lib/apphunk/proxy.rb CHANGED
@@ -8,6 +8,10 @@ module Apphunk
8
8
  PROXY_API_URL = "http://127.0.0.1:8212/api/messages"
9
9
 
10
10
  def send_message_to_apphunkd(message, options)
11
+ if options[:environments] && options[:environment] && !options[:environments].include?(options[:environment])
12
+ return false
13
+ end
14
+
11
15
  payload = prepare_payload(message, options)
12
16
  result = Apphunk::Remote.post(PROXY_API_URL, payload, 3)
13
17
  return process_response(result)
@@ -28,11 +32,11 @@ module Apphunk
28
32
  if result.response.code == '201'
29
33
  return true
30
34
  else
31
- Apphunk::Logger.error "The Apphunkd Proxy couldn't store the message: #{result.response.code} / #{result.response.body}"
35
+ Apphunk::Logger.error "The Apphunkd-Proxy couldn't store the message: #{result.response.code} / #{result.response.body}"
32
36
  return false
33
37
  end
34
38
  else
35
- Apphunk::Logger.error "Connection Error: Could not get a response from Apphunkd in time"
39
+ Apphunk::Logger.error "Connection Error: Could not get a response from local Apphunkd-Proxy in time"
36
40
  return false
37
41
  end
38
42
  end
data/lib/apphunk.rb CHANGED
@@ -2,19 +2,50 @@ require 'rubygems'
2
2
 
3
3
  module Apphunk
4
4
 
5
+ autoload :Config, 'apphunk/config'
5
6
  autoload :Logger, 'apphunk/logger'
6
7
  autoload :Proxy, 'apphunk/proxy'
7
8
  autoload :Remote, 'apphunk/remote'
8
9
 
9
10
  class << self
10
11
 
12
+ # Default options to be used for Apphunk.log. Initialized by Apphunk::Config.
11
13
  attr_accessor :default_options
12
14
 
15
+ # Sends a +message+ to your remote inbox at apphunk.com
16
+ #
17
+ # * <tt>message</tt> - The body of the message
18
+ # * <tt>options</tt> - A hash of options. Merges with Apphunk.default_options
19
+ #
20
+ # For a list of available options see Apphunk::Config.
21
+ #
22
+ # ==== Examples
23
+ #
24
+ # Apphunk.log("Yet another hello world")
25
+ # Apphunk.log("Tag me baby", :tags => 'apphunk, doc, examples', :trails => { :user_id => 5 })
26
+ # Apphunk.log("I'm on my way to a different project", :token => 'secret_project_access_token')
27
+ #
13
28
  def log(message, options = {})
14
29
  options = (self.default_options || {}).merge(options)
15
30
  Apphunk::Proxy.send_message_to_apphunkd(message, options)
16
31
  end
17
32
 
33
+ # Send messages with predefined options in a block
34
+ #
35
+ # Yields the Apphunk module which can be used to send messages via Apphunk.log,
36
+ # but temporarily merges the provided +options+ with Apphunk.default_options.
37
+ # Can be used to send a bunch of messages with the same options.
38
+ #
39
+ # * <tt>options</tt> - A hash of options. Merges with Apphunk.default_options
40
+ #
41
+ # For a list of available options see Apphunk::Config.
42
+ #
43
+ # ==== Examples
44
+ # Apphunk.log_with_options(:tags => 'hello world') do |apphunk|
45
+ # apphunk.log("A messages with tags")
46
+ # apphunk.log("Another messages with the same tags")
47
+ # end
48
+ #
18
49
  def log_with_options(options = {}, &block)
19
50
  preserved_defaults = self.default_options
20
51
  self.default_options = (self.default_options || {}).merge(options)
@@ -22,5 +53,31 @@ module Apphunk
22
53
  self.default_options = preserved_defaults
23
54
  end
24
55
 
56
+ # Set runtime configuration options
57
+ #
58
+ # Yields Apphunk::Config which can be used to set configuration options in one place.
59
+ # See Apphunk::Config for a list of available options. These options will be available in Apphunk.default_options.
60
+ #
61
+ # ==== Examples
62
+ #
63
+ # Apphunk.config do |config|
64
+ # config.token = "secret_project_token"
65
+ # config.environments = %w(staging production)
66
+ # end
67
+ #
68
+ def config(&block)
69
+ yield Apphunk::Config
70
+ self.default_options[:tags] = Apphunk::Config.tags
71
+ self.default_options[:token] = Apphunk::Config.token
72
+ self.default_options[:trails] = Apphunk::Config.trails
73
+ self.default_options[:environments] = Apphunk::Config.environments
74
+
75
+ if Apphunk::Config.environment.blank?
76
+ Apphunk::Config.environment = self.default_options[:environment]
77
+ else
78
+ self.default_options[:environment] = Apphunk::Config.environment
79
+ end
80
+ end
81
+
25
82
  end
26
83
  end
data/rails/init.rb CHANGED
@@ -0,0 +1,3 @@
1
+ # Init Apphunk Rails Support
2
+ # Set the default environment to current Rails.env
3
+ Apphunk.default_options = { :environment => RAILS_ENV || Rails.env }
@@ -13,6 +13,12 @@ describe Apphunk::Proxy do
13
13
  Apphunk::Proxy.send_message_to_apphunkd("My Message", @opts)
14
14
  end
15
15
 
16
+ it "should return false if options include allowed environments and the current environment isn't included in that list" do
17
+ @opts[:environments] = ['production', 'staging']
18
+ @opts[:environment] = 'development'
19
+ Apphunk::Proxy.send_message_to_apphunkd("My Message", @opts).should be_false
20
+ end
21
+
16
22
  context 'posting' do
17
23
  before(:each) do
18
24
  @payload = { "prepared" => "payload" }
@@ -66,15 +72,15 @@ describe Apphunk::Proxy do
66
72
 
67
73
  it 'should create an OpenStruct, containing the message and extracted options' do
68
74
  payload = Apphunk::Proxy.prepare_payload("My Message", @opts)
69
- payload.message.should == "My Message"
70
- payload.token.should == "secret"
71
- payload.environment.should == "development"
72
- payload.tags.should == "test"
75
+ payload[:message].should == "My Message"
76
+ payload[:token].should == "secret"
77
+ payload[:environment].should == "development"
78
+ payload[:tags].should == "test"
73
79
  end
74
80
 
75
81
  it 'should render the trails to json' do
76
82
  payload = Apphunk::Proxy.prepare_payload("My Message", @opts)
77
- payload.trails.should == "{\"user\":\"5\"}"
83
+ payload[:trails].should == "{\"user\":\"5\"}"
78
84
  end
79
85
  end
80
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apphunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Wolff
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-20 00:00:00 +01:00
12
+ date: 2009-11-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -61,7 +61,39 @@ files:
61
61
  - TODO.rdoc
62
62
  - VERSION
63
63
  - apphunk.gemspec
64
+ - doc/apple-touch-icon.png
65
+ - doc/classes/Apphunk.html
66
+ - doc/classes/Apphunk/Config.html
67
+ - doc/classes/Apphunk/Logger.html
68
+ - doc/classes/Apphunk/Proxy.html
69
+ - doc/classes/Apphunk/Remote.html
70
+ - doc/classes/Apphunk/Remote/Result.html
71
+ - doc/created.rid
72
+ - doc/css/main.css
73
+ - doc/css/panel.css
74
+ - doc/css/reset.css
75
+ - doc/favicon.ico
76
+ - doc/files/LICENSE.html
77
+ - doc/files/README_rdoc.html
78
+ - doc/files/lib/apphunk/config_rb.html
79
+ - doc/files/lib/apphunk/logger_rb.html
80
+ - doc/files/lib/apphunk/proxy_rb.html
81
+ - doc/files/lib/apphunk/remote/result_rb.html
82
+ - doc/files/lib/apphunk/remote_rb.html
83
+ - doc/files/lib/apphunk_rb.html
84
+ - doc/i/arrows.png
85
+ - doc/i/results_bg.png
86
+ - doc/i/tree_bg.png
87
+ - doc/index.html
88
+ - doc/js/jquery-1.3.2.min.js
89
+ - doc/js/jquery-effect.js
90
+ - doc/js/main.js
91
+ - doc/js/searchdoc.js
92
+ - doc/panel/index.html
93
+ - doc/panel/search_index.js
94
+ - doc/panel/tree.js
64
95
  - lib/apphunk.rb
96
+ - lib/apphunk/config.rb
65
97
  - lib/apphunk/logger.rb
66
98
  - lib/apphunk/proxy.rb
67
99
  - lib/apphunk/remote.rb
@@ -98,7 +130,7 @@ rubyforge_project:
98
130
  rubygems_version: 1.3.5
99
131
  signing_key:
100
132
  specification_version: 3
101
- summary: A library to send messages to Apphunk.com
133
+ summary: A library that send's messages to Apphunk.com
102
134
  test_files:
103
135
  - spec/apphunk/proxy_spec.rb
104
136
  - spec/apphunk_spec.rb