mailhogwarts 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06d33f9b29f4f608d28c36cbe43ffc320cf429c8
4
+ data.tar.gz: 0e95e0e7a17014f46bcdf12a70703cd7cbdb4d8a
5
+ SHA512:
6
+ metadata.gz: b274fa42d80fff94f3d9d27be1ce133341825b98ba0906978bf321f299166f7a3b864ba51531b00cc834d10b1476c12ff9d917ec34f518d87c7182a167275198
7
+ data.tar.gz: 39b807b9b5eacffe09a51be521d702a556ce18d6faa9e5c7b92ca836150b28694b0b67192d6400f032fa03bd40691d5274bd71d50830158916665edb7ecfd864
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .idea
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ Gemfile.lock
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mailhogwarts.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Furtikov Kirill Alekseevich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'mailhogwarts/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'mailhogwarts'
7
+ spec.version = MailHogwarts::VERSION
8
+ spec.authors = ['Furtikov Kirill']
9
+ spec.email = ['kafurtikov@gmail.com']
10
+
11
+ spec.summary = 'A simple Ruby gem for using MailHog API'
12
+ spec.description = 'A Ruby gem for rapid API testing with great conventions.'
13
+ spec.homepage = 'https://github.com/KirillFurtikov/mailhogwarts'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.16'
20
+ spec.add_development_dependency 'rake', '~> 10.0'
21
+ spec.add_development_dependency 'rspec', '~> 3.0'
22
+
23
+ spec.add_dependency 'rest-client', '~> 2.0'
24
+ end
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ [![Build Status](https://travis-ci.org/KirillFurtikov/MailHogwarts.svg?branch=master)](https://travis-ci.org/KirillFurtikov/MailHogwarts)
2
+
3
+ # MailHogwarts
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/MailHogwarts`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'mailhogwarts'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install MailHogwarts
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/KirillFurtikov/MailHogwarts. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the MailHogwarts project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/MailHogwarts/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mail_hogwarts'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/mail_hogwarts'
@@ -0,0 +1,20 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'base64'
4
+ require 'yaml'
5
+
6
+ require_relative 'mailhogwarts/version'
7
+ require_relative 'mailhogwarts/mailer'
8
+ require_relative 'mailhogwarts/messages'
9
+ require_relative 'mailhogwarts/message'
10
+ require_relative 'mailhogwarts/search'
11
+
12
+ module MailHogwarts
13
+ def self.messages(args)
14
+ @messages = Messages.new(url: args[:url])
15
+ end
16
+
17
+ def self.search(url, kind, query)
18
+ @search = Search.new(url: url, kind: kind, query: query)
19
+ end
20
+ end
@@ -0,0 +1,75 @@
1
+ module MailHogwarts
2
+ class Mailer
3
+ attr_reader :domain, :url, :path, :body, :messages
4
+
5
+ def initialize(args)
6
+ @url = "#{@domain = args[:url]}#{@path = args[:path]}"
7
+ end
8
+
9
+ def call
10
+ response = RestClient::Request.execute method: :get, url: @url, verify_ssl: false
11
+ @body = JSON.parse(response.body)
12
+
13
+ @messages = body['items'].map do |message|
14
+ Message.new id: message['ID'],
15
+ created_at: Time.parse(message['Created']).to_i,
16
+ from: message['Raw']['From'],
17
+ to: message['Raw']['To'],
18
+ subject: readable_subject(message['Content']['Headers']['Subject'].join(' ')),
19
+ body: readable_body(message['Content']['Body'])
20
+ end
21
+
22
+ @messages.size
23
+ end
24
+
25
+ def [](index)
26
+ @messages[index]
27
+ end
28
+
29
+ def ids
30
+ @ids = @messages.map(&:id)
31
+ end
32
+
33
+ def count
34
+ body['count']
35
+ end
36
+
37
+ def total
38
+ body['total']
39
+ end
40
+
41
+ def select(filters)
42
+ messages = @messages
43
+ filtered_messages = []
44
+
45
+ (%i[from to subject body] & filters.keys).each do |filter|
46
+ messages.each do |message|
47
+ filtered_messages << message if message.send(filter).include?(filters[filter])
48
+ end
49
+
50
+ messages = filtered_messages
51
+ filtered_messages = []
52
+ end
53
+
54
+ messages
55
+ end
56
+
57
+ private
58
+
59
+ def readable_body(body)
60
+ Base64.decode64(body).force_encoding('utf-8')
61
+ end
62
+
63
+ def readable_subject(subject)
64
+ subject.split('=?UTF-8?Q?').map do |word|
65
+ next if word.size.zero?
66
+
67
+ word.strip.gsub(/(\?=)/, '').tr('_', ' ')
68
+ end.reject(&:nil?).map do |word|
69
+ next if word.nil?
70
+
71
+ word.unpack('M').join('')
72
+ end.join('').strip.force_encoding('utf-8')
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,26 @@
1
+ module MailHogwarts
2
+ class Message
3
+ include Comparable
4
+ attr_reader :message
5
+
6
+ def initialize(fields)
7
+ @message = fields
8
+
9
+ @message.keys.each do |key|
10
+ define_singleton_method(key.to_s) do
11
+ @message[key]
12
+ end
13
+ end
14
+ end
15
+
16
+ def keys
17
+ @message.keys
18
+ end
19
+
20
+ alias_method :fields, :keys
21
+
22
+ def <=>(other)
23
+ created_at.to_i <=> other.created_at.to_i
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module MailHogwarts
2
+ class Messages < Mailer
3
+ def initialize(args)
4
+ super(args.merge(path: '/api/v2/messages'))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MailHogwarts
2
+ class Search < Mailer
3
+ def initialize(args)
4
+ super(args.merge(path: "/api/v2/search?kind=#{args[:kind]}&query=#{args[:query]}"))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module MailHogwarts
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/mail_hogwarts'
@@ -0,0 +1,11 @@
1
+ RSpec.describe MailHogwarts do
2
+ describe 'VERSION' do
3
+ it 'has a version number' do
4
+ expect(MailHogwarts::VERSION).not_to be nil
5
+ end
6
+ end
7
+
8
+ it 'respond to messages' do
9
+ expect(MailHogwarts).respond_to?(:messages)
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+ require 'mail_hogwarts'
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = '.rspec_status'
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailhogwarts
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Furtikov Kirill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-28 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: A Ruby gem for rapid API testing with great conventions.
70
+ email:
71
+ - kafurtikov@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - MailHogwarts.gemspec
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/mail-hogwarts.rb
87
+ - lib/mail_hogwarts.rb
88
+ - lib/mailhogwarts.rb
89
+ - lib/mailhogwarts/mailer.rb
90
+ - lib/mailhogwarts/message.rb
91
+ - lib/mailhogwarts/messages.rb
92
+ - lib/mailhogwarts/search.rb
93
+ - lib/mailhogwarts/version.rb
94
+ - spec/mail_hogwarts_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/KirillFurtikov/mailhogwarts
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A simple Ruby gem for using MailHog API
120
+ test_files: []