sqs2mandrill 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f0ff95205cdfa8aae7991ae1e9e263244328637
4
+ data.tar.gz: 50c001e1055e19ea0649a5f2cd1c6973d1af913c
5
+ SHA512:
6
+ metadata.gz: 2d9ff8cd8697c8c9d37659124491722886803178c3763327406776f9c082426038210658821fd084b5956c5fa0270b1fb9e187500e96d82ff3787ea08697ad6f
7
+ data.tar.gz: 267d5a791ebdd84329a7c94dc7c1a70121ea61e46608051e811cec4c7715f912c61416c27cb7214c0c493441051325846451e37a3528ab3ffdd4034610b2d648
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sqs2mandrill.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 EmergeAdapt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ijonas Kisselbach
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Sqs2mandrill
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sqs2mandrill'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sqs2mandrill
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/sqs2mandrill/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+ # Prepares the $LOAD_PATH by adding to it lib directories of the gem and
5
+ # its dependencies:
6
+ require 'sqs2mandrill'
7
+
8
+ mh = Sqs2mandrill::MessageHandler.new
9
+ mh.transfer_messages
@@ -0,0 +1,68 @@
1
+ require "sqs2mandrill/version"
2
+ require "aws-sdk-v1"
3
+ require "json"
4
+ require "logger"
5
+ require "mandrill"
6
+
7
+ module Sqs2mandrill
8
+ class MessageHandler
9
+ def initialize
10
+ @awsAccessKeyId = ENV['AWS_ACCESS_KEY']
11
+ @awsSecretAccessKey = ENV['AWS_SECRET_ACCESS_KEY']
12
+ @queue = ENV['MANDRILL_QUEUE']
13
+ logfile = ENV['SQS2MANDRILL_LOGFILE_PATH'].nil? ? STDOUT : File.open(ENV['SQS2MANDRILL_LOGFILE_PATH'], 'a')
14
+ @logger = Logger.new logfile
15
+ @stop = false
16
+
17
+ raise RuntimeError, "Please ensure AWS_ACCESS_KEY is set." if @awsAccessKeyId.nil? or @awsAccessKeyId.empty?
18
+ raise RuntimeError, "Please ensure AWS_SECRET_ACCESS_KEY is set." if @awsSecretAccessKey.nil? or @awsSecretAccessKey.empty?
19
+ raise RuntimeError, "Please ensure MANDRILL_QUEUE is set." if @queue.nil? or @queue.empty?
20
+
21
+ @logger.info "MessageHandler ready to transfer messages."
22
+ end
23
+
24
+ def stop
25
+ @stop = true
26
+ end
27
+
28
+ def transfer_messages
29
+ @logger.info "MessageHandler awaiting first message from #{@queue}"
30
+ begin
31
+ sqs = AWS::SQS.new(region: 'us-east-1', access_key_id: @awsAccessKeyId, secret_access_key: @awsSecretAccessKey)
32
+ sqs.queues[@queue].poll do |message|
33
+ handle_received_message(message)
34
+ return if @stop
35
+ end
36
+ rescue Exception => ex
37
+ @logger.error "Something cause an SQS failure."
38
+ @logger.error ex
39
+ end
40
+ end
41
+
42
+ def handle_received_message(message)
43
+ @logger.info "Message received."
44
+ @logger.debug message.body
45
+ payload = JSON.parse(message.body)
46
+ send_to_mandrill(payload["template_name"], payload["template_content"], payload["message"])
47
+ rescue JSON::ParserError => ex
48
+ # TODO needs some form of remote notification that an error occured.
49
+ @logger.error "Bad message format. Unable to deserialize message into JSON."
50
+ @logger.error ex
51
+ rescue Exception => ex
52
+ @logger.error "Something caused a message handling failure."
53
+ @logger.error ex
54
+ end
55
+
56
+ def send_to_mandrill(template_name, template_content, message)
57
+ @logger.info "Sending to Mandrill"
58
+
59
+ m = Mandrill::API.new
60
+ @logger.debug m.messages.send_template(template_name, template_content, message)
61
+
62
+
63
+ @logger.info "Message sent."
64
+ rescue Exception => ex
65
+ @logger.error ex
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module Sqs2mandrill
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sqs2mandrill/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sqs2mandrill"
8
+ spec.version = Sqs2mandrill::VERSION
9
+ spec.authors = ["EmergeAdapt"]
10
+ spec.email = ["development@emergeadapt.com"]
11
+ spec.summary = %q{Takes a JSON payload off an SQS queue and posts it to Mandrills email service.}
12
+ spec.description = %q{Basic WIP.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "aws-sdk-v1", "~> 1.60.2"
24
+ spec.add_dependency "mandrill-api", "~> 1.0.53"
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqs2mandrill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - EmergeAdapt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-v1
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.60.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.60.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: mandrill-api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.53
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.53
69
+ description: Basic WIP.
70
+ email:
71
+ - development@emergeadapt.com
72
+ executables:
73
+ - sqs2mandrill
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/sqs2mandrill
84
+ - lib/sqs2mandrill.rb
85
+ - lib/sqs2mandrill/version.rb
86
+ - sqs2mandrill.gemspec
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Takes a JSON payload off an SQS queue and posts it to Mandrills email service.
111
+ test_files: []