smtp2go 0.0.1 → 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 +4 -4
- data/.travis.yml +9 -5
- data/Guardfile +2 -2
- data/README.md +59 -19
- data/Rakefile +3 -3
- data/lib/smtp2go/core.rb +24 -19
- data/lib/smtp2go/exceptions.rb +13 -1
- data/lib/smtp2go/settings.rb +4 -4
- data/lib/smtp2go/version.rb +1 -1
- data/smtp2go.gemspec +5 -4
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7505696ab4e607ce4606d66d4e442f9a89ae67b
|
4
|
+
data.tar.gz: abbcdfaa17512beca6083bf61b6bba8181068118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1dcef3637bf2f52bfb8d8c98d8f2a4aa5d14739795dbdb15a1fc4356777c8f5bd3987fcb276f9edd3e3d3868466c86fb604ed386f1a6e85838e0ba7b7b29dcc
|
7
|
+
data.tar.gz: 0c028cefc7adea72bc58af82c18399549342606fa25849e20874f84ebe5274cb03cf015e9d0750d74e8b68b80a7599f6b3ac4e426362b41f53277b208da8c22a
|
data/.travis.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.
|
4
|
+
- 2.4.1
|
5
|
+
- 2.3.3
|
6
|
+
- 2.2.6
|
7
|
+
- 2.1.10
|
5
8
|
before_install: gem install bundler -v 1.13.7
|
9
|
+
service_name: travis-ci
|
6
10
|
notifications:
|
7
11
|
slack:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
secure:
|
12
|
+
secure: SwkR+0rZUYXK/nvYa6PBYj310weZNQyHrMFp+lqW+9vmrvefJ25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s0BzooDtFtnLyYHQ/91GmesQ1Bv+Y6CxOMM7uq9i8uFq5Y+EGnHNIz/MaSP39dkuJuwXWxLjA4sc8CGexxLvGYI7M5upaF06KJQnSbjVhDK7O5YPT4/3y1+Q3uveKESXqqu8peZWNnYN3KLXV0mTzRsHxk3FQF12ADjyqjIwzdvk/i1GO68qKnQvxJMQCVrMPYXtbUQNwJOgGFMmwQGM8yX6fWqPLRv41h9PScv+ZjUtHiy8B4SirXY1mTqlUu3GRPGXVkwtdxw5Dlc540aA=
|
data/Guardfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
guard :rspec, cmd: 'rspec --format documentation', :
|
1
|
+
guard :rspec, cmd: 'rspec --format documentation', all_on_start: true do
|
2
2
|
watch(%r{^spec/.+_spec\.rb$})
|
3
3
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
4
|
-
watch('spec/spec_helper.rb') {
|
4
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
5
5
|
end
|
data/README.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
-
|
1
|
+
[](https://travis-ci.org/smtp2go-oss/smtp2go-ruby)
|
2
|
+
[](https://coveralls.io/github/smtp2go-oss/smtp2go-ruby?branch=master)
|
3
|
+
[](https://badge.fury.io/rb/smtp2go)
|
4
|
+
[](https://gemnasium.com/github.com/smtp2go-oss/smtp2go-ruby)
|
5
|
+
[](https://codeclimate.com/github/smtp2go-oss/smtp2go-ruby)
|
6
|
+
[](https://codeclimate.com/github/smtp2go-oss/smtp2go-ruby)
|
7
|
+
[]()
|
2
8
|
|
3
|
-
|
9
|
+
# smtp2go
|
10
|
+
|
11
|
+
Library for interfacing with the [smtp2go API](https://apidoc.smtp2go.com/documentation/#/README)
|
12
|
+
|
13
|
+
We also have a [Ruby on Rails Library ](https://github.com/smtp2go-oss/smtp2go-rails)
|
4
14
|
|
5
15
|
## Installation
|
6
16
|
|
@@ -24,22 +34,52 @@ Sign up for a free account [here](https://www.smtp2go.com/pricing) and get an AP
|
|
24
34
|
|
25
35
|
$ export SMTP2GO_API_KEY="<your_API_key>"
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
require 'smtp2go'
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
Here is a REPL session showing a successful send and probing of the response object:
|
38
|
+
|
39
|
+
[1] pry(main)> require 'smtp2go'
|
40
|
+
=> true
|
41
|
+
[2] pry(main)> client = Smtp2go::Smtp2goClient.new
|
42
|
+
=> #<Smtp2go::Smtp2goClient:0x007fb6ee17b108
|
43
|
+
@api_key="<redacted>",
|
44
|
+
@headers=
|
45
|
+
{"Content-Type"=>"application/json",
|
46
|
+
"X-Smtp2go-Api"=>"smtp2go-ruby",
|
47
|
+
[3] pry(main)> payload = {
|
48
|
+
[3] pry(main)*> sender: 'dave@example.com',
|
49
|
+
[3] pry(main)*> recipients: ['matt@example.com'],
|
50
|
+
[3] pry(main)*> subject: 'Test Message',
|
51
|
+
[3] pry(main)*> text: 'Test message',
|
52
|
+
[3] pry(main)*> html: '<html><body><h1>Test HTML message</h1></body></html>'}</html>'}
|
53
|
+
=> {:sender=>'dave@example.com',
|
54
|
+
:recipients=>['matt@example.com'],
|
55
|
+
:subject=>'Test Message',
|
56
|
+
:text=>'Test message',
|
57
|
+
:html=>'<html><body><h1>Test HTML message</h1></body></html>'}</html>'}
|
58
|
+
[4] pry(main)> response = client.send payload
|
59
|
+
=> #<Smtp2go::Smtp2goResponse:0x007fb6ee268840
|
60
|
+
@rate_limit=
|
61
|
+
#<Smtp2go::RateLimit:0x007fb6ee268818
|
62
|
+
@limit="250",
|
63
|
+
@remaining="250",
|
64
|
+
@reset="51">,
|
65
|
+
@response=
|
66
|
+
{"request_id"=>"<redacted>",
|
67
|
+
"data"=>{"failures"=>[], "succeeded"=>1, "failed"=>0}}>
|
68
|
+
[5] pry(main)> response.rate_limit
|
69
|
+
=> #<Smtp2go::RateLimit:0x007fb6ee268818
|
70
|
+
@limit="250",
|
71
|
+
@remaining="250",
|
72
|
+
@reset="51">
|
73
|
+
[6] pry(main)> response.success?
|
74
|
+
=> true
|
75
|
+
[7] pry(main)> response.errors
|
76
|
+
=> nil
|
77
|
+
[8] pry(main)> response.json
|
78
|
+
=> {"request_id"=>"<redacted>",
|
79
|
+
"data"=>{"failures"=>[], "succeeded"=>1, "failed"=>0}}
|
80
|
+
[9] pry(main)>
|
81
|
+
|
82
|
+
Full API documentation can be found [here](https://apidoc.smtp2go.com/documentation/#/README), with Ruby specific docs [here](http://www.rubydoc.info/gems/smtp2go/0.0.1)
|
43
83
|
|
44
84
|
|
45
85
|
## Development
|
@@ -50,7 +90,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
50
90
|
|
51
91
|
## Contributing
|
52
92
|
|
53
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/smtp2go-oss/smtp2go.
|
93
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/smtp2go-oss/smtp2go-ruby.
|
54
94
|
|
55
95
|
|
56
96
|
## License
|
data/Rakefile
CHANGED
data/lib/smtp2go/core.rb
CHANGED
@@ -5,41 +5,45 @@ require 'smtp2go/settings'
|
|
5
5
|
|
6
6
|
module Smtp2go
|
7
7
|
# Ruby Library for interacting with the smtp2go API
|
8
|
-
|
9
8
|
class Smtp2goClient
|
9
|
+
# Client to handle API interfacing
|
10
10
|
attr_reader :headers, :send_endpoint
|
11
11
|
def initialize
|
12
12
|
@api_key = ENV['SMTP2GO_API_KEY']
|
13
13
|
@headers = HEADERS
|
14
14
|
@send_endpoint = SEND_ENDPOINT
|
15
|
-
raise Smtp2goAPIKeyException
|
16
|
-
'smtp2go requires SMTP2GO_API_KEY Environment Variable to be set' if not @api_key
|
15
|
+
raise Smtp2goAPIKeyException unless @api_key
|
17
16
|
end
|
18
17
|
|
19
18
|
# @param sender [String] the from email address
|
20
|
-
# @param recipients [Array <String>] the
|
19
|
+
# @param recipients [Array <String>] the email address of the recipient(s)
|
21
20
|
# @param subject [String] the email subject
|
22
|
-
# @param
|
21
|
+
# @param text [String] the email text content (optional if html is passed)
|
22
|
+
# @param html [String] the email html content (optional if text is passed)
|
23
23
|
# @return [Smtp2goResponse] response object
|
24
|
-
def send(sender:, recipients:, subject:,
|
24
|
+
def send(sender:, recipients:, subject:, text: nil, html: nil)
|
25
|
+
raise Smtp2goParameterException unless [html, text].any?
|
25
26
|
payload = {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
api_key: @api_key,
|
28
|
+
sender: sender,
|
29
|
+
to: recipients,
|
30
|
+
subject: subject,
|
31
|
+
text_body: text,
|
32
|
+
html_body: html
|
31
33
|
}
|
32
34
|
response = HTTParty.post(
|
33
35
|
@send_endpoint,
|
34
|
-
:
|
35
|
-
:
|
36
|
-
|
36
|
+
body: JSON.dump(payload),
|
37
|
+
headers: @headers
|
38
|
+
)
|
39
|
+
Smtp2goResponse.new response
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
43
|
+
# Wraps response object with smtp2go specific data
|
40
44
|
class Smtp2goResponse
|
41
45
|
attr_reader :rate_limit
|
42
|
-
def initialize
|
46
|
+
def initialize(response)
|
43
47
|
@response = response
|
44
48
|
@rate_limit = RateLimit.new @response.headers
|
45
49
|
end
|
@@ -49,15 +53,15 @@ module Smtp2go
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def success?
|
52
|
-
|
56
|
+
json['data']['succeeded'] ? true : false
|
53
57
|
end
|
54
58
|
|
55
59
|
def errors
|
56
|
-
|
60
|
+
json['data']['error']
|
57
61
|
end
|
58
62
|
|
59
63
|
def request_id
|
60
|
-
|
64
|
+
json['request_id']
|
61
65
|
end
|
62
66
|
|
63
67
|
def status_code
|
@@ -65,9 +69,10 @@ module Smtp2go
|
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
72
|
+
# Rate limiting class to be attached to response
|
68
73
|
class RateLimit
|
69
74
|
attr_reader :limit, :remaining, :reset
|
70
|
-
def initialize
|
75
|
+
def initialize(headers)
|
71
76
|
@limit = headers['x-ratelimit-limit']
|
72
77
|
@remaining = headers['x-ratelimit-remaining']
|
73
78
|
@reset = headers['x-ratelimit-reset']
|
data/lib/smtp2go/exceptions.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
module Smtp2go
|
2
|
-
class
|
2
|
+
class Smtp2goBaseException < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class Smtp2goAPIKeyException < Smtp2goBaseException
|
6
|
+
def message
|
7
|
+
'Smtp2go requires SMTP2GO_API_KEY Environment Variable to be set'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Smtp2goParameterException < Smtp2goBaseException
|
12
|
+
def message
|
13
|
+
'send call requires either text or html arguments'
|
14
|
+
end
|
3
15
|
end
|
4
16
|
end
|
data/lib/smtp2go/settings.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'smtp2go/version'
|
2
2
|
|
3
3
|
module Smtp2go
|
4
|
-
API_ROOT = 'https://api.smtp2go.com/v3/'
|
5
|
-
API_SEND_URL = 'email/send'
|
4
|
+
API_ROOT = 'https://api.smtp2go.com/v3/'.freeze
|
5
|
+
API_SEND_URL = 'email/send'.freeze
|
6
6
|
SEND_ENDPOINT = API_ROOT + API_SEND_URL
|
7
7
|
HEADERS = {
|
8
8
|
'Content-Type' => 'application/json',
|
9
9
|
'X-Smtp2go-Api' => 'smtp2go-ruby',
|
10
|
-
'X-Smtp2go-Api-Version' => VERSION
|
11
|
-
}
|
10
|
+
'X-Smtp2go-Api-Version' => VERSION
|
11
|
+
}.freeze
|
12
12
|
end
|
data/lib/smtp2go/version.rb
CHANGED
data/smtp2go.gemspec
CHANGED
@@ -30,12 +30,13 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
34
|
+
spec.add_development_dependency 'coveralls', '~> 0.8.19'
|
34
35
|
spec.add_development_dependency 'guard', '~> 2.13', '>= 2.13.0'
|
35
36
|
spec.add_development_dependency 'guard-rspec', '~> 4.6', '>= 4.6.4'
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
37
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
38
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
39
|
spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
39
40
|
spec.add_development_dependency 'webmock', '~> 2.3', '>= 2.3.2'
|
40
|
-
spec.add_runtime_dependency
|
41
|
+
spec.add_runtime_dependency 'httparty', '~> 0.14.0'
|
41
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smtp2go
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- smtp2go
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.19
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.19
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: guard
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,14 +84,14 @@ dependencies:
|
|
70
84
|
requirements:
|
71
85
|
- - "~>"
|
72
86
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
87
|
+
version: '12.0'
|
74
88
|
type: :development
|
75
89
|
prerelease: false
|
76
90
|
version_requirements: !ruby/object:Gem::Requirement
|
77
91
|
requirements:
|
78
92
|
- - "~>"
|
79
93
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
94
|
+
version: '12.0'
|
81
95
|
- !ruby/object:Gem::Dependency
|
82
96
|
name: rspec
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|