rubymail 0.11
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/.gitignore +64 -0
- data/Gemfile +7 -0
- data/LICENSE +201 -0
- data/README.md +2 -0
- data/Rakefile +1 -0
- data/lib/multimap/.gitignore +4 -0
- data/lib/multimap/LICENSE +20 -0
- data/lib/multimap/README.rdoc +16 -0
- data/lib/multimap/Rakefile +34 -0
- data/lib/multimap/benchmarks/bm_nested_multimap_construction.rb +60 -0
- data/lib/multimap/benchmarks/bm_nested_multimap_lookup.rb +33 -0
- data/lib/multimap/ext/extconf.rb +6 -0
- data/lib/multimap/ext/nested_multimap_ext.c +24 -0
- data/lib/multimap/extras/graphing.rb +83 -0
- data/lib/multimap/lib/multimap.rb +569 -0
- data/lib/multimap/lib/multiset.rb +185 -0
- data/lib/multimap/lib/nested_multimap.rb +158 -0
- data/lib/multimap/spec/enumerable_examples.rb +50 -0
- data/lib/multimap/spec/hash_examples.rb +264 -0
- data/lib/multimap/spec/multimap_spec.rb +45 -0
- data/lib/multimap/spec/multiset_spec.rb +184 -0
- data/lib/multimap/spec/nested_multimap_spec.rb +202 -0
- data/lib/multimap/spec/set_examples.rb +301 -0
- data/lib/multimap/spec/spec_helper.rb +67 -0
- data/lib/rubymail/address.rb +17 -0
- data/lib/rubymail/base.rb +118 -0
- data/lib/rubymail/bounce.rb +31 -0
- data/lib/rubymail/client.rb +87 -0
- data/lib/rubymail/complaint.rb +31 -0
- data/lib/rubymail/domain.rb +34 -0
- data/lib/rubymail/list.rb +37 -0
- data/lib/rubymail/log.rb +19 -0
- data/lib/rubymail/mailbox.rb +41 -0
- data/lib/rubymail/message.rb +16 -0
- data/lib/rubymail/route.rb +99 -0
- data/lib/rubymail/rubymail_error.rb +53 -0
- data/lib/rubymail/secure.rb +19 -0
- data/lib/rubymail/unsubscribe.rb +31 -0
- data/lib/rubymail/webhook.rb +43 -0
- data/lib/rubymail.rb +31 -0
- data/rubymail.gemspec +18 -0
- data/spec/address_spec.rb +27 -0
- data/spec/base_spec.rb +132 -0
- data/spec/bounce_spec.rb +66 -0
- data/spec/client_spec.rb +118 -0
- data/spec/complaint_spec.rb +103 -0
- data/spec/domain_spec.rb +80 -0
- data/spec/helpers/rubymail_helper.rb +9 -0
- data/spec/list/member_spec.rb +82 -0
- data/spec/list/message_spec.rb +40 -0
- data/spec/list_spec.rb +70 -0
- data/spec/log_spec.rb +27 -0
- data/spec/mailbox_spec.rb +63 -0
- data/spec/route_spec.rb +100 -0
- data/spec/secure_spec.rb +54 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/unsubscribe_spec.rb +82 -0
- data/spec/webhook_spec.rb +115 -0
- metadata +159 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rubymail
|
2
|
+
class Unsubscribe
|
3
|
+
def initialize(rubymail, domain)
|
4
|
+
@rubymail = rubymail
|
5
|
+
@domain = domain
|
6
|
+
end
|
7
|
+
|
8
|
+
def list(options={})
|
9
|
+
Rubymail.submit(:get, unsubscribe_url, options)["items"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(email)
|
13
|
+
Rubymail.submit :get, unsubscribe_url(email)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(email, tag='*')
|
17
|
+
Rubymail.submit :post, unsubscribe_url, {:address => email, :tag => tag}
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(email)
|
21
|
+
Rubymail.submit :delete, unsubscribe_url(email)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def unsubscribe_url(address=nil)
|
27
|
+
"#{@rubymail.base_url}/#{@domain}/unsubscribes#{'/' + address if address}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rubymail
|
2
|
+
class Webhook
|
3
|
+
attr_accessor :default_webhook_url, :domain
|
4
|
+
|
5
|
+
def initialize(rubymail, domain, url)
|
6
|
+
@rubymail = rubymail
|
7
|
+
@domain = domain
|
8
|
+
@default_webhook_url = url
|
9
|
+
end
|
10
|
+
|
11
|
+
def available_ids
|
12
|
+
%w(bounce deliver drop spam unsubscribe click open).map(&:to_sym)
|
13
|
+
end
|
14
|
+
|
15
|
+
def list
|
16
|
+
Rubymail.submit(:get, webhook_url)["webhooks"] || []
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(id)
|
20
|
+
Rubymail.submit :get, webhook_url(id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create(id, url=default_webhook_url)
|
24
|
+
params = {:id => id, :url => url}
|
25
|
+
Rubymail.submit :post, webhook_url, params
|
26
|
+
end
|
27
|
+
|
28
|
+
def update(id, url=default_webhook_url)
|
29
|
+
params = {:url => url}
|
30
|
+
Rubymail.submit :put, webhook_url(id), params
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(id)
|
34
|
+
Rubymail.submit :delete, webhook_url(id)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def webhook_url(id=nil)
|
40
|
+
"#{@rubymail.base_url}/domains/#{domain}/webhooks#{'/' + id if id}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/rubymail.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "json"
|
2
|
+
require "multimap/lib/multimap"
|
3
|
+
require "multimap/lib/multiset"
|
4
|
+
require "multimap/lib/nested_multimap"
|
5
|
+
|
6
|
+
require "rubymail/rubymail_error"
|
7
|
+
require "rubymail/base"
|
8
|
+
require "rubymail/domain"
|
9
|
+
require "rubymail/route"
|
10
|
+
require "rubymail/mailbox"
|
11
|
+
require "rubymail/bounce"
|
12
|
+
require "rubymail/unsubscribe"
|
13
|
+
require "rubymail/webhook"
|
14
|
+
require "rubymail/complaint"
|
15
|
+
require "rubymail/log"
|
16
|
+
require "rubymail/list"
|
17
|
+
require "rubymail/list/member"
|
18
|
+
require "rubymail/message"
|
19
|
+
require "rubymail/secure"
|
20
|
+
require "rubymail/address"
|
21
|
+
require "rubymail/client"
|
22
|
+
|
23
|
+
#require "startup"
|
24
|
+
|
25
|
+
def Rubymail(options={})
|
26
|
+
options[:api_key] = Rubymail.api_key if Rubymail.api_key
|
27
|
+
options[:domain] = Rubymail.domain if Rubymail.domain
|
28
|
+
options[:webhook_url] = Rubymail.webhook_url if Rubymail.webhook_url
|
29
|
+
options[:public_api_key] = Rubymail.public_api_key if Rubymail.public_api_key
|
30
|
+
Rubymail::Base.new(options)
|
31
|
+
end
|
data/rubymail.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.authors = ["Krishpranav"]
|
3
|
+
gem.email = ["krisna.pranav@gmail.com"]
|
4
|
+
gem.description = %q{ruby mail framework}
|
5
|
+
gem.summary = %q{ruby mail framework}
|
6
|
+
gem.homepage = "http://github.com/krishpranav/rubymail"
|
7
|
+
|
8
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
9
|
+
gem.files = `git ls-files`.split("\n")
|
10
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
11
|
+
gem.name = "rubymail"
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
gem.version = "0.11"
|
14
|
+
|
15
|
+
gem.add_development_dependency(%q<rspec>, [">= 2"])
|
16
|
+
gem.add_development_dependency(%q<pry>, [">= 0"])
|
17
|
+
gem.add_development_dependency(%q<webmock>, [">= 2"])
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubymail::Address do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@sample = "foo@rubymail.net"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "validate an address" do
|
10
|
+
it "should require a public api key" do
|
11
|
+
rubymail = Rubymail({:api_key => "api-key"})
|
12
|
+
expect { rubymail.addresses }.to raise_error(ArgumentError, ":public_api_key is a required argument to validate addresses")
|
13
|
+
end
|
14
|
+
it "should make a GET request with correct params to find a given webhook" do
|
15
|
+
rubymail = Rubymail({:api_key => "api-key", :public_api_key => "public-api-key"})
|
16
|
+
|
17
|
+
sample_response = "{\"is_valid\":true,\"address\":\"foo@rubymail.net\",\"parts\":{\"display_name\":null,\"local_part\":\"foo\",\"domain\":\"rubymail.net\"},\"did_you_mean\":null}"
|
18
|
+
validate_url = rubymail.addresses.send(:address_url, 'validate')
|
19
|
+
|
20
|
+
expect(Rubymail).to receive(:submit).
|
21
|
+
with(:get, validate_url, {:address => @sample}).
|
22
|
+
and_return(sample_response)
|
23
|
+
|
24
|
+
rubymail.addresses.validate(@sample)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubymail::Base do
|
4
|
+
|
5
|
+
it "should raise an error if the api_key has not been set" do
|
6
|
+
Rubymail.config { |c| c.api_key = nil }
|
7
|
+
expect do
|
8
|
+
Rubymail()
|
9
|
+
end.to raise_error ArgumentError
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can be called directly if the api_key has been set via Rubymail.configure" do
|
13
|
+
Rubymail.config { |c| c.api_key = "some-junk-string" }
|
14
|
+
expect do
|
15
|
+
Rubymail()
|
16
|
+
end.not_to raise_error()
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can be instanced with the api_key as a param" do
|
20
|
+
expect do
|
21
|
+
Rubymail({:api_key => "some-junk-string"})
|
22
|
+
end.not_to raise_error()
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Rubymail.new" do
|
26
|
+
it "Rubymail() method should return a new Rubymail object" do
|
27
|
+
rubymail = Rubymail({:api_key => "some-junk-string"})
|
28
|
+
expect(rubymail).to be_kind_of(Rubymail::Base)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "resources" do
|
33
|
+
before :each do
|
34
|
+
@rubymail = Rubymail({:api_key => "some-junk-string"})
|
35
|
+
end
|
36
|
+
|
37
|
+
it "Rubymail#mailboxes should return an instance of Rubymail::Mailbox" do
|
38
|
+
expect(@rubymail.mailboxes).to be_kind_of(Rubymail::Mailbox)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "Rubymail#routes should return an instance of Rubymail::Route" do
|
42
|
+
expect(@rubymail.routes).to be_kind_of(Rubymail::Route)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "internal helper methods" do
|
47
|
+
before :each do
|
48
|
+
@rubymail = Rubymail({:api_key => "some-junk-string"})
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Rubymail#base_url" do
|
52
|
+
it "should return https url if use_https is true" do
|
53
|
+
expect(@rubymail.base_url).to eq "https://api:#{Rubymail.api_key}@#{Rubymail.rubymail_host}/#{Rubymail.api_version}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "Rubymail.submit" do
|
58
|
+
let(:client_double) { double(Rubymail::Client) }
|
59
|
+
|
60
|
+
it "should send method and arguments to Rubymail::Client" do
|
61
|
+
expect(Rubymail::Client).to receive(:new)
|
62
|
+
.with('/')
|
63
|
+
.and_return(client_double)
|
64
|
+
expect(client_double).to receive(:test_method)
|
65
|
+
.with({:arg1=>"val1"})
|
66
|
+
.and_return('{}')
|
67
|
+
|
68
|
+
Rubymail.submit :test_method, '/', :arg1=>"val1"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "configuration" do
|
74
|
+
describe "default settings" do
|
75
|
+
it "api_version is v3" do
|
76
|
+
expect(Rubymail.api_version).to eql 'v3'
|
77
|
+
end
|
78
|
+
it "should use https by default" do
|
79
|
+
expect(Rubymail.protocol).to eq "https"
|
80
|
+
end
|
81
|
+
it "rubymail_host is 'api.rubymail.net'" do
|
82
|
+
expect(Rubymail.rubymail_host).to eql 'api.rubymail.net'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "test_mode is false" do
|
86
|
+
expect(Rubymail.test_mode).to eql false
|
87
|
+
end
|
88
|
+
|
89
|
+
it "domain is not set" do
|
90
|
+
expect(Rubymail.domain).to be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "setting configurations" do
|
95
|
+
before(:each) do
|
96
|
+
Rubymail.configure do |c|
|
97
|
+
c.api_key = 'some-api-key'
|
98
|
+
c.api_version = 'v2'
|
99
|
+
c.protocol = 'https'
|
100
|
+
c.rubymail_host = 'api.rubymail.net'
|
101
|
+
c.test_mode = false
|
102
|
+
c.domain = 'some-domain'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
after(:each) { Rubymail.configure { |c| c.domain = nil } }
|
107
|
+
|
108
|
+
it "allows me to set my API key easily" do
|
109
|
+
expect(Rubymail.api_key).to eql 'some-api-key'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "allows me to set the api_version attribute" do
|
113
|
+
expect(Rubymail.api_version).to eql 'v2'
|
114
|
+
end
|
115
|
+
|
116
|
+
it "allows me to set the protocol attribute" do
|
117
|
+
expect(Rubymail.protocol).to eql 'https'
|
118
|
+
end
|
119
|
+
|
120
|
+
it "allows me to set the rubymail_host attribute" do
|
121
|
+
expect(Rubymail.rubymail_host).to eql 'api.rubymail.net'
|
122
|
+
end
|
123
|
+
it "allows me to set the test_mode attribute" do
|
124
|
+
expect(Rubymail.test_mode).to eql false
|
125
|
+
end
|
126
|
+
|
127
|
+
it "allows me to set my domain easily" do
|
128
|
+
expect(Rubymail.domain).to eql 'some-domain'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/spec/bounce_spec.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubymail::Bounce do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@rubymail = Rubymail({:api_key => "api-key"})
|
7
|
+
|
8
|
+
@sample = {
|
9
|
+
:email => "test@sample.rubymail.org",
|
10
|
+
:name => "test",
|
11
|
+
:domain => "sample.rubymail.org"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "list bounces" do
|
16
|
+
it "should make a GET request with the right params" do
|
17
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.rubymail.org\" } ]}"
|
18
|
+
bounces_url = @rubymail.bounces(@sample[:domain]).send(:bounce_url)
|
19
|
+
|
20
|
+
expect(Rubymail).to receive(:submit).
|
21
|
+
with(:get, bounces_url, {}).
|
22
|
+
and_return(sample_response)
|
23
|
+
|
24
|
+
@rubymail.bounces(@sample[:domain]).list
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "find bounces" do
|
29
|
+
it "should make a GET request with correct params to find given email address" do
|
30
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.rubymail.org\" } ]}"
|
31
|
+
bounces_url = @rubymail.bounces(@sample[:domain]).send(:bounce_url, @sample[:email])
|
32
|
+
|
33
|
+
expect(Rubymail).to receive(:submit).
|
34
|
+
with(:get, bounces_url).
|
35
|
+
and_return(sample_response)
|
36
|
+
|
37
|
+
@rubymail.bounces(@sample[:domain]).find(@sample[:email])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "add bounces" do
|
42
|
+
it "should make a POST request with correct params to add a given email address" do
|
43
|
+
sample_response = "{\"items\": [{\"size_bytes\": 0, \"mailbox\": \"postmaster@bsample.rubymail.org\" } ]}"
|
44
|
+
bounces_url = @rubymail.bounces(@sample[:domain]).send(:bounce_url)
|
45
|
+
|
46
|
+
expect(Rubymail).to receive(:submit).
|
47
|
+
with(:post, bounces_url, {:address => @sample[:email]} ).
|
48
|
+
and_return(sample_response)
|
49
|
+
|
50
|
+
@rubymail.bounces(@sample[:domain]).add(@sample[:email])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "destroy bounces" do
|
55
|
+
it "should make DELETE request with correct params to remove a given email address" do
|
56
|
+
sample_response = "{\"message\"=>\"Bounced address has been removed\", \"address\"=>\"postmaster@bsample.rubymail.org\"}"
|
57
|
+
bounces_url = @rubymail.bounces(@sample[:domain]).send(:bounce_url, @sample[:email])
|
58
|
+
|
59
|
+
expect(Rubymail).to receive(:submit).
|
60
|
+
with(:delete, bounces_url).
|
61
|
+
and_return(sample_response)
|
62
|
+
|
63
|
+
@rubymail.bounces(@sample[:domain]).destroy(@sample[:email])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
describe Rubymail::Client do
|
6
|
+
subject { described_class.new(url) }
|
7
|
+
|
8
|
+
describe '#get' do
|
9
|
+
context 'without query params' do
|
10
|
+
let(:url) { 'https://api:key@api.rubymail.net/v3/routes' }
|
11
|
+
|
12
|
+
it 'sends a GET request to the given path' do
|
13
|
+
stub = stub_request(:get, 'https://api.rubymail.net/v3/routes')
|
14
|
+
.with(basic_auth: ['api', 'key'])
|
15
|
+
|
16
|
+
subject.get
|
17
|
+
|
18
|
+
expect(stub).to have_been_requested
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with query params' do
|
23
|
+
let(:url) { 'https://api:key@api.rubymail.net/v3/routes' }
|
24
|
+
|
25
|
+
it 'sends a GET request to the given path with the params' do
|
26
|
+
stub = stub_request(:get, 'https://api.rubymail.net/v3/routes?limit=10')
|
27
|
+
.with(basic_auth: ['api', 'key'])
|
28
|
+
|
29
|
+
subject.get(limit: 10)
|
30
|
+
|
31
|
+
expect(stub).to have_been_requested
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when an error happens' do
|
36
|
+
let(:url) { 'https://api:key@api.rubymail.net/v3/routes/123' }
|
37
|
+
let(:error_body) { { "message" => "Expression is missing" }.to_json }
|
38
|
+
|
39
|
+
before do
|
40
|
+
stub_request(:get, 'https://api.rubymail.net/v3/routes/123')
|
41
|
+
.with(basic_auth: ['api', 'key'])
|
42
|
+
.to_return(status: [400, "Bad Request"],
|
43
|
+
body: error_body)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'raises exception that contains the error code and body' do
|
47
|
+
begin
|
48
|
+
subject.get
|
49
|
+
rescue => e
|
50
|
+
@exception = e
|
51
|
+
end
|
52
|
+
|
53
|
+
expect(@exception.http_code).to eq(400)
|
54
|
+
expect(@exception.http_body).to eq(error_body)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#post' do
|
60
|
+
let(:url) { 'https://api:key@api.rubymail.net/v3/routes' }
|
61
|
+
let(:params) { { action: ['forward', 'stop'], description: 'yolo' } }
|
62
|
+
let(:response) do
|
63
|
+
{
|
64
|
+
"message" => "Route has been created",
|
65
|
+
"route" => {
|
66
|
+
"actions" => [
|
67
|
+
"forward(\"stefan@metrilo.com\")",
|
68
|
+
"stop()"
|
69
|
+
],
|
70
|
+
"created_at" => "Wed, 15 Jun 2016 07:10:09 GMT",
|
71
|
+
"description" => "Sample route",
|
72
|
+
"expression" => "match_recipient(\".*@metrilo.com\")",
|
73
|
+
"id" => "5760ff5163badc3a756f9d2c",
|
74
|
+
"priority" => 5
|
75
|
+
}
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
before do
|
80
|
+
stub_request(:post, 'https://api.rubymail.net/v3/routes')
|
81
|
+
.with(basic_auth: ['api', 'key'],
|
82
|
+
body: 'action=forward&action=stop&description=yolo')
|
83
|
+
.to_return(body: response.to_json)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'sends a POST request with the params form-encoded' do
|
87
|
+
expect(subject.post(params)).to eq(response.to_json)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#put' do
|
92
|
+
let(:url) { 'https://api:key@api.rubymail.net/v3/routes/123' }
|
93
|
+
|
94
|
+
it 'sends a PUT request with the params form-encoded' do
|
95
|
+
stub = stub_request(:put, 'https://api.rubymail.net/v3/routes/123')
|
96
|
+
.with(basic_auth: ['api', 'key'],
|
97
|
+
body: 'action=forward&action=stop&description=yolo')
|
98
|
+
|
99
|
+
subject.put(action: ['forward', 'stop'],
|
100
|
+
description: 'yolo')
|
101
|
+
|
102
|
+
expect(stub).to have_been_requested
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#delete' do
|
107
|
+
let(:url) { 'https://api:key@api.rubymail.net/v3/routes/123' }
|
108
|
+
|
109
|
+
it 'sends a DELETE request with the params form-encoded' do
|
110
|
+
stub = stub_request(:delete, 'https://api.rubymail.net/v3/routes/123')
|
111
|
+
.with(basic_auth: ['api', 'key'])
|
112
|
+
|
113
|
+
subject.delete
|
114
|
+
|
115
|
+
expect(stub).to have_been_requested
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubymail::Complaint do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@rubymail = Rubymail({:api_key => "api-key"})
|
7
|
+
|
8
|
+
@sample = {
|
9
|
+
:email => "test@sample.rubymail.org",
|
10
|
+
:name => "test",
|
11
|
+
:domain => "sample.rubymail.org"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "list complaints" do
|
16
|
+
it "should make a GET request with the right params" do
|
17
|
+
sample_response = <<EOF
|
18
|
+
{
|
19
|
+
"total_count": 1,
|
20
|
+
"items": [
|
21
|
+
{
|
22
|
+
"count": 2,
|
23
|
+
"created_at": "Tue, 15 Nov 2011 08:25:11 GMT",
|
24
|
+
"address": "romanto@profista.com"
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
28
|
+
EOF
|
29
|
+
|
30
|
+
complaints_url = @rubymail.complaints(@sample[:domain]).send(:complaint_url)
|
31
|
+
|
32
|
+
expect(Rubymail).to receive(:submit).
|
33
|
+
with(:get, complaints_url, {}).
|
34
|
+
and_return(sample_response)
|
35
|
+
|
36
|
+
@rubymail.complaints(@sample[:domain]).list
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe "add complaint" do
|
42
|
+
it "should make a POST request with correct params to add a given email address to complaint from a tag" do
|
43
|
+
sample_response = <<EOF
|
44
|
+
{
|
45
|
+
"message": "Address has been added to the complaints table",
|
46
|
+
"address": "#{@sample[:email]}"
|
47
|
+
}
|
48
|
+
EOF
|
49
|
+
|
50
|
+
complaints_url = @rubymail.complaints(@sample[:domain]).send(:complaint_url)
|
51
|
+
|
52
|
+
expect(Rubymail).to receive(:submit)
|
53
|
+
.with(:post, complaints_url, {:address => @sample[:email]})
|
54
|
+
.and_return(sample_response)
|
55
|
+
|
56
|
+
@rubymail.complaints(@sample[:domain]).add(@sample[:email])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
describe "find complaint" do
|
62
|
+
it "should make a GET request with the right params to find given email address" do
|
63
|
+
sample_response = <<EOF
|
64
|
+
{
|
65
|
+
"complaint": {
|
66
|
+
"count": 2,
|
67
|
+
"created_at": "Tue, 15 Nov 2011 08:25:11 GMT",
|
68
|
+
"address": "romanto@profista.com"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
EOF
|
72
|
+
|
73
|
+
complaints_url = @rubymail.complaints(@sample[:domain]).send(:complaint_url, @sample[:email])
|
74
|
+
|
75
|
+
expect(Rubymail).to receive(:submit)
|
76
|
+
.with(:get, complaints_url)
|
77
|
+
.and_return(sample_response)
|
78
|
+
|
79
|
+
@rubymail.complaints(@sample[:domain]).find(@sample[:email])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
describe "delete complaint" do
|
85
|
+
it "should make a DELETE request with correct params to remove a given email address" do
|
86
|
+
sample_response = <<EOF
|
87
|
+
{
|
88
|
+
"message": "Complaint event has been removed",
|
89
|
+
"address": "#{@sample[:email]}"}"
|
90
|
+
}
|
91
|
+
EOF
|
92
|
+
|
93
|
+
complaints_url = @rubymail.complaints(@sample[:domain]).send(:complaint_url, @sample[:email])
|
94
|
+
|
95
|
+
expect(Rubymail).to receive(:submit)
|
96
|
+
.with(:delete, complaints_url)
|
97
|
+
.and_return(sample_response)
|
98
|
+
|
99
|
+
@rubymail.complaints(@sample[:domain]).destroy(@sample[:email])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/spec/domain_spec.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubymail::Domain do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@rubymail = Rubymail({:api_key => "api-key"})
|
7
|
+
|
8
|
+
@sample = {
|
9
|
+
:email => "test@sample.rubymail.org",
|
10
|
+
:name => "test",
|
11
|
+
:domain => "sample.rubymail.org"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "list domains" do
|
16
|
+
it "should make a GET request with the right params" do
|
17
|
+
|
18
|
+
sample_response = "{\"total_count\": 1, \"items\": [{\"created_at\": \"Tue, 12 Feb 2013 20:13:49 GMT\", \"smtp_login\": \"postmaster@sample.rubymail.org\", \"name\": \"sample.rubymail.org\", \"smtp_password\": \"67bw67bz7w\" }]}"
|
19
|
+
domains_url = @rubymail.domains.send(:domain_url)
|
20
|
+
|
21
|
+
expect(Rubymail).to receive(:submit).
|
22
|
+
with(:get, domains_url, {}).
|
23
|
+
and_return(sample_response)
|
24
|
+
|
25
|
+
@rubymail.domains.list
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "find domains" do
|
30
|
+
it "should make a GET request with correct params to find given domain" do
|
31
|
+
sample_response = "{\"domain\": {\"created_at\": \"Tue, 12 Feb 2013 20:13:49 GMT\", \"smtp_login\": \"postmaster@bample.rubymail.org\", \"name\": \"sample.rubymail.org\", \"smtp_password\": \"67bw67bz7w\" }, \"receiving_dns_records\": [], \"sending_dns_records\": []}"
|
32
|
+
domains_url = @rubymail.domains.send(:domain_url, @sample[:domain])
|
33
|
+
|
34
|
+
expect(Rubymail).to receive(:submit).
|
35
|
+
with(:get, domains_url).
|
36
|
+
and_return(sample_response)
|
37
|
+
|
38
|
+
@rubymail.domains.find(@sample[:domain])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "add domains" do
|
43
|
+
it "should make a POST request with correct params to add a domain" do
|
44
|
+
sample_response = "{\"domain\": {\"created_at\": \"Tue, 12 Feb 2013 20:13:49 GMT\", \"smtp_login\": \"postmaster@sample.rubymail.org\",\"name\": \"sample.rubymail.org\",\"smtp_password\": \"67bw67bz7w\"}, \"message\": \"Domain has been created\"}"
|
45
|
+
domains_url = @rubymail.domains.send(:domain_url)
|
46
|
+
|
47
|
+
expect(Rubymail).to receive(:submit).
|
48
|
+
with(:post, domains_url, {:name => @sample[:domain]} ).
|
49
|
+
and_return(sample_response)
|
50
|
+
|
51
|
+
@rubymail.domains.create(@sample[:domain])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "delete domain" do
|
56
|
+
it "should make a DELETE request with correct params" do
|
57
|
+
sample_response = "{\"message\": \"Domain has been deleted\"}"
|
58
|
+
domains_url = @rubymail.domains.send(:domain_url, @sample[:domain])
|
59
|
+
|
60
|
+
expect(Rubymail).to receive(:submit).
|
61
|
+
with(:delete, domains_url).
|
62
|
+
and_return(sample_response)
|
63
|
+
|
64
|
+
@rubymail.domains.delete(@sample[:domain])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'verify domain' do
|
69
|
+
it 'should make a PUT request to verify with correct params' do
|
70
|
+
sample_response = "{\"domain\": {\"created_at\": \"Tue, 12 Feb 2013 20:13:49 GMT\", \"smtp_login\": \"postmaster@bample.rubymail.org\", \"name\": \"sample.rubymail.org\", \"smtp_password\": \"67bw67bz7w\", \"state\": \"active\"}, \"message\": \"Domain DNS records have been updated\", \"receiving_dns_records\": [], \"sending_dns_records\": []}"
|
71
|
+
verify_domain_url = "#{@rubymail.domains.send(:domain_url, @sample[:domain])}/verify"
|
72
|
+
|
73
|
+
expect(Rubymail).to receive(:submit)
|
74
|
+
.with(:put, verify_domain_url)
|
75
|
+
.and_return(sample_response)
|
76
|
+
|
77
|
+
@rubymail.domains.verify(@sample[:domain])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module RubymailHelper
|
2
|
+
def generate_request_auth(api_key, offset=0)
|
3
|
+
timestamp = Time.now.to_i + offset * 60
|
4
|
+
token = ([nil]*50).map { ((48..57).to_a+(65..90).to_a+(97..122).to_a).sample.chr }.join
|
5
|
+
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), api_key, '%s%s' % [timestamp, token])
|
6
|
+
|
7
|
+
return timestamp, token, signature
|
8
|
+
end
|
9
|
+
end
|