mailosaur 0.0.17 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -14
- data/lib/helper.rb +6 -0
- data/lib/mailosaur.rb +93 -70
- data/lib/mailosaur/message_generator.rb +31 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 958bed120db8df13a226f1f8cbfb58c0b6675d3f
|
4
|
+
data.tar.gz: 2339ed43752ac88db945241349114715dd722f0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ad786ad1421004232b750c89b6645f4ea9e53b66ede0fef35d6b8f988640c91e813ca3985a4145451043a740d55f5d081b3ca6851ee0dfb06dfc7625a4799f8
|
7
|
+
data.tar.gz: 89117a52e1f693a10824314ee6f6725aa7dcc1ff35809ac61bdf0f28684b1ae5df9df81ac71488683ed521a641383ce257efe62d73f638b61777c4691f9d0eee
|
data/README.md
CHANGED
@@ -7,47 +7,54 @@ For more info go to [mailosaur.com](https://mailosaur.com/)
|
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
gem install mailosaur
|
10
|
+
``` gem install mailosaur ```
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
```ruby
|
14
14
|
require 'mailosaur'
|
15
|
-
require "test/unit"
|
16
15
|
|
17
16
|
mailbox = Mailosaur.new(mailbox,apikey)
|
18
17
|
|
19
|
-
emails = mailbox.
|
20
|
-
|
21
|
-
assert_equal('something', emails[0].Subject, 'The subject should be something')
|
18
|
+
emails = mailbox.get_emails_by_recipient('anything.1eaaeef6@mailosaur.in')
|
22
19
|
```
|
20
|
+
|
21
|
+
Optional: Timeout
|
22
|
+
|
23
|
+
- Default timeout is set to 20, if you want to increase or decrease this, set the time in seconds to the `MAILOSAUR_TIMEOUT` variable.
|
24
|
+
|
25
|
+
``` export MAILOSAUR_TIMEOUT=60 ```
|
26
|
+
|
27
|
+
|
23
28
|
##Api
|
24
29
|
|
25
30
|
*functions:*
|
26
31
|
|
27
|
-
-
|
32
|
+
- get_emails - Retrieves all emails
|
33
|
+
|
34
|
+
- get_emails('search_text') - Retrieves all emails with ``` search_text ``` in their body or subject.
|
28
35
|
|
29
|
-
-
|
36
|
+
- get_emails_by_recipient('recipient_email') -
|
30
37
|
Retrieves all emails sent to the given recipient.
|
31
38
|
|
32
|
-
-
|
39
|
+
- get_email('email_id') -
|
33
40
|
Retrieves the email with the given id.
|
34
41
|
|
35
|
-
-
|
42
|
+
- delete_all_emails -
|
36
43
|
Deletes all emails in a mailbox.
|
37
44
|
|
38
|
-
-
|
45
|
+
- delete_email('email_id') -
|
39
46
|
Deletes the email with the given id.
|
40
47
|
|
41
|
-
-
|
48
|
+
- get_attachment('attachment_id') -
|
42
49
|
Retrieves the attachment with specified id.
|
43
50
|
|
44
|
-
-
|
51
|
+
- get_raw_email('raw_id') -
|
45
52
|
Retrieves the complete raw EML file for the rawId given. RawId is a property on the email object.
|
46
53
|
|
47
|
-
-
|
54
|
+
- generate_email_address -
|
48
55
|
Generates a random email address which can be used to send emails into the mailbox.
|
49
56
|
|
50
|
-
*
|
57
|
+
*Email Object Structure*
|
51
58
|
|
52
59
|
- **Email** - The core object returned by the Mailosaur API
|
53
60
|
- **id** - The email identifier
|
data/lib/helper.rb
ADDED
data/lib/mailosaur.rb
CHANGED
@@ -1,100 +1,123 @@
|
|
1
|
-
|
2
|
-
require 'rest_client'
|
3
|
-
require 'json'
|
4
|
-
require 'rest_client'
|
5
|
-
require 'securerandom'
|
6
|
-
require 'date'
|
7
|
-
require "#{File.dirname(__FILE__)}/mailosaur/email"
|
1
|
+
require_relative 'helper.rb'
|
8
2
|
|
9
|
-
# Main class to access Mailosaur.com api.
|
10
3
|
class Mailosaur
|
11
|
-
|
12
|
-
@API_KEY
|
13
|
-
@BASE_URI
|
4
|
+
attr_reader :message
|
14
5
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
21
|
-
@API_KEY = ENV['MAILOSAUR_APIKEY'] || apiKey
|
22
|
-
@BASE_URI = 'https://mailosaur.com/v2'
|
6
|
+
def initialize(mailbox, apiKey, timeout=20)
|
7
|
+
@mailbox = ENV['MAILOSAUR_MAILBOX'] || mailbox
|
8
|
+
@api_key = ENV['MAILOSAUR_APIKEY'] || apiKey
|
9
|
+
@timeout = timeout
|
10
|
+
@base_uri = 'https://mailosaur.com/v2'
|
11
|
+
@message = MessageGenerator.new
|
23
12
|
end
|
24
13
|
|
25
14
|
# Retrieves all emails which have the searchPattern text in their body or subject.
|
26
|
-
def
|
27
|
-
if
|
28
|
-
|
29
|
-
searchCriteria = Hash.new
|
30
|
-
searchCriteria['search'] = search
|
15
|
+
def get_emails(search_criteria = {})
|
16
|
+
if search_criteria.is_a? String
|
17
|
+
search_criteria = {'search' => search_criteria}
|
31
18
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
data
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
return emails
|
41
|
-
end
|
42
|
-
# back off and retry
|
43
|
-
sleep(i*i)
|
19
|
+
search_criteria['key'] = @api_key
|
20
|
+
search_criteria['mailbox'] = @mailbox
|
21
|
+
response = send_get_emails_request(search_criteria)
|
22
|
+
if response.length > 2
|
23
|
+
data = JSON.parse(response.body)
|
24
|
+
data.map { |em| Email.new(em) }
|
25
|
+
else
|
26
|
+
message.no_emails_found(search_criteria)
|
44
27
|
end
|
45
28
|
end
|
46
29
|
|
47
30
|
# Retrieves all emails sent to the given recipient.
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
return getEmails(searchCriteria)
|
31
|
+
def get_emails_by_recipient(recipient_email)
|
32
|
+
search_criteria = {'recipient' => recipient_email}
|
33
|
+
get_emails(search_criteria)
|
52
34
|
end
|
53
35
|
|
54
36
|
# Retrieves the email with the given id.
|
55
|
-
def
|
56
|
-
params
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
email = Email.new(data)
|
61
|
-
return email
|
37
|
+
def get_email(email_id)
|
38
|
+
params = {'key' => @api_key}
|
39
|
+
response = RestClient.get("#{@base_uri}/email/#{email_id}", {:params => params})
|
40
|
+
data = JSON.parse(response.body)
|
41
|
+
Email.new(data)
|
62
42
|
end
|
63
43
|
|
64
|
-
# Deletes all emails in a mailbox.
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
queryParams['mailbox'] = @MAILBOX
|
69
|
-
RestClient.post("#{@BASE_URI}/emails/deleteall", nil, {:params => queryParams})
|
44
|
+
# Deletes all emails in a @mailbox.
|
45
|
+
def delete_all_emails
|
46
|
+
query_params = {'key' => @api_key, '@mailbox' => @mailbox }
|
47
|
+
RestClient.post("#{@base_uri}/emails/deleteall", nil, {:params => query_params})
|
70
48
|
end
|
71
49
|
|
72
50
|
# Deletes the email with the given id.
|
73
|
-
def
|
74
|
-
params =
|
75
|
-
params
|
76
|
-
RestClient.post(@BASE_URI + '/email/' + emailId + '/delete/', nil,{:params => params})
|
51
|
+
def delete_email(email_id)
|
52
|
+
params = {'key' => @api_key}
|
53
|
+
RestClient.post("#{@base_uri}/email/#{email_id}/delete/", nil, {:params => params})
|
77
54
|
end
|
78
55
|
|
79
56
|
# Retrieves the attachment with specified id.
|
80
|
-
def
|
81
|
-
params =
|
82
|
-
params
|
83
|
-
response = RestClient.get(@BASE_URI + '/attachment/' + attachmentId, {:params => params})
|
84
|
-
return response.body
|
57
|
+
def get_attachment(attachment_id)
|
58
|
+
params = {'key' => @api_key}
|
59
|
+
RestClient.get("#{@base_uri}/attachment/#{attachment_id}", {:params => params}).body
|
85
60
|
end
|
86
61
|
|
87
62
|
# Retrieves the complete raw EML file for the rawId given. RawId is a property on the email object.
|
88
|
-
def
|
89
|
-
params =
|
90
|
-
params
|
91
|
-
response = RestClient.get(@BASE_URI + '/raw/' + rawId, {:params => params})
|
92
|
-
return response.body
|
63
|
+
def get_raw_email(raw_id)
|
64
|
+
params = {'key' => @api_key}
|
65
|
+
RestClient.get("#{@base_uri}/raw/#{raw_id}", {:params => params}).body
|
93
66
|
end
|
94
67
|
|
95
|
-
# Generates a random email address which can be used to send emails into the mailbox.
|
96
|
-
def
|
68
|
+
# Generates a random email address which can be used to send emails into the @mailbox.
|
69
|
+
def generate_email_address
|
97
70
|
uuid = SecureRandom.hex(3)
|
98
|
-
|
71
|
+
"%s.%s@mailosaur.in" % [uuid, @mailbox]
|
72
|
+
end
|
73
|
+
|
74
|
+
# old methods
|
75
|
+
def getEmails(search_criteria = {})
|
76
|
+
message.new_syntax('getEmails')
|
77
|
+
get_emails(search_criteria)
|
78
|
+
end
|
79
|
+
def getEmailsByRecipient(recipient_email)
|
80
|
+
message.new_syntax('getEmailsByRecipient')
|
81
|
+
get_emails_by_recipient(recipient_email)
|
82
|
+
end
|
83
|
+
def getEmail(email_id)
|
84
|
+
message.new_syntax('getEmail')
|
85
|
+
get_email(email_id)
|
86
|
+
end
|
87
|
+
def deleteAllEmail
|
88
|
+
message.new_syntax('deleteAllEmail')
|
89
|
+
delete_all_emails
|
90
|
+
end
|
91
|
+
def deleteEmail(email_id)
|
92
|
+
message.new_syntax('deleteEmail')
|
93
|
+
delete_email(email_id)
|
94
|
+
end
|
95
|
+
def getAttachment(attachment_id)
|
96
|
+
message.new_syntax('getAttachment')
|
97
|
+
get_attachment(attachment_id)
|
98
|
+
end
|
99
|
+
def getRawEmail(raw_id)
|
100
|
+
message.new_syntax('getRawEmail')
|
101
|
+
get_raw_email(raw_id)
|
102
|
+
end
|
103
|
+
def generateEmailAddress
|
104
|
+
message.new_syntax('generateEmailAddress')
|
105
|
+
generate_email_address
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def send_get_emails_request(search_criteria)
|
111
|
+
r = ''
|
112
|
+
begin
|
113
|
+
Timeout::timeout(@timeout) {
|
114
|
+
until r.length > 2 && !r.nil?
|
115
|
+
r = RestClient.get("#{@base_uri}/emails", {:params => search_criteria})
|
116
|
+
end
|
117
|
+
r
|
118
|
+
}
|
119
|
+
rescue Timeout::Error
|
120
|
+
''
|
121
|
+
end
|
99
122
|
end
|
100
123
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class MessageGenerator
|
2
|
+
attr_accessor :message
|
3
|
+
|
4
|
+
def no_emails_found(data)
|
5
|
+
"\e[36m No emails were found for #{data} \e[0m\n\e[32m Try checking the params. \e[0m"
|
6
|
+
end
|
7
|
+
|
8
|
+
def new_syntax(method)
|
9
|
+
puts ":::::: Please use new syntax for #{method} ::::::\n
|
10
|
+
\e[36m @mailbox.#{look_ruby(method)}(params) \e[0m"
|
11
|
+
end
|
12
|
+
|
13
|
+
def sleep
|
14
|
+
puts "\e[36m Let's give the email some time to get there... \e[0m"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def look_ruby(method)
|
20
|
+
output = String.new
|
21
|
+
caps = method.scan(/[A-Z]+/).map(&:downcase!)
|
22
|
+
other = method.split(/[A-Z]+/)
|
23
|
+
a3 = other.join('_ ')
|
24
|
+
a4 = a3.split(' ')
|
25
|
+
words = ''
|
26
|
+
other.count.times do |i|
|
27
|
+
words << "#{a4[i]}#{caps[i]}"
|
28
|
+
end
|
29
|
+
words
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailosaur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clickity Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -88,6 +88,7 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- LICENSE
|
90
90
|
- README.md
|
91
|
+
- lib/helper.rb
|
91
92
|
- lib/mailosaur.rb
|
92
93
|
- lib/mailosaur/attachment.rb
|
93
94
|
- lib/mailosaur/email.rb
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- lib/mailosaur/email_data.rb
|
96
97
|
- lib/mailosaur/image.rb
|
97
98
|
- lib/mailosaur/link.rb
|
99
|
+
- lib/mailosaur/message_generator.rb
|
98
100
|
homepage: http://mailosaur.com
|
99
101
|
licenses:
|
100
102
|
- MIT
|