mailinator-fix 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27aa45fb157a2b07788ce3b33a4ee1b2c4ef0ef5
4
+ data.tar.gz: f3c672a2595f20f914d69407699cf5eecd3294e5
5
+ SHA512:
6
+ metadata.gz: bfe05dfe18002cad74e3949dad89b20b1f7b848ed05580426f16dce0a6f8670a884c44301c417b1653dedae6bbb9ecc998f6ff167accaaf5bed35bd91d83119e
7
+ data.tar.gz: c56c8c7459da05b6082bb7b33334464cc96e7f1172a3119d3c1ce54363b926a82d408656aebcfcbc4d26365f420955c614032b70702f8d5a61957770e8cca42f
@@ -0,0 +1,15 @@
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
15
+ .ruby-version
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.1.1
7
+ - 2.1.2
8
+ - 2.1.3
9
+ - 2.1.4
10
+ - 2.1.5
11
+ - 2.2.0
12
+ bundler_args: --without debug
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mailinator.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rubocop', '~> 0.28'
8
+ gem 'rspec', '~> 3.1'
9
+ gem 'guard', '~> 2.10'
10
+ gem 'guard-rspec', '~> 4.5'
11
+ gem 'fakeweb', '~> 1.3'
12
+ end
13
+
14
+ group :debug do
15
+ gem 'pry', '~> 0.10'
16
+ gem 'pry-byebug', '~> 2.0'
17
+ end
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: 'bundle exec rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { 'spec' }
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alejandro Dev.
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.
@@ -0,0 +1,103 @@
1
+ [![Build Status](https://travis-ci.org/ainformatico/mailinator.svg)](https://travis-ci.org/ainformatico/mailinator)
2
+ [![Code Climate](https://codeclimate.com/github/ainformatico/mailinator/badges/gpa.svg)](https://codeclimate.com/github/ainformatico/mailinator)
3
+
4
+ # Mailinator
5
+
6
+ Mailinator REST API wrapper, http://mailinator.com/apidocs.jsp
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'mailinator'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install mailinator
23
+
24
+ ## Usage
25
+
26
+ ### Configuration
27
+
28
+ ```ruby
29
+ Mailinator.configure do |config|
30
+ config.token = 'YOURTOKEN'
31
+ end
32
+ ```
33
+
34
+ ### Email
35
+
36
+ Access to an email
37
+
38
+ ```ruby
39
+ email = Mailinator::Email.get('email-abcd1234')
40
+ ```
41
+
42
+ Now you have access to some methods:
43
+
44
+ * `email.id`
45
+ * `email.subject`
46
+ * `email.body`
47
+ * `email.body_html`
48
+ * `email.read?`
49
+ * `email.inbox_fetches_left`
50
+ * `email.email_fetches_left`
51
+ * `email.sender`
52
+ * `email.reply_to`
53
+ * `email.from`
54
+ * `email.ip`
55
+ * `email.received`
56
+ * `email.date`
57
+ * `email.time`
58
+ * `email.forwards_left`
59
+ * `email.original`, original request
60
+
61
+ ### Inbox
62
+
63
+ Access to an inbox
64
+
65
+ ```ruby
66
+ inbox = Mailinator::Inbox.get('inbox-abcd1234')
67
+ ```
68
+
69
+ This returns a list of the emails for the given _inbox_, but not the emails themselves.
70
+ To download an `Email` you need:
71
+
72
+ ```ruby
73
+ email = inbox.messages.first.download
74
+ ```
75
+
76
+ or
77
+
78
+ ```ruby
79
+ inbox.messages.first.download do |email|
80
+ [...]
81
+ end
82
+ ```
83
+
84
+ ## Contributing
85
+
86
+ 1. Fork it ( https://github.com/ainformatico/mailinator/fork )
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create a new Pull Request
91
+
92
+
93
+ ## License
94
+
95
+ Copyright (c) 2014 Alejandro Dev.
96
+
97
+ MIT License
98
+
99
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
102
+
103
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ['--color', '--format', 'documentation']
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ require 'mailinator/model'
2
+ require 'mailinator/models/email'
3
+ require 'mailinator/models/entry'
4
+ require 'mailinator/models/inbox'
5
+ require 'mailinator/api'
6
+ require 'mailinator/email'
7
+ require 'mailinator/inbox'
8
+ require 'mailinator/config'
9
+ require 'mailinator/version'
10
+
11
+ module Mailinator
12
+ class << self
13
+ attr_writer :config
14
+
15
+ def configure
16
+ yield(config)
17
+ end
18
+
19
+ def config
20
+ @config ||= Config.new
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,56 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module Mailinator
5
+
6
+ class Api
7
+ class NotFound < StandardError; end
8
+ class RequestError < StandardError; end
9
+
10
+ def get(url, params = {})
11
+ response = request(url, params)
12
+ handle_response(response)
13
+ end
14
+
15
+ def token
16
+ Mailinator.config.token
17
+ end
18
+
19
+ private
20
+
21
+ def request(url, params)
22
+ uri = generate_url(url)
23
+ uri.query = generate_params(params)
24
+ perform_request(uri)
25
+ end
26
+
27
+ def perform_request(uri)
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ http.use_ssl = (uri.scheme == 'https')
30
+ http.get(uri.request_uri)
31
+ end
32
+
33
+ def generate_url(url)
34
+ URI("#{base_url}/#{url}")
35
+ end
36
+
37
+ def generate_params(params)
38
+ URI.encode_www_form(params.merge({token: token}))
39
+ end
40
+
41
+ def base_url
42
+ 'https://api.mailinator.com/api'
43
+ end
44
+
45
+ def handle_response(response)
46
+ case response.code.to_i
47
+ when 200
48
+ JSON.parse(response.body)
49
+ when 404
50
+ fail NotFound
51
+ else
52
+ fail RequestError, {status: response.message, code: response.code}
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ module Mailinator
2
+ class TokenError < StandardError; end
3
+
4
+ class Config
5
+ attr_accessor :token
6
+
7
+ def token
8
+ fail TokenError, 'Please provide a token' if @token.nil?
9
+ @token
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Mailinator
2
+ class Email
3
+ class << self
4
+ def get(id)
5
+ api = Api.new
6
+ data = api.get('email', msgid: id)
7
+ populate(data)
8
+ end
9
+
10
+ private
11
+
12
+ def populate(data)
13
+ Mailinator::Models::Email.new(data)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Mailinator
2
+ class Inbox
3
+ class << self
4
+ def get(to)
5
+ api = Api.new
6
+ data = api.get('inbox', to: to)
7
+ populate(data)
8
+ end
9
+
10
+ private
11
+
12
+ def populate(data)
13
+ Mailinator::Models::Inbox.new(data)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require 'hashie'
2
+
3
+ module Mailinator
4
+ module Models
5
+ class Base < Hashie::Mash
6
+ def initialize(data)
7
+ @data = data
8
+ super(transform_data)
9
+ end
10
+
11
+ def original
12
+ @data
13
+ end
14
+
15
+ def transform_data
16
+ @data
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ require 'date'
2
+
3
+ module Mailinator
4
+ module Models
5
+ class Email < Base
6
+ def transform_data
7
+ {
8
+ id: @data['data']['id'],
9
+ subject: @data['data']['subject'],
10
+ body: @data['data']['parts'].first['body'],
11
+ body_html: retrieve_body_html,
12
+ inbox_fetches_left: @data['apiInboxFetchesLeft'],
13
+ email_fetches_left: @data['apiEmailFetchesLeft'],
14
+ forwards_left: @data['forwardsLeft'],
15
+ sender: @data['data']['headers']['sender'],
16
+ from: @data['data']['from'],
17
+ date: DateTime.parse(@data['data']['headers']['date']),
18
+ time: @data['data']['time'],
19
+ ip: @data['data']['ip'],
20
+ to: @data['data']['headers']['to'],
21
+ reply_to: @data['data']['headers']['reply-to'],
22
+ received: @data['data']['headers']['received'],
23
+ read?: @data['data']['been_read']
24
+ }
25
+ end
26
+
27
+ private
28
+
29
+ def retrieve_body_html
30
+ html = @data['data']['parts'][1] || {}
31
+ html['body']
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ module Mailinator
2
+ module Models
3
+ class Entry < Base
4
+ def download
5
+ email = Mailinator::Email.get(id)
6
+ if block_given?
7
+ yield email
8
+ else
9
+ email
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Mailinator
2
+ module Models
3
+ class Inbox < Base
4
+ def transform_data
5
+ {
6
+ messages: @data['messages'].map { |entry| Entry.new(entry) }
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Mailinator
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailinator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mailinator-fix'
8
+ spec.version = Mailinator::VERSION
9
+ spec.authors = ['Patrick']
10
+ spec.email = ['patrickzhang@live.ca']
11
+ spec.summary = %q{Mailinator REST API wrapper}
12
+ spec.homepage = 'https://github.com/ainformatico/mailinator'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'hashie', '~> 3.3'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.6'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
@@ -0,0 +1,5 @@
1
+ HTTP/1.1 200 OK
2
+ Server: Apache-Coyote/1.1
3
+ Date: Sun, 28 Dec 2014 13:39:51 GMT
4
+
5
+ {"apiInboxFetchesLeft":696,"apiEmailFetchesLeft":10,"data":{"headers":{"sender":"example@example.net","content-type":"multipart\/alternative;\r\n\tboundary=\"MIMEBoundaryec1dc8828d9bbedf095f9e9d2ebdbdeb\"","to":"recipient@mailinator.com","x-connecting-ip":"127.0.0.1","subject":"This is a subject","mime-version":"1.0","x-received-time":"1419696967076","reply-to":"example@example.net","received":"from 127-0-0-1.dynamic-ip.example.net ()\r\n by mail.mailinator.com with SMTP (Postfix)\r\n for recipient@mailinator.com;\r\n Sat, 27 Dec 2014 16:16:07 +0000 (UTC)","from":"\"Sender\" <example@example.net>","date":"Sun, 28 Dec 2014 00:16:00 +0800"},"seconds_ago":77024,"id":"1419696967-44152505-recipient","to":"recipient@mailinator.com","time":1419696967076,"subject":"This is a subject","fromfull":"example@example.net","parts":[{"headers":{"content-type":"text\/plain;\r\n\tcharset=\"iso-8859-1\"","content-transfer-encoding":"quoted-printable"},"body":"This is a body"}],"been_read":false,"from":"Sender","ip":"127.0.0.1"},"forwardsLeft":10}
@@ -0,0 +1,5 @@
1
+ HTTP/1.1 200 OK
2
+ Server: Apache-Coyote/1.1
3
+ Date: Sun, 28 Dec 2014 13:39:51 GMT
4
+
5
+ {"apiInboxFetchesLeft":696,"apiEmailFetchesLeft":10,"data":{"headers":{"sender":"example@example.net","content-type":"multipart\/alternative;\r\n\tboundary=\"MIMEBoundaryec1dc8828d9bbedf095f9e9d2ebdbdeb\"","to":"recipient@mailinator.com","x-connecting-ip":"127.0.0.1","subject":"This is a subject","mime-version":"1.0","x-received-time":"1419696967076","reply-to":"example@example.net","received":"from 127-0-0-1.dynamic-ip.example.net ()\r\n by mail.mailinator.com with SMTP (Postfix)\r\n for recipient@mailinator.com;\r\n Sat, 27 Dec 2014 16:16:07 +0000 (UTC)","from":"\"Sender\" <example@example.net>","date":"Sun, 28 Dec 2014 00:16:00 +0800"},"seconds_ago":77024,"id":"1419696967-44152505-recipient","to":"recipient@mailinator.com","time":1419696967076,"subject":"This is a subject","fromfull":"example@example.net","parts":[{"headers":{"content-type":"text\/plain;\r\n\tcharset=\"iso-8859-1\"","content-transfer-encoding":"quoted-printable"},"body":"This is a body"},{"headers":{"content-type":"text\/html;\r\n\tcharset=\"iso-8859-1\"","content-transfer-encoding":"quoted-printable"},"body":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\r\n\r\n<head>\r\n<meta content=\"en-us\" http-equiv=\"Content-Language\" \/>\r\n<meta content=\"text\/html; charset=utf-8\" http-equiv=\"Content-Type\" \/>\r\n<title>Alert<\/title>\r\n<\/head>\r\n\r\n<body><p>This is a body<\/p><\/body>\r\n\r\n<\/html>"}],"been_read":false,"from":"Sender","ip":"127.0.0.1"},"forwardsLeft":10}
@@ -0,0 +1,6 @@
1
+ HTTP/1.1 500 server error
2
+ Server: Apache-Coyote/1.1
3
+ Content-Type: text/html;charset=utf-8
4
+ Content-Language: en
5
+ Content-Length: 975
6
+ Date: Sun, 28 Dec 2014 15:59:50 GMT
@@ -0,0 +1,5 @@
1
+ HTTP/1.1 200 OK
2
+ Server: Apache-Coyote/1.1
3
+ Date: Sun, 28 Dec 2014 16:26:18 GMT
4
+
5
+ {"messages":[{"seconds_ago":87011,"id":"1419696967-44152505-recipient","to":"recipient@mailinator.com","time":1419696967076,"subject":"First subject","fromfull":"sender@example.org","been_read":false,"from":"Sender name","ip":"127.0.0.1"},{"seconds_ago":73130,"id":"1419710848-46252175-recipient","to":"recipient@mailinator.com","time":1419710848789,"subject":"Second subject","fromfull":"sender@example.org","been_read":false,"from":"Another sender name","ip":"127.0.0.2"}]}
@@ -0,0 +1,6 @@
1
+ HTTP/1.1 404 msg not found
2
+ Server: Apache-Coyote/1.1
3
+ Content-Type: text/html;charset=utf-8
4
+ Content-Language: en
5
+ Content-Length: 975
6
+ Date: Sun, 28 Dec 2014 15:59:50 GMT
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailinator::Api do
4
+ let(:token) { 'ABCD' }
5
+
6
+ before do
7
+ Mailinator.configure do |config|
8
+ config.token = token
9
+ end
10
+ end
11
+
12
+ it 'should raise when document not found' do
13
+ api = Mailinator::Api.new
14
+ expect { api.get('not-found') }.to raise_error(Mailinator::Api::NotFound)
15
+ end
16
+
17
+ it 'should raise when an error occurred' do
18
+ api = Mailinator::Api.new
19
+ expect { api.get('error') }.to raise_error(Mailinator::Api::RequestError)
20
+ end
21
+
22
+ it 'should GET' do
23
+ api = Mailinator::Api.new
24
+ params = {custom: :custom, token: token}
25
+ url = 'url'
26
+ uri = URI("#{api.send(:base_url)}/#{url}")
27
+ uri.query = URI.encode_www_form(params.merge(params))
28
+ response = double(:response, {code: '200', body: {id: 1}.to_json})
29
+
30
+ expect(api)
31
+ .to receive(:get)
32
+ .with(url, params)
33
+ .and_call_original
34
+
35
+ expect(api)
36
+ .to receive(:perform_request)
37
+ .with(uri) { response }
38
+
39
+ api.get(url, params)
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailinator::Config do
4
+ it 'should assign the token propery' do
5
+ token = 'ABCD'
6
+ config = subject
7
+ config.token = token
8
+ expect(config.token).to eq(token)
9
+ end
10
+
11
+ it 'should raise an error if no token specified' do
12
+ expect { subject.token }.to raise_error(Mailinator::TokenError)
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailinator::Email do
4
+ before do
5
+ Mailinator.configure do |config|
6
+ config.token = 'ABCD'
7
+ end
8
+ end
9
+
10
+ it 'should get an email' do
11
+ body = 'This is a body'
12
+ message = Mailinator::Email.get('abcd1234')
13
+ expect(message.id).to eq('1419696967-44152505-recipient')
14
+ expect(message.subject).to eq('This is a subject')
15
+ expect(message.body).to eq(body)
16
+ expect(message.body_html).to include("<p>#{body}</p>")
17
+ expect(message.read?).to_not be
18
+ expect(message.inbox_fetches_left).to eq(696)
19
+ expect(message.email_fetches_left).to eq(10)
20
+ expect(message.sender).to eq('example@example.net')
21
+ expect(message.reply_to).to eq('example@example.net')
22
+ expect(message.from).to eq('Sender')
23
+ expect(message.ip).to eq('127.0.0.1')
24
+ expect(message.received).to match(a_string_matching('from 127-0-0-1.dynamic-ip.example.net'))
25
+ expect(message.date).to be_a(DateTime)
26
+ expect(message.time).to eq(1419696967076)
27
+ expect(message.forwards_left).to eq(10)
28
+ expect(message.original).to be_a(Hash)
29
+ end
30
+
31
+ it 'should return nil for #body_html when no html body' do
32
+ body = 'This is a body'
33
+ message = Mailinator::Email.get('abcd1234plain')
34
+ expect(message.body).to eq(body)
35
+ expect(message.body_html).to_not be
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailinator::Inbox do
4
+ let(:inbox) { Mailinator::Inbox.get('abcd1234') }
5
+
6
+ before do
7
+ Mailinator.configure do |config|
8
+ config.token = 'ABCD'
9
+ end
10
+ end
11
+
12
+ it 'should get an inbox' do
13
+ expect(inbox.messages).to be_a(Array)
14
+ expect(inbox.original).to be_a(Hash)
15
+ expect(inbox.messages.first).to include(id: '1419696967-44152505-recipient')
16
+ expect(inbox.messages.last).to include(id: '1419710848-46252175-recipient')
17
+ end
18
+
19
+ it 'should #download an email' do
20
+ expect(inbox.messages.first.download).to be_a(Mailinator::Models::Email)
21
+ expect(inbox.messages.first.download).to eq(Mailinator::Email.get(inbox.messages.first.id))
22
+ inbox.messages.first.download do |message|
23
+ expect(message).to eq(Mailinator::Email.get(inbox.messages.first.id))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailinator::Models::Base do
4
+
5
+ let(:data) { {custom: :custom} }
6
+
7
+ it 'should #transform_data with defaults' do
8
+ class CustomModel < Mailinator::Models::Base; end
9
+
10
+ klass = CustomModel.new(data)
11
+
12
+ expect(klass).to be_a(Mailinator::Models::Base)
13
+ expect(klass.custom).to eq(data[:custom])
14
+ expect(klass.original).to eq(data)
15
+ end
16
+
17
+ it 'should #transform_data' do
18
+ class CustomModel < Mailinator::Models::Base
19
+ def transform_data
20
+ {
21
+ custom: @data[:custom]
22
+ }
23
+ end
24
+ end
25
+
26
+ klass = CustomModel.new(data)
27
+
28
+ expect(klass).to be_a(Mailinator::Models::Base)
29
+ expect(klass.custom).to eq(data[:custom])
30
+ expect(klass.original).to eq(data)
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailinator do
4
+ describe 'configuration' do
5
+ let(:token) { 'ABCD' }
6
+
7
+ it 'should configure the token' do
8
+ Mailinator.configure do |config|
9
+ config.token = token
10
+ end
11
+
12
+ expect(Mailinator.config.token).to eq token
13
+ end
14
+
15
+ it 'should configure the token, short version' do
16
+ Mailinator.config.token = token
17
+ expect(Mailinator.config.token).to eq token
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'mailinator'
2
+
3
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ config.color = true
7
+ config.filter_run focus: true
8
+ config.run_all_when_everything_filtered = true
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'fakeweb'
2
+
3
+ FakeWeb.allow_net_connect = false
4
+
5
+ def fixture_file(filename)
6
+ return '' if filename == ''
7
+
8
+ file_path = File.join(File.expand_path(File.dirname(__FILE__)), '../', 'fixtures/', filename)
9
+ File.read(file_path)
10
+ end
11
+
12
+ def register_uri(url, file, method = :get)
13
+ FakeWeb.register_uri(method, url, response: fixture_file(file))
14
+ end
15
+
16
+ register_uri('https://api.mailinator.com/api/inbox?to=abcd1234&token=ABCD', 'inbox.response')
17
+ register_uri('https://api.mailinator.com/api/email?msgid=abcd1234&token=ABCD', 'email.response')
18
+ register_uri('https://api.mailinator.com/api/email?msgid=abcd1234plain&token=ABCD', 'email-plain.response')
19
+ register_uri('https://api.mailinator.com/api/email?msgid=1419696967-44152505-recipient&token=ABCD', 'email.response')
20
+ register_uri('https://api.mailinator.com/api/not-found?token=ABCD', 'not-found.response')
21
+ register_uri('https://api.mailinator.com/api/error?token=ABCD', 'error.response')
22
+
23
+ # NOTE: fix for travis ruby 1.9.3
24
+ # it replaces https:// to http://:443
25
+ register_uri('http://api.mailinator.com:443/api/inbox?to=abcd1234&token=ABCD', 'inbox.response')
26
+ register_uri('http://api.mailinator.com:443/api/email?msgid=abcd1234&token=ABCD', 'email.response')
27
+ register_uri('http://api.mailinator.com:443/api/email?msgid=abcd1234plain&token=ABCD', 'email-plain.response')
28
+ register_uri('http://api.mailinator.com:443/api/email?msgid=1419696967-44152505-recipient&token=ABCD', 'email.response')
29
+ register_uri('http://api.mailinator.com:443/api/not-found?token=ABCD', 'not-found.response')
30
+ register_uri('http://api.mailinator.com:443/api/error?token=ABCD', 'error.response')
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailinator-fix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - patrickzhang@live.ca
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - Guardfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/mailinator.rb
70
+ - lib/mailinator/api.rb
71
+ - lib/mailinator/config.rb
72
+ - lib/mailinator/email.rb
73
+ - lib/mailinator/inbox.rb
74
+ - lib/mailinator/model.rb
75
+ - lib/mailinator/models/email.rb
76
+ - lib/mailinator/models/entry.rb
77
+ - lib/mailinator/models/inbox.rb
78
+ - lib/mailinator/version.rb
79
+ - mailinator.gemspec
80
+ - spec/fixtures/email-plain.response
81
+ - spec/fixtures/email.response
82
+ - spec/fixtures/error.response
83
+ - spec/fixtures/inbox.response
84
+ - spec/fixtures/not-found.response
85
+ - spec/lib/mailinator/api_spec.rb
86
+ - spec/lib/mailinator/config_spec.rb
87
+ - spec/lib/mailinator/email_spec.rb
88
+ - spec/lib/mailinator/inbox_spec.rb
89
+ - spec/lib/mailinator/model_spec.rb
90
+ - spec/mailinator_spec.rb
91
+ - spec/spec_helper.rb
92
+ - spec/support/fake_web.rb
93
+ homepage: https://github.com/ainformatico/mailinator
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Mailinator REST API wrapper
117
+ test_files:
118
+ - spec/fixtures/email-plain.response
119
+ - spec/fixtures/email.response
120
+ - spec/fixtures/error.response
121
+ - spec/fixtures/inbox.response
122
+ - spec/fixtures/not-found.response
123
+ - spec/lib/mailinator/api_spec.rb
124
+ - spec/lib/mailinator/config_spec.rb
125
+ - spec/lib/mailinator/email_spec.rb
126
+ - spec/lib/mailinator/inbox_spec.rb
127
+ - spec/lib/mailinator/model_spec.rb
128
+ - spec/mailinator_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/support/fake_web.rb