leadersend 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce9b8259f8b1e82631796939e260515e24b9f5a0
4
+ data.tar.gz: 1bfa1fe938bddb1a1f7da47d7be64729658a5e9d
5
+ SHA512:
6
+ metadata.gz: e5a905477a67dc7213822f7d64672bd8f94a4a871b615e026e69531a3f21dbb88156d1b001a7aeeaca2740e74ae8c07d8fa8433089972702f3eb82563fbd59a1
7
+ data.tar.gz: 5646ef8c222edf8f8005ad3b5892fc2b24480b8a3f5af18cbd277a2dee45e2d8e3328b260a111ac800773a00b75ba977955e77d73552792982ce5244aa93e98e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in leadersend.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Epigene
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,88 @@
1
+ # Leadersend
2
+
3
+ Ruby wrapper for Leadersend transactional email sending service
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'leadersend'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install leadersend
20
+
21
+ ## Usage
22
+
23
+ LS can be used instead of Leadersend
24
+
25
+ ### Configure
26
+ ```ruby
27
+ # /config/initializers/leadersend.rb
28
+
29
+ Leadersend.configure do |config|
30
+ config.username = "example@domain.com"
31
+ config.api_key = "0953e545acdf063cb8a903a174gh721f" # place your key here
32
+ config.api_url = "http://api.leadersend.com/1.0/?output=json" # leave as is
33
+ config.host = "smtp.leadersend.com" # leave as is
34
+ end
35
+ ```
36
+
37
+ Setup ActionMailer::Base.smtp_settings with
38
+ ```ruby
39
+ ActionMailer::Base.smtp_settings = {
40
+ :address => Leadersend.config.host,
41
+ :port => '587',
42
+ :authentication => :plain,
43
+ :user_name => Leadersend.config.username,
44
+ :password => Leadersend.config.api_key,
45
+ :domain => 'example-domain.com'
46
+ }
47
+ ```
48
+
49
+ ### Send Email
50
+ Instantiate a Leadersend::Mail object with given parameters
51
+ ```ruby
52
+ mailer = Leadersend::Mail.new to: self.email, from: from, fromname: fromname, subject: subject, template_path: template_path, locals: locals, title: title
53
+ ```
54
+ Parameter examples and explanations:
55
+ ```ruby
56
+ to: "example@email.com"
57
+ from: "coworker@company.com"
58
+ fromname: "Bob"
59
+ subject: "Friday party!"
60
+ template_path = "delivery/partials/party_markup"
61
+ title = "It is friday!"
62
+ locals = {variable: value, another_variable: different_value} # These will be made available in the template
63
+ ```
64
+
65
+ Call the #send method on the instantiated objecto send an email. This method returns a hash
66
+ ```ruby
67
+ sent_mail_hash = mailer.send
68
+ ```
69
+
70
+ ### Log the sending
71
+ Result hash content and explanations:
72
+ ```ruby
73
+ {
74
+ title: @title,
75
+ body: @template, # returns the actual markup generated
76
+ status: status, # very useful, returns "sent" on success and "error" on fail
77
+ subject: @subject,
78
+ to_address: @to,
79
+ response: result.inspect # a verbose repeat of what you already knew, for example
80
+ :response=>"[{\"email\"=>\"example@email.com\", \"status\"=>\"sent\", \"id\"=>\"ecf0ea8f33df690a02c83ccc86x678be\"}]"
81
+ }
82
+ ```
83
+
84
+ Use this information to populate a logging object like SentMail
85
+
86
+
87
+
88
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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 'leadersend/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "leadersend"
8
+ spec.version = Leadersend::VERSION
9
+ spec.date = Date.today.to_s
10
+ spec.authors = ["Epigene", "Sacristan", "artursbraucs"]
11
+ spec.email = ["augusts.bautra@gmail.com"]
12
+ spec.summary = %q{Ruby wrapper for LeaderSend, the Transactional Email Delivery Service}
13
+ spec.description = %q{Ruby wrapper for LeaderSend, the Transactional Email Delivery Service}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency 'rspec', "~> 3.2.0"
25
+ end
data/lib/leadersend.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'leadersend/version'
2
+ require 'leadersend/mailer'
3
+
4
+ module Leadersend
5
+ ROOT = File.expand_path("../..", __FILE__)
6
+
7
+ def self.root
8
+ return ROOT
9
+ end
10
+
11
+ class << self
12
+ attr_accessor :config
13
+ end
14
+
15
+ def self.configure
16
+ self.config ||= Config.new
17
+ yield(config)
18
+ end
19
+
20
+ class Config
21
+ attr_accessor :api_url, :host, :username, :api_key
22
+
23
+ def initialize
24
+ @api_url = "http://api.leadersend.com/1.0/?output=json"
25
+ @host = "smtp.leadersend.com"
26
+ @username = "example@domain.com"
27
+ @api_key = "0953e545acdf063cb8a903a174gh721f"
28
+ end
29
+
30
+ end
31
+
32
+ Leadersend.configure {}
33
+ end
34
+
35
+ LS = Leadersend
@@ -0,0 +1,58 @@
1
+ module Leadersend
2
+ class Mail
3
+ def initialize to: nil, from: nil, fromname: nil, subject: "System", template_path: nil, locals: {}, title: "System"
4
+ @api_email_url = LEADERSEND_API_URL
5
+ @api_user = LEADERSEND_USERNAME
6
+ @api_key = LEADERSEND_API_KEY
7
+ @to = to
8
+ @subject = subject
9
+ @template_path = template_path
10
+ @locals = locals
11
+ @title = title
12
+ @from = from
13
+ @fromname = fromname
14
+ @template_path = template_path
15
+
16
+ if @template_path
17
+ @template = ApplicationController.new.render_to_string(:partial => @template_path, :locals => @locals )
18
+ end
19
+ end
20
+
21
+ def send
22
+ result = call_api
23
+ status = (result[0] && result[0]["status"]) ? result[0]["status"] : "error"
24
+ return {
25
+ title: @title,
26
+ body: @template,
27
+ status: status,
28
+ subject: @subject,
29
+ to_address: @to,
30
+ response: result.inspect
31
+ }
32
+ end
33
+
34
+ def call_api
35
+ subject = @subject
36
+ fromname = @fromname
37
+ options = {method: "messagesSend", apikey: @api_key, to: {email: @to}, subject: @subject, html: @template, from: {name: @fromname, email: @from}, auto_plain: true}
38
+ resp = post_api @api_email_url, options
39
+ json = JSON.parse(resp)
40
+ puts json
41
+ return json
42
+ rescue => e
43
+ return [{"status" => "error", "description" => "<#{e.class.name}>: #{e.message}"}]
44
+ end
45
+
46
+ private
47
+
48
+ def post_api url, params
49
+ uri = URI.parse(url)
50
+ http = Net::HTTP.new(uri.host, uri.port)
51
+ http.use_ssl = false
52
+ form_params = params.to_query
53
+ res = http.post(uri.request_uri, form_params)
54
+ res.body
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Leadersend
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'leadersend' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ # rspec-expectations config goes here. You can use an alternate
8
+ # assertion/expectation library such as wrong or the stdlib/minitest
9
+ # assertions if you prefer.
10
+ config.expect_with :rspec do |expectations|
11
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
12
+ end
13
+
14
+ config.mock_with :rspec do |mocks|
15
+ mocks.verify_partial_doubles = true
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ # rspec spec/tests/basic_spec.rb
2
+ describe "Leadersend" do
3
+ it "#root returns gem root" do
4
+ expect(Leadersend.root).to eq File.expand_path("../../..", __FILE__)
5
+ end
6
+
7
+ describe "config" do
8
+ it "default username should be ok" do
9
+ expect(Leadersend.config.username).to eq "example@domain.com"
10
+ end
11
+ it "default api_key should be ok" do
12
+ expect(Leadersend.config.api_key).to eq "0953e545acdf063cb8a903a174gh721f"
13
+ end
14
+ it "default api_url should be ok" do
15
+ expect(Leadersend.config.api_url).to eq "http://api.leadersend.com/1.0/?output=json"
16
+ end
17
+ it "default host should be ok" do
18
+ expect(Leadersend.config.host).to eq "smtp.leadersend.com"
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leadersend
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Epigene
8
+ - Sacristan
9
+ - artursbraucs
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-02-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.7'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 3.2.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 3.2.0
57
+ description: Ruby wrapper for LeaderSend, the Transactional Email Delivery Service
58
+ email:
59
+ - augusts.bautra@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - leadersend.gemspec
71
+ - lib/leadersend.rb
72
+ - lib/leadersend/mailer.rb
73
+ - lib/leadersend/version.rb
74
+ - spec/spec_helper.rb
75
+ - spec/tests/basic_spec.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Ruby wrapper for LeaderSend, the Transactional Email Delivery Service
100
+ test_files:
101
+ - spec/spec_helper.rb
102
+ - spec/tests/basic_spec.rb