sendhub 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Sendhub
2
2
  class Client
3
3
 
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
 
6
6
  def initialize(config=nil)
7
7
  config[:host] ||= 'api.sendhub.net'
@@ -0,0 +1,45 @@
1
+ require 'sendhub'
2
+
3
+ module God
4
+ module Contacts
5
+ class Sendhub < Contact
6
+ class << self
7
+ attr_accessor :api_key, :secret_key, :from
8
+ end
9
+
10
+ def valid?
11
+ valid = true
12
+ valid &= complain("Attribute 'api_key' must be specified", self) unless arg(:api_key)
13
+ valid &= complain("Attribute 'secret_key' must be specified", self) unless arg(:secret_key)
14
+ valid &= complain("Attribute 'from' must be specified", self) unless arg(:from)
15
+ valid
16
+ end
17
+
18
+ attr_accessor :to
19
+
20
+ def notify(message, time, priority, category, host)
21
+ puts "#{message}"
22
+ data = {
23
+ :message => message,
24
+ :time => time,
25
+ :priority => priority,
26
+ :category => category,
27
+ :host => host
28
+ }
29
+
30
+ client = ::Sendhub::Client.new(:api_key => arg(:api_key), :secret_key => arg(:secret_key))
31
+ res = client.send_email(
32
+ :from => arg(:from),
33
+ :to => arg(:to),
34
+ :subject => "[god] #{message}",
35
+ :body => data.inspect
36
+ )
37
+
38
+ applog(nil, :info, res.inspect)
39
+ rescue Object => e
40
+ applog(nil, :info, "failed to send email to #{arg(:to)}: #{e.message}")
41
+ applog(nil, :debug, e.backtrace.join("\n"))
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ module SendhubMethods
2
+
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ @sendhub_settings = {}
9
+ attr_accessor :sendhub_settings
10
+ end
11
+
12
+ def perform_delivery_sendhub(message)
13
+ client = Sendhub::Client.new(
14
+ :api_key => ActionMailer::Base.sendhub_settings[:api_key],
15
+ :secret_key => ActionMailer::Base.sendhub_settings[:secret_key]
16
+ )
17
+ res = client.send_email(
18
+ :from => message.from,
19
+ :to => message.to,
20
+ :subject => message.subject,
21
+ :body => message.body,
22
+ :content_type => message.content_type
23
+ )
24
+ end
25
+
26
+ end
27
+
28
+ class ActionMailer::Base
29
+ include SendhubMethods
30
+ end
@@ -0,0 +1,22 @@
1
+ module Sendhub
2
+ class Rails
3
+ def initialize(options)
4
+ @client = Sendhub::Client.new(
5
+ :api_key => options[:api_key],
6
+ :secret_key => options[:secret_key]
7
+ )
8
+ end
9
+
10
+ def deliver!(message)
11
+ res = @client.send_email(
12
+ :from => message.from,
13
+ :to => message.to,
14
+ :subject => message.subject,
15
+ :body => message.body,
16
+ :content_type => message.content_type
17
+ )
18
+ end
19
+ end
20
+ end
21
+
22
+ ActionMailer::Base.add_delivery_method :sendhub, Sendhub::Rails
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendhub
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 9
10
- version: 0.1.9
9
+ - 10
10
+ version: 0.1.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Taylor
@@ -49,6 +49,9 @@ files:
49
49
  - lib/sendhub/client.rb
50
50
  - lib/sendhub/http.rb
51
51
  - lib/sendhub/response.rb
52
+ - lib/sendhub/plugins/god.rb
53
+ - lib/sendhub/plugins/rails2.rb
54
+ - lib/sendhub/plugins/rails3.rb
52
55
  has_rdoc: true
53
56
  homepage: http://sendhub.net/
54
57
  licenses: []