temp-mail 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 620c116367f787e71d05662291cd548c2bb6008f
4
+ data.tar.gz: f2cdb0635fcd35360f34619802154cc038b14b96
5
+ SHA512:
6
+ metadata.gz: 61b7eebc7396d6c6bd6db01bfdc39c15e71c8fe8fd66c2ddb0add49370bd6b3be9d360bfd1f3406e20313285c12ae79f3b951b2512215d74b72f44dcdc76e3e3
7
+ data.tar.gz: 6b787ffcb49a1da9cc325f36f3684c2acebef083fb22e66057a5c3e28d79525454def92156f07308c5bcde390c83a3ed7e1a0adf992d07445d6a45bfd6a16f0d
@@ -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
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in temp-mail.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Maxim Dobryakov
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,35 @@
1
+ [![Build Status](https://travis-ci.org/maxd/temp-mail.svg?branch=master)](https://travis-ci.org/maxd/temp-mail)
2
+
3
+ # temp-mail
4
+
5
+ Ruby client for temp-mail.ru
6
+
7
+ ## Usage
8
+
9
+ ### Get available domain names
10
+
11
+ ```ruby
12
+ require 'temp/mail'
13
+
14
+ client = Temp::Mail::Client.new
15
+ p client.available_domains
16
+ ```
17
+
18
+ ### Get incoming e-mails
19
+
20
+ ```ruby
21
+ require 'temp/mail'
22
+
23
+ client = Temp::Mail::Client.new
24
+ p client.incoming_emails
25
+ ```
26
+
27
+ [Here](http://api.temp-mail.ru/) is Temp Mail API specification. It describe all fields of e-mail objects in incoming list.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/maxd/temp-mail/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,7 @@
1
+ require 'temp/mail/version'
2
+ require 'temp/mail/client'
3
+
4
+ module Temp
5
+ module Mail
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'digest'
4
+
5
+ module Temp
6
+ module Mail
7
+ class Client
8
+ def available_domains
9
+ response = Net::HTTP.get_response(URI('http://api.temp-mail.ru/request/domains/format/json/'))
10
+ JSON.parse(response.body, symbolize_names: true)
11
+ end
12
+
13
+ def incoming_emails(email)
14
+ hash = Digest::MD5.hexdigest(email)
15
+ response = Net::HTTP.get_response(URI("http://api.temp-mail.ru/request/mail/id/#{hash}/format/json/"))
16
+
17
+ if response.is_a?(Net::HTTPNotFound)
18
+ []
19
+ else
20
+ JSON.parse(response.body, symbolize_names: true)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Temp
2
+ module Mail
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'temp/mail'
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'net/smtp'
3
+
4
+ describe Temp::Mail::Client do
5
+ context 'get available domains' do
6
+ subject { described_class.new.available_domains }
7
+
8
+ it { expect(subject).to be_a Array }
9
+ it { expect(subject).to_not be_empty }
10
+ end
11
+
12
+ context 'check incoming emails (empty inbox)' do
13
+ subject { described_class.new.incoming_emails('demo@example.com') }
14
+
15
+ it { expect(subject).to be_a Array }
16
+ it { expect(subject).to be_empty }
17
+ end
18
+
19
+ context 'check incoming emails' do
20
+ let(:message_subject) { 'test message' }
21
+ let(:message) { 'This is a test message.' }
22
+ let(:from_email) { 'temp-mail-gem@yandex.ru' }
23
+ let(:to_email) { 'test-mail-gem@landmail.co' }
24
+
25
+ let(:smtp_host) { %w{smtp yandex ru}.join(?.) }
26
+ let(:smtp_port) { 465 }
27
+ let(:username) { 'temp-mail-gem' }
28
+ let(:password) { 'xei9daeph0Eka5Nileuh' }
29
+
30
+ before do
31
+ smtp = Net::SMTP.new(smtp_host, smtp_port)
32
+ smtp.enable_ssl
33
+ smtp.start('yandex.ru', username, password, :login) do
34
+ smtp.open_message_stream(from_email, to_email) do |f|
35
+ f.puts "From: #{from_email}"
36
+ f.puts "To: #{to_email}"
37
+ f.puts "Subject: #{message_subject}"
38
+ f.puts
39
+ f.puts message
40
+ end
41
+ end
42
+
43
+ sleep 2
44
+ end
45
+
46
+ subject { described_class.new.incoming_emails(to_email) }
47
+
48
+ it do
49
+ expect(subject).to be_a Array
50
+ expect(subject).to_not be_empty
51
+ expect(subject.last).to include(:mail_unique_id, :mail_id, :mail_address_id, :mail_from, :mail_subject, :mail_preview, :mail_text_only, :mail_text, :mail_html, :mail_timestamp)
52
+ expect(subject.last).to include(mail_address_id: Digest::MD5.hexdigest(to_email))
53
+ expect(subject.last).to include(mail_from: from_email)
54
+ expect(subject.last).to include(mail_subject: message_subject)
55
+ expect(subject.last).to include(mail_text: message + ?\n)
56
+ end
57
+ end
58
+ 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 'temp/mail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'temp-mail'
8
+ spec.version = Temp::Mail::VERSION
9
+ spec.authors = ['Maxim Dobryakov']
10
+ spec.email = ['maxim.dobryakov@gmail.com']
11
+ spec.summary = %q{Client to temp-mail.ru API.}
12
+ spec.description = %q{Ruby client to temp-mail.ru API}
13
+ spec.homepage = 'https://github.com/maxd/temp-mail'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.2'
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: temp-mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Dobryakov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Ruby client to temp-mail.ru API
56
+ email:
57
+ - maxim.dobryakov@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/temp/mail.rb
70
+ - lib/temp/mail/client.rb
71
+ - lib/temp/mail/version.rb
72
+ - spec/spec_helper.rb
73
+ - spec/temp/mail/client_spec.rb
74
+ - temp-mail.gemspec
75
+ homepage: https://github.com/maxd/temp-mail
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Client to temp-mail.ru API.
99
+ test_files:
100
+ - spec/spec_helper.rb
101
+ - spec/temp/mail/client_spec.rb