mailosaur 0.0.15
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 +7 -0
- data/LICENSE +20 -0
- data/README.md +77 -0
- data/lib/mailosaur.rb +100 -0
- data/lib/mailosaur/attachment.rb +10 -0
- data/lib/mailosaur/email.rb +23 -0
- data/lib/mailosaur/email_address.rb +9 -0
- data/lib/mailosaur/email_data.rb +13 -0
- data/lib/mailosaur/image.rb +8 -0
- data/lib/mailosaur/link.rb +8 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 501a6cd736f697c7ce94be900f857908a429236e
|
4
|
+
data.tar.gz: 30b1efc11055ef774708c6626420988a907b4136
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 779191e3b09423f86fac7d48d723e739fc0840056fbb447ac436b0d021cfef8f5863548a91bfdb0d700e5121f2e1f78df0dfcbf0d48fd6155701591126a58dff
|
7
|
+
data.tar.gz: 34afbb94d69fd211d0bc37f30dea9ac8cbf9ec137bb26a5cf86dd092d0324bfbfcebe46edb9db68b342f2491d9797b564c296d7a94c3d575ab45cca0237f361a
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Clickity Ltd
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Mailosaur Ruby bindings
|
2
|
+
|
3
|
+
Mailosaur allows you to automate tests that require email. You can also use it for manual testing as it gives you unlimited test email addresses or use it as a fake/dummy SMTP service.
|
4
|
+
|
5
|
+
For more info go to [mailosaur.com](https://mailosaur.com/)
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
gem install mailosaur
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
```ruby
|
14
|
+
require 'mailosaur'
|
15
|
+
require "test/unit"
|
16
|
+
|
17
|
+
mailbox = Mailosaur.new(mailbox,apikey)
|
18
|
+
|
19
|
+
emails = mailbox.getEmailsByRecipient('anything.1eaaeef6@mailosaur.in')
|
20
|
+
|
21
|
+
assert_equal('something', emails[0].Subject, 'The subject should be something')
|
22
|
+
```
|
23
|
+
##Api
|
24
|
+
|
25
|
+
*functions:*
|
26
|
+
|
27
|
+
- **Email[] GetEmails(String searchPattern)** - Retrieves all emails which have the searchPattern text in their body or subject.
|
28
|
+
|
29
|
+
- **Email[] GetEmailsByRecipient(String recipientEmail)** -
|
30
|
+
Retrieves all emails sent to the given recipient.
|
31
|
+
|
32
|
+
- **Email GetEmail(String emailId)** -
|
33
|
+
Retrieves the email with the given id.
|
34
|
+
|
35
|
+
- **Void DeleteAllEmail()** -
|
36
|
+
Deletes all emails in a mailbox.
|
37
|
+
|
38
|
+
- **Void DeleteEmail(String emailId)** -
|
39
|
+
Deletes the email with the given id.
|
40
|
+
|
41
|
+
- **Byte[] GetAttachment(String attachmentId)** -
|
42
|
+
Retrieves the attachment with specified id.
|
43
|
+
|
44
|
+
- **Byte[] GetRawEmail(String rawId)** -
|
45
|
+
Retrieves the complete raw EML file for the rawId given. RawId is a property on the email object.
|
46
|
+
|
47
|
+
- **String GenerateEmailAddress()** -
|
48
|
+
Generates a random email address which can be used to send emails into the mailbox.
|
49
|
+
|
50
|
+
*structures*
|
51
|
+
|
52
|
+
- **Email** - The core object returned by the Mailosaur API
|
53
|
+
- **id** - The email identifier
|
54
|
+
- **creationdate** - The date your email was received by Mailosaur
|
55
|
+
- **senderHost** - The host name of the machine that sent the email
|
56
|
+
- **rawId** - Reference for raw email data
|
57
|
+
- **html** - The HTML content of the email
|
58
|
+
- **links** - All links found within the HTML content of the email
|
59
|
+
- **images** - All images found within the HTML content of the email
|
60
|
+
- **body** - Unescaped HTML body of the email
|
61
|
+
- **text** - The text content of the email
|
62
|
+
- **links** - All links found within the text content of the email
|
63
|
+
- **body** - Text body of the email
|
64
|
+
- **headers** - Contains all email headers as object properties
|
65
|
+
- **subject** - Email subject
|
66
|
+
- **priority** - Email priority
|
67
|
+
- **from** - Details of email sender(s)
|
68
|
+
- **address** - Email address
|
69
|
+
- **name** - Email sender name
|
70
|
+
- **to** - Details of email recipient(s)
|
71
|
+
- **address** - Email address
|
72
|
+
- **name** - Email recipient name
|
73
|
+
- **attachments** - Details of any attachments found within the email
|
74
|
+
- **id** - Attachment identifier
|
75
|
+
- **fileName** - Attachment file name
|
76
|
+
- **length** - Attachment file size (in bytes)
|
77
|
+
- **contentType** - Attachment mime type (e.g. "image/png")
|
data/lib/mailosaur.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'json'
|
4
|
+
require 'rest_client'
|
5
|
+
require 'securerandom'
|
6
|
+
require 'date'
|
7
|
+
require "#{File.dirname(__FILE__)}/mailosaur/email"
|
8
|
+
|
9
|
+
# Main class to access Mailosaur.com api.
|
10
|
+
class Mailosaur
|
11
|
+
@MAILBOX
|
12
|
+
@API_KEY
|
13
|
+
@BASE_URI
|
14
|
+
|
15
|
+
# Pass in your mailbox id and api key to authenticate
|
16
|
+
# Leave mailbox and/or apiKey empty to load settings from environment.
|
17
|
+
# export MAILOSAUR_APIKEY=abcex7
|
18
|
+
# export MAILOSAUR_MAILBOX=123456abcde
|
19
|
+
def initialize(mailbox, apiKey)
|
20
|
+
@MAILBOX = ENV['MAILOSAUR_MAILBOX'] || mailbox
|
21
|
+
@API_KEY = ENV['MAILOSAUR_APIKEY'] || apiKey
|
22
|
+
@BASE_URI = 'https://mailosaur.com/v2'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Retrieves all emails which have the searchPattern text in their body or subject.
|
26
|
+
def getEmails(searchCriteria = Hash.new)
|
27
|
+
if searchCriteria.is_a? String
|
28
|
+
search = searchCriteria
|
29
|
+
searchCriteria = Hash.new
|
30
|
+
searchCriteria['search'] = search
|
31
|
+
end
|
32
|
+
searchCriteria['key'] = @API_KEY
|
33
|
+
searchCriteria['mailbox'] = @MAILBOX
|
34
|
+
for i in 1..10
|
35
|
+
response = RestClient.get("#{@BASE_URI}/emails", {:params => searchCriteria})
|
36
|
+
data = JSON.parse(response.body)
|
37
|
+
emails = data.map { |em| Email.new(em) }
|
38
|
+
|
39
|
+
if !emails.nil? && emails.length>0
|
40
|
+
return emails
|
41
|
+
end
|
42
|
+
# back off and retry
|
43
|
+
sleep(i*i)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Retrieves all emails sent to the given recipient.
|
48
|
+
def getEmailsByRecipient(recipientEmail)
|
49
|
+
searchCriteria = Hash.new
|
50
|
+
searchCriteria['recipient']= recipientEmail
|
51
|
+
return getEmails(searchCriteria)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Retrieves the email with the given id.
|
55
|
+
def getEmail(emailId)
|
56
|
+
params = Hash.new
|
57
|
+
params['key'] = @API_KEY
|
58
|
+
response = RestClient.get(@BASE_URI + '/email/' + emailId, {:params => params})
|
59
|
+
data = JSON.parse(response.body)
|
60
|
+
email = Email.new(data)
|
61
|
+
return email
|
62
|
+
end
|
63
|
+
|
64
|
+
# Deletes all emails in a mailbox.
|
65
|
+
def deleteAllEmail
|
66
|
+
queryParams = Hash.new
|
67
|
+
queryParams['key'] = @API_KEY
|
68
|
+
queryParams['mailbox'] = @MAILBOX
|
69
|
+
RestClient.post("#{@BASE_URI}/emails/deleteall", nil, {:params => queryParams})
|
70
|
+
end
|
71
|
+
|
72
|
+
# Deletes the email with the given id.
|
73
|
+
def deleteEmail(emailId)
|
74
|
+
params = Hash.new
|
75
|
+
params['key'] = @API_KEY
|
76
|
+
RestClient.post(@BASE_URI + '/email/' + emailId + '/delete/', nil,{:params => params})
|
77
|
+
end
|
78
|
+
|
79
|
+
# Retrieves the attachment with specified id.
|
80
|
+
def getAttachment(attachmentId)
|
81
|
+
params = Hash.new
|
82
|
+
params['key'] = @API_KEY
|
83
|
+
response = RestClient.get(@BASE_URI + '/attachment/' + attachmentId, {:params => params})
|
84
|
+
return response.body
|
85
|
+
end
|
86
|
+
|
87
|
+
# Retrieves the complete raw EML file for the rawId given. RawId is a property on the email object.
|
88
|
+
def getRawEmail(rawId)
|
89
|
+
params = Hash.new
|
90
|
+
params['key'] = @API_KEY
|
91
|
+
response = RestClient.get(@BASE_URI + '/raw/' + rawId, {:params => params})
|
92
|
+
return response.body
|
93
|
+
end
|
94
|
+
|
95
|
+
# Generates a random email address which can be used to send emails into the mailbox.
|
96
|
+
def generateEmailAddress()
|
97
|
+
uuid = SecureRandom.hex(3)
|
98
|
+
return "%s.%s@mailosaur.in" % [uuid, @MAILBOX]
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/email_address"
|
2
|
+
require "#{File.dirname(__FILE__)}/email_data"
|
3
|
+
require "#{File.dirname(__FILE__)}/attachment"
|
4
|
+
|
5
|
+
class Email
|
6
|
+
attr_accessor :id, :creationdate, :senderHost, :from, :to, :mailbox, :rawId, :html, :text, :headers, :subject, :priority, :attachments
|
7
|
+
|
8
|
+
def initialize(hash)
|
9
|
+
@id = hash['id']
|
10
|
+
@creationdate = DateTime.iso8601(hash['creationdate'])
|
11
|
+
@senderHost = hash['senderHost']
|
12
|
+
@from= hash['from'].map { |f| EmailAddress.new(f) }
|
13
|
+
@to= hash['to'].map { |t| EmailAddress.new(t) }
|
14
|
+
@mailbox = hash['mailbox']
|
15
|
+
@rawId = hash['rawId']
|
16
|
+
@html = hash.has_key?('html')?EmailData.new(hash['html']):nil
|
17
|
+
@text = hash.has_key?('text')?EmailData.new(hash['text']):nil
|
18
|
+
@headers = hash['headers']
|
19
|
+
@subject = hash['subject']
|
20
|
+
@priority = hash['priority']
|
21
|
+
@attachments = hash.has_key?('attachments')?hash['attachments'].map { |a| Attachment.new(a) } : nil
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/link"
|
2
|
+
require "#{File.dirname(__FILE__)}/image"
|
3
|
+
|
4
|
+
|
5
|
+
class EmailData
|
6
|
+
attr_accessor :links, :body, :images
|
7
|
+
|
8
|
+
def initialize(hash)
|
9
|
+
@links =hash.has_key?('links') ? hash['links'].map { |a| Link.new(a) } : nil
|
10
|
+
@body = hash['body']
|
11
|
+
@images = hash.has_key?('images') ? hash['images'].map { |a| Image.new(a) } : nil
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailosaur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.15
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Clickity Ltd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mime-types
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.25'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.25'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mail
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.6.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.6.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 10.3.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.3.2
|
83
|
+
description: Gem containing ruby bindings for the mailosaur.com mail testing api.
|
84
|
+
email: support@mailosaur.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- LICENSE
|
90
|
+
- README.md
|
91
|
+
- lib/mailosaur.rb
|
92
|
+
- lib/mailosaur/attachment.rb
|
93
|
+
- lib/mailosaur/email.rb
|
94
|
+
- lib/mailosaur/email_address.rb
|
95
|
+
- lib/mailosaur/email_data.rb
|
96
|
+
- lib/mailosaur/image.rb
|
97
|
+
- lib/mailosaur/link.rb
|
98
|
+
homepage: http://mailosaur.com
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.2.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Bindings for mailosaur.com
|
122
|
+
test_files: []
|