appygram 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # Appygram <http://www.appygram.com>
2
+
3
+ Appygram is a simple service to handle messages from your web
4
+ or mobile app. This gem provides communication with the Appygram
5
+ service via a simple API. Useful features higher in the stack
6
+ are found in gems that depend on this one, e.g. appygram-rails,
7
+ which automatically turns uncaught Rails exceptions into traces.
8
+
9
+ ## Installation
10
+
11
+ 1. Add gem entry to Gemfile
12
+
13
+ ```ruby
14
+ gem 'appygram'
15
+ ```
16
+
17
+ 2. Run <code>bundle install</code>
18
+
19
+ 3. Configure your API Key in an initializer, e.g. config/appygram.rb
20
+
21
+ ```ruby
22
+ Appygram.configure :api_key => 'your_api_key'
23
+ ```
24
+
25
+ using a valid API key for your app provided by Appygram
26
+
27
+ ## Invocation
28
+
29
+ ```ruby
30
+ require 'appygram'
31
+
32
+ # Sending an appygram
33
+ Appygram.send :topic => 'Test', :message => 'This is a test.'
34
+
35
+ # Sending a trace
36
+ Appygram.trace some_exception
37
+
38
+ # Sending a trace with accompanying appygram fields
39
+ Appygram.trace some_exception, :email => 'some_user@domain'
40
+ ```
41
+
42
+ ## Supported fields in an appygram
43
+
44
+ * topic - of principal importance in message routing
45
+ * subject
46
+ * message
47
+ * name
48
+ * email
49
+ * phone
50
+ * platform ('web' by default for this connector)
51
+ * software ('appygram.rb [VERSION]' by default for this connector)
52
+ * app_json - Any object assigned to this field will be serialized
53
+ into JSON. If it is a hash, top level keys will be addressable
54
+ in the message routing and formatting.
55
+
56
+ ## Traces
57
+
58
+ * Traces send the current stack trace from your application.
59
+ * Appygram deduplicates traces and treats them statistically;
60
+ traces are converted to notifications based on rules agreed by
61
+ the system and the user.
62
+ * If you send fields (like "name" and "email") along with the
63
+ trace, Appygram can put that information into notifications.
64
+ For example, if you generate a trace because of an unexpected
65
+ exception, and you include the contact information for the
66
+ logged-in user who experienced the exception, responders can
67
+ more easily identify and communicate with the affected user
68
+ about what might have led to the exception.
69
+
70
+ ## Additional configuration options
71
+
72
+ You can call Appygram.configure multiple times safely, or pack
73
+ all the options you need into one call.
74
+
75
+ To minimize network bandwidth in the event that your app generates
76
+ a LOT of traces, you can throttle the trace sender when you configure
77
+ Appygram. You can throttle all traces on a per-second basis, or
78
+ duplicate traces per day.
79
+
80
+ ```ruby
81
+ Appygram.configure :max_traces_per_second => 3
82
+ # and/or
83
+ Appygram.configure :max_duplicate_traces_per_day => 1
84
+ ```
85
+
86
+ You can set defaults for the platform or software at configuration time.
87
+
88
+ ```ruby
89
+ Appygram.configure :platform => 'Ruboto'
90
+ # and/or
91
+ Appygram.configure :software => 'awesomesauce'
92
+ ```
93
+
94
+ The standard endpoints for Appygram are built in. If you need to change
95
+ them, you can configure <code>:appygram_endpoint</code> and
96
+ <code>:trace_endpoint</code> to the full URL destination where data is
97
+ to be sent.
98
+
99
+ If you send traces, you can provide a map of uri stubs to paths
100
+ within your application. Appygram will use these to hyperlink
101
+ the traces to the appropriate repository online. This map may
102
+ be also populated by higher level gems, like appygram_rails;
103
+ anything you supply here will be additively merged.
104
+
105
+ ```ruby
106
+ Appygram.add_trace_uris 'lib' => 'http://github.com/anythinglabs/appygram.rb'
107
+ ```
108
+
109
+ ## Rules for improvement
110
+
111
+ * This gem must not have other dependencies.
112
+ * This gem may take advantage of other gems (e.g. async i/o,
113
+ background queueing, http pooling) if detected, and the advantage
114
+ is related directly to communication with the service
115
+ * Effort should be made to retain parity with other fully supported
116
+ connectors
117
+
118
+ Copyright © 2012 Solertium
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib/appygram'
6
+ t.test_files = FileList['test/*.rb']
7
+ end
data/lib/appygram.rb CHANGED
@@ -1,14 +1,28 @@
1
1
  require "appygram/version"
2
2
  require 'net/http'
3
3
  require 'net/https'
4
+ require 'json'
4
5
 
5
6
  module Appygram
6
7
  def self.configure(params)
7
- Appygram::Config.api_key = params[:api_key]
8
- endpoint = params[:endpoint] || 'https://appygram.herokuapp.com/appygrams'
9
- Appygram::Config.endpoint = URI endpoint
10
- Appygram::Config.platform = params[:platform] || 'web'
11
- Appygram::Config.software = params[:software] || "appygram.rb #{Appygram::VERSION}"
8
+ if params[:api_key]
9
+ Appygram::Config.api_key = params[:api_key]
10
+ end
11
+ if params[:appygram_endpoint]
12
+ appygram_endpoint = params[:appygram_endpoint] || 'https://appygram.herokuapp.com/appygrams'
13
+ Appygram::Config.appygram_endpoint = URI appygram_endpoint
14
+ end
15
+ if params[:trace_endpoint]
16
+ trace_endpoint = params[:trace_endpoint] || 'https://appygram.appspot.com/traces'
17
+ Appygram::Config.trace_endpoint = URI trace_endpoint
18
+ end
19
+ if params[:platform]
20
+ Appygram::Config.platform = params[:platform] || 'web'
21
+ end
22
+ if params[:software]
23
+ Appygram::Config.software = params[:software] || "appygram.rb #{Appygram::VERSION}"
24
+ end
25
+ # TODO: respect throttling per readme
12
26
  end
13
27
 
14
28
  def self.send(params)
@@ -16,8 +30,38 @@ module Appygram
16
30
  pc[:api_key] = Appygram::Config.api_key
17
31
  pc[:platform] = Appygram::Config.platform unless pc[:platform]
18
32
  pc[:software] = Appygram::Config.software unless pc[:software]
19
- url = Appygram::Config.endpoint
33
+ if pc[:app_json]
34
+ pc[:app_json] = JSON pc[:app_json]
35
+ end
36
+ url = Appygram::Config.appygram_endpoint
37
+ req = Net::HTTP::Post.new url.request_uri
38
+ req.form_data = pc
39
+ session = Net::HTTP.new(url.hostname, url.port)
40
+ session.use_ssl = true
41
+ session.start {|http|
42
+ http.request(req)
43
+ }
44
+ end
45
+
46
+ def self.trace(exception, params = {})
47
+ pc = params.clone
48
+ pc[:api_key] = Appygram::Config.api_key
49
+ pc[:platform] = Appygram::Config.platform unless pc[:platform]
50
+ pc[:software] = Appygram::Config.software unless pc[:software]
51
+ if pc[:app_json]
52
+ pc[:app_json] = JSON pc[:app_json]
53
+ end
54
+ url = Appygram::Config.trace_endpoint
20
55
  req = Net::HTTP::Post.new url.request_uri
56
+ trace = []
57
+ exception.backtrace.each do |line|
58
+ trace << line.split(':')
59
+ end
60
+ pc[:trace] = JSON({
61
+ 'class' => exception.class.name,
62
+ 'message' => exception.message,
63
+ 'backtrace' => trace
64
+ })
21
65
  req.form_data = pc
22
66
  session = Net::HTTP.new(url.hostname, url.port)
23
67
  session.use_ssl = true
@@ -28,12 +72,15 @@ module Appygram
28
72
 
29
73
  class Config
30
74
  class << self
31
- attr_accessor :api_key, :endpoint, :software, :platform
75
+ attr_accessor :api_key, :appygram_endpoint, :trace_endpoint, :software, :platform
32
76
  def api_key
33
77
  return @api_key unless @api_key.nil?
34
78
  end
35
- def endpoint
36
- return @endpoint unless @endpoint.nil?
79
+ def appygram_endpoint
80
+ return @appygram_endpoint unless @appygram_endpoint.nil?
81
+ end
82
+ def trace_endpoint
83
+ return @trace_endpoint unless @trace_endpoint.nil?
37
84
  end
38
85
  def software
39
86
  return @software unless @software.nil?
@@ -1,3 +1,3 @@
1
1
  module Appygram
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/test/local.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'minitest/autorun'
2
+ require 'appygram'
3
+
4
+ describe Appygram do
5
+ describe "when invoking the gem" do
6
+ it "must have a version number" do
7
+ Appygram::VERSION.wont_be_nil
8
+ end
9
+ end
10
+ describe "when configuring" do
11
+ it "must support setting the API key" do
12
+ Appygram.configure :api_key => '123'
13
+ Appygram::Config.api_key.must_equal '123'
14
+ end
15
+ it "must support setting the platform" do
16
+ Appygram.configure :platform => 'test_plat'
17
+ Appygram::Config.platform.must_equal 'test_plat'
18
+ end
19
+ it "must support setting the software" do
20
+ Appygram.configure :software => 'test_sw'
21
+ Appygram::Config.software.must_equal 'test_sw'
22
+ end
23
+ it "must support overriding the appygram endpoint" do
24
+ Appygram.configure :appygram_endpoint => 'http://a/b'
25
+ Appygram::Config.appygram_endpoint.to_s.must_equal 'http://a/b'
26
+ end
27
+ it "must support overriding the trace endpoint" do
28
+ Appygram.configure :trace_endpoint => 'http://a/b'
29
+ Appygram::Config.trace_endpoint.to_s.must_equal 'http://a/b'
30
+ end
31
+ it "must not clobber values set earlier" do
32
+ Appygram::Config.platform.must_equal 'test_plat'
33
+ end
34
+ end
35
+ end
data/test/network.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'minitest/autorun'
2
+ require 'appygram'
3
+
4
+ describe Appygram do
5
+ before do
6
+ Appygram.configure :api_key => '6135441b70dc91c092fef59cb983f97eada68b75',
7
+ :appygram_endpoint => 'https://appygram.herokuapp.com/appygrams',
8
+ :trace_endpoint => 'https://appygram.appspot.com/traces'
9
+ end
10
+ describe "When connected to real servers" do
11
+ it "sends appygrams" do
12
+ Appygram.send :topic => 'Test', :message => 'This is a test.',
13
+ :app_json => { 'key' => 'value' }
14
+ end
15
+ it "sends traces" do
16
+ begin
17
+ raise "boom"
18
+ rescue StandardError => e
19
+ Appygram.trace e
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appygram
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2012-11-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Discovers topics and sends messages
15
15
  email:
@@ -20,11 +20,13 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
22
  - Gemfile
23
- - README.markdown
23
+ - README.md
24
24
  - Rakefile
25
25
  - appygram.gemspec
26
26
  - lib/appygram.rb
27
27
  - lib/appygram/version.rb
28
+ - test/local.rb
29
+ - test/network.rb
28
30
  homepage: https://github.com/anythinglabs/appygram.rb
29
31
  licenses: []
30
32
  post_install_message:
@@ -45,8 +47,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
47
  version: '0'
46
48
  requirements: []
47
49
  rubyforge_project: appygram
48
- rubygems_version: 1.8.15
50
+ rubygems_version: 1.8.17
49
51
  signing_key:
50
52
  specification_version: 3
51
53
  summary: Communicate with the Appygram message routing service
52
- test_files: []
54
+ test_files:
55
+ - test/local.rb
56
+ - test/network.rb
57
+ has_rdoc:
data/README.markdown DELETED
@@ -1,55 +0,0 @@
1
- # Appygram <http://www.appygram.com>
2
-
3
- Appygram is a simple service to handle messages from your web
4
- or mobile app. This gem provides communication with the Appygram
5
- service via a simple API. Useful features higher in the stack
6
- are found in gems that depend on this one, e.g. appygram-rails,
7
- which turns uncaught Rails exceptions into appygrams.
8
-
9
- ## Installation
10
-
11
- 1. Add gem entry to Gemfile
12
-
13
- ```ruby
14
- gem 'appygram'
15
- ```
16
-
17
- 2. Run <code>bundle install</code>
18
-
19
- 3. Configure your API Key in an initializer, e.g. config/appygram.rb
20
-
21
- ```ruby
22
- Appygram.configure :api_key => 'your_api_key'
23
- ```
24
-
25
- using a valid API key for your app provided by Appygram
26
-
27
- ## Invocation
28
-
29
- ```ruby
30
- require 'appygram'
31
-
32
- Appygram.send :topic => 'Test', :message => 'This is a test.'
33
- ```
34
-
35
- ## Supported fields in an appygram
36
-
37
- * topic
38
- * subject
39
- * message
40
- * name
41
- * email
42
- * phone
43
- * platform ('web' by default for this connector)
44
- * software ('appygram.rb [VERSION]' by default for this connector)
45
-
46
- ## Rules for improvement
47
-
48
- * This gem must not have other dependencies.
49
- * This gem may take advantage of other gems (e.g. async i/o,
50
- background queueing, http pooling) if detected, and the advantage
51
- is related directly to communication with the service
52
- * Effort should be made to retain parity with other fully supported
53
- connectors
54
-
55
- Copyright © 2012 Solertium