qwop_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qwop_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 DailyBurn
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.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # QwopClient
2
+
3
+ QwopClient is a client for publishing messages to an NSQ instance
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'qwop_client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install qwop_client
18
+
19
+ After installing you will need to add an initializer that defines QwopClient.nsq_host (default: localhost) and QwopClient.nsq_port (default: 4150). If using rails this file can be generated for you by running:
20
+
21
+ $ rails generate initializer
22
+
23
+ ## Usage
24
+
25
+ QwopClient::Mailers::Sendgrid.queue("name_of_your_nsq_queue", Mail.new)
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ class InitializerGenerator < Rails::Generators::Base
2
+ desc "This generator creates an initializer file at config/initializers"
3
+ def create_initializer_file
4
+ create_file "config/initializers/qwop_client_initializer.rb", "QwopClient.nsq_host='localhost'\nQwopClient.nsq_port=4150"
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ require "json"
2
+ require "nsq"
3
+ require "securerandom"
4
+
5
+ module QwopClient
6
+ class Client
7
+
8
+ def self.enqueue(queue, args)
9
+ message = {
10
+ :id => SecureRandom.uuid,
11
+ :task_name => "#{queue} Task",
12
+ :args => args
13
+ }
14
+
15
+ NSQ::Publisher.new(QwopClient::nsq_host, QwopClient::nsq_port) do |publisher|
16
+ publisher.publish(queue, message.to_json)
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'action_mailer'
2
+ require 'qwop_client/client'
3
+
4
+ module QwopClient
5
+ module Mailers
6
+ class Sendgrid
7
+
8
+ def self.queue(queue, mail)
9
+ mail.inform_interceptors
10
+ mail.inform_observers
11
+
12
+ to = mail.header[:to].to_s
13
+ from = mail.header[:from].to_s
14
+ subject = mail.subject
15
+ text_content = mail.parts[0] ? mail.parts[0].decoded : ""
16
+ html_content = mail.parts[1].decoded if mail.parts.length > 0
17
+ sendgrid_headers = {"X-SMTPAPI" => mail['X-SMTPAPI'].to_s}
18
+
19
+ QwopClient::Client.enqueue(queue, [to, from, subject, text_content, html_content, sendgrid_headers, ActionMailer::Base.perform_deliveries])
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module QwopClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "qwop_client/client"
2
+ require "qwop_client/mailers/sendgrid"
3
+ require "qwop_client/version"
4
+
5
+ module QwopClient
6
+ mattr_accessor :nsq_host, :nsq_port
7
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qwop_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qwop_client"
8
+ spec.version = QwopClient::VERSION
9
+ spec.authors = ["DailyBurn"]
10
+ spec.email = ["dev@dailyburn.com"]
11
+ spec.description = %q{QwopClient is a client for publishing messages to an NSQ instance}
12
+ spec.summary = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.6"
24
+
25
+ spec.add_dependency "actionmailer", ">= 3.0.0"
26
+ spec.add_dependency "ruby_nsq", "~> 0.0.2"
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'qwop_client'
2
+
3
+ describe QwopClient::Client do
4
+ describe "self.enqueue" do
5
+ it "should generate a unique message id" do
6
+ SecureRandom.should_receive(:uuid)
7
+ QwopClient::Client.enqueue("queue", "message")
8
+ end
9
+
10
+ it "should return an nsq publisher" do
11
+ QwopClient::Client.enqueue("queue", "message").should be_a(NSQ::Publisher)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ require 'qwop_client'
2
+ require 'mail'
3
+
4
+ describe QwopClient::Mailers::Sendgrid do
5
+ before(:all) do
6
+ @mail = Mail.new(:to => "test", :from => "test", :subject => "test")
7
+ end
8
+
9
+ describe "self.queue" do
10
+ it "should inform interceptors" do
11
+ @mail.should_receive(:inform_interceptors)
12
+ QwopClient::Mailers::Sendgrid.queue("mail_queue", @mail)
13
+ end
14
+
15
+ it "should inform observers" do
16
+ @mail.should_receive(:inform_observers)
17
+ QwopClient::Mailers::Sendgrid.queue("mail_queue", @mail)
18
+ end
19
+
20
+ it "should add sendgrid headers" do
21
+ QwopClient::Client.should_receive(:enqueue) do |arg1, arg2|
22
+ arg1.should eq "mail_queue"
23
+ arg2.should include({"X-SMTPAPI" => ""})
24
+ end
25
+ QwopClient::Mailers::Sendgrid.queue("mail_queue", @mail)
26
+ end
27
+
28
+ it "should queue the mail message" do
29
+ QwopClient::Mailers::Sendgrid.queue("mail_queue", @mail).should be_a(NSQ::Publisher)
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qwop_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - DailyBurn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.6'
62
+ - !ruby/object:Gem::Dependency
63
+ name: actionmailer
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 3.0.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 3.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: ruby_nsq
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.0.2
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.0.2
94
+ description: QwopClient is a client for publishing messages to an NSQ instance
95
+ email:
96
+ - dev@dailyburn.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - lib/generators/initializer_generator.rb
107
+ - lib/qwop_client.rb
108
+ - lib/qwop_client/client.rb
109
+ - lib/qwop_client/mailers/sendgrid.rb
110
+ - lib/qwop_client/version.rb
111
+ - qwop_client.gemspec
112
+ - spec/client_spec.rb
113
+ - spec/mailers/sendgrid_spec.rb
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 1.8.24
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: ''
139
+ test_files:
140
+ - spec/client_spec.rb
141
+ - spec/mailers/sendgrid_spec.rb