temp-mail-ruby 0.0.2

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: 2655399d798a961c245a8bf1447354277b8c2dc9
4
+ data.tar.gz: 1153da44425d1088af1f26e1132ab60895e73556
5
+ SHA512:
6
+ metadata.gz: 646f8e7dcf0e8ec423d94b8cdabf0f6e2f865ab853beae31750b25ea9ef8966380cf8bfdd2da3562962d26e32d5924234357665a50c54123a2256fb96a7de505
7
+ data.tar.gz: bcfd5e321054609c3b7a82ad5eaf15f4bba6002be8f6e7d3af9d79a18c1d7e288288bc03469d38d4040516b1d27b3c02c8156e8958edbdbfccb10d5b584b63ea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 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,37 @@
1
+ [![Build Status](https://travis-ci.org/yogahp/temp-mail-ruby.svg?branch=master)](https://travis-ci.org/yogahp/temp-mail-ruby)
2
+
3
+ # temp-mail-ruby
4
+
5
+ Ruby client for [TempMail](https://temp-mail.org)
6
+
7
+ Original version : [temp-mail](https://github.com/maxd/temp-mail)
8
+
9
+ ## Usage
10
+
11
+ ### Get available domain names
12
+
13
+ ```ruby
14
+ require 'temp/mail'
15
+
16
+ client = Temp::Mail::Client.new
17
+ p client.available_domains
18
+ ```
19
+
20
+ ### Get incoming e-mails
21
+
22
+ ```ruby
23
+ require 'temp/mail'
24
+
25
+ client = Temp::Mail::Client.new
26
+ p client.incoming_emails('buburgoreng@vps30.com')
27
+ ```
28
+
29
+ [Here](https://temp-mail.org/en/api/) is Temp Mail API specification. It describe all fields of e-mail objects in incoming list.
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/yogahp/temp-mail-ruby/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 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('https://api.temp-mail.org/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("https://api.temp-mail.org/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.2'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'temp/mail'
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'net/smtp'
3
+ require 'gmail'
4
+
5
+ describe Temp::Mail::Client do
6
+ context 'get available domains' do
7
+ subject { described_class.new.available_domains }
8
+
9
+ it { expect(subject).to be_a Array }
10
+ it { expect(subject).to_not be_empty }
11
+ end
12
+
13
+ context 'check incoming emails (empty inbox)' do
14
+ subject { described_class.new.incoming_emails('demo@example.com') }
15
+
16
+ it { expect(subject).to be_a Array }
17
+ it { expect(subject).to be_empty }
18
+ end
19
+
20
+ context 'check incoming emails' do
21
+ let(:message_subject) { 'test message' }
22
+ let(:message) { 'This is a test message.' }
23
+ let(:from_email) { 'tempmail.gem@gmail.com' }
24
+ let(:to_email) { email = described_class.new.available_domains; "test#{email[rand(0..email.count - 1)]}" }
25
+ let(:user_name) { from_email }
26
+ let(:password) { 'd3liv3rusfr0m3v1l' }
27
+
28
+ before do
29
+ gmail = Gmail.connect(user_name, password)
30
+ email = gmail.compose
31
+ email.to = to_email
32
+ email.subject = message_subject
33
+ email.body = message
34
+ email.deliver!
35
+ email.deliver!
36
+ gmail.logout
37
+ sleep 2
38
+ end
39
+
40
+ subject { described_class.new.incoming_emails(to_email) }
41
+
42
+ it do
43
+ expect(subject).to be_a Array
44
+ expect(subject).to_not be_empty
45
+ expect(subject.last).to include(:createdAt, :mail_id, :mail_address_id, :mail_from, :mail_subject, :mail_preview, :mail_text_only, :mail_text, :mail_html, :mail_timestamp, :_id)
46
+ expect(subject.last).to include(mail_address_id: Digest::MD5.hexdigest(to_email))
47
+ expect(subject.last).to include(mail_from: from_email)
48
+ expect(subject.last).to include(mail_subject: message_subject)
49
+ expect(subject.last).to include(mail_text: message + ?\n)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
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-ruby'
8
+ spec.version = Temp::Mail::VERSION
9
+ spec.authors = ['Maxim Dobryakov', ' Yoga Hapriana']
10
+ spec.email = ['maxim.dobryakov@gmail.com', 'thenelse@rocketmail.com']
11
+ spec.summary = %q{Client to temp-mail.org API.}
12
+ spec.description = %q{Ruby client to temp-mail.org API}
13
+ spec.homepage = 'https://github.com/yogahp/temp-mail-ruby'
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
+ spec.add_development_dependency 'gmail', '~> 0.6.0'
25
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: temp-mail-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Dobryakov
8
+ - " Yoga Hapriana"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.2'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.2'
56
+ - !ruby/object:Gem::Dependency
57
+ name: gmail
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.6.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.6.0
70
+ description: Ruby client to temp-mail.org API
71
+ email:
72
+ - maxim.dobryakov@gmail.com
73
+ - thenelse@rocketmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/temp/mail.rb
85
+ - lib/temp/mail/client.rb
86
+ - lib/temp/mail/version.rb
87
+ - spec/spec_helper.rb
88
+ - spec/temp/mail/client_spec.rb
89
+ - temp-mail-ruby.gemspec
90
+ homepage: https://github.com/yogahp/temp-mail-ruby
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.10
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Client to temp-mail.org API.
114
+ test_files:
115
+ - spec/spec_helper.rb
116
+ - spec/temp/mail/client_spec.rb