├── .gitignore ├── .rspec ├── .travis.yml ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib └── temp │ ├── mail.rb │ └── mail │ ├── client.rb │ └── version.rb ├── spec ├── spec_helper.rb └── temp │ └── mail │ └── client_spec.rb └── temp-mail.gemspec /.gitignore: -------------------------------------------------------------------------------- 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 16 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.1.5 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in temp-mail.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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('monkey9000@flurred.com') 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 36 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | 8 | -------------------------------------------------------------------------------- /lib/temp/mail.rb: -------------------------------------------------------------------------------- 1 | require 'temp/mail/version' 2 | require 'temp/mail/client' 3 | 4 | module Temp 5 | module Mail 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/temp/mail/client.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /lib/temp/mail/version.rb: -------------------------------------------------------------------------------- 1 | module Temp 2 | module Mail 3 | VERSION = '0.0.1' 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'temp/mail' 3 | -------------------------------------------------------------------------------- /spec/temp/mail/client_spec.rb: -------------------------------------------------------------------------------- 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 59 | -------------------------------------------------------------------------------- /temp-mail.gemspec: -------------------------------------------------------------------------------- 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 25 | --------------------------------------------------------------------------------