Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

V1 release #14

Merged
merged 23 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
Expand Down
13 changes: 4 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.1.1
- 2.1.2
- 2.1.3
- 2.1.4
- 2.1.5
- 2.2.0
- 2.3.0
- 2.4.0
- 2.5.0
- 2.6.0
bundler_args: --without debug
before_install:
- gem update bundler
19 changes: 11 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in mailinator.gemspec
gemspec

group :development do
gem 'rubocop', '~> 0.41.2'
gem 'rspec', '~> 3.4.0'
gem 'guard', '~> 2.14.0'
gem 'guard-rspec', '~> 4.7.0'
gem 'listen', '~> 2.10.1'
gem 'fakeweb', '~> 1.3'
gem 'coveralls', require: false
gem 'fakeweb', '~> 1.3.0'
gem 'guard', '~> 2.14.2'
gem 'guard-rspec', '~> 4.7.3'
gem 'listen', '~> 3.1.5'
gem 'rspec', '~> 3.7.0'
gem 'rubocop', '~> 0.57.1'
end

group :debug do
gem 'pry', '~> 0.10.3'
gem 'pry-byebug', '~> 3.4.0'
gem 'pry', '~> 0.11.3'
gem 'pry-byebug', '~> 3.6.0'
end
135 changes: 135 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
PATH
remote: .
specs:
mailinator (0.0.4)
hashie (~> 3.4.4)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
byebug (10.0.2)
coderay (1.1.2)
coveralls (0.7.1)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
diff-lcs (1.3)
docile (1.3.1)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
fakeweb (1.3.0)
ffi (1.9.25)
formatador (0.2.5)
guard (2.14.2)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashie (3.4.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
jaro_winkler (1.5.1)
json (2.1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lumberjack (1.0.13)
method_source (0.9.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
multi_json (1.13.1)
nenv (0.3.0)
netrc (0.11.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.12.1)
parser (2.5.1.0)
ast (~> 2.4.0)
powerpack (0.1.2)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.6.0)
byebug (~> 10.0)
pry (~> 0.10)
rainbow (3.0.0)
rake (11.1.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.57.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
shellany (0.0.1)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
term-ansicolor (1.6.0)
tins (~> 1.0)
thor (0.20.0)
tins (1.16.3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.4.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.7)
coveralls
fakeweb (~> 1.3.0)
guard (~> 2.14.2)
guard-rspec (~> 4.7.3)
listen (~> 3.1.5)
mailinator!
pry (~> 0.11.3)
pry-byebug (~> 3.6.0)
rake (~> 11.1.2)
rspec (~> 3.7.0)
rubocop (~> 0.57.1)

BUNDLED WITH
1.16.0
2 changes: 2 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/ainformatico/mailinator.svg)](https://travis-ci.org/ainformatico/mailinator)
[![Code Climate](https://codeclimate.com/github/ainformatico/mailinator/badges/gpa.svg)](https://codeclimate.com/github/ainformatico/mailinator)
[![Coverage Status](https://coveralls.io/repos/github/ainformatico/mailinator/badge.svg?branch=master)](https://coveralls.io/github/ainformatico/mailinator?branch=master)

# Mailinator

Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |task|
task.rspec_opts = ['--color', '--format', 'documentation']
end

task :default => :spec
task default: :spec
2 changes: 2 additions & 0 deletions lib/mailinator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mailinator/model'
require 'mailinator/models/email'
require 'mailinator/models/entry'
Expand Down
20 changes: 12 additions & 8 deletions lib/mailinator/api.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# frozen_string_literal: true

require 'net/http'
require 'json'

module Mailinator

class Api
class NotFound < StandardError; end
class RequestError < StandardError; end

def get(url, params = {})
response = request(url, params)

handle_response(response)
end

Expand All @@ -21,12 +23,14 @@ def token
def request(url, params)
uri = generate_url(url)
uri.query = generate_params(params)

perform_request(uri)
end

def perform_request(uri)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == 'https')

http.get(uri.request_uri)
end

Expand All @@ -35,7 +39,7 @@ def generate_url(url)
end

def generate_params(params)
URI.encode_www_form(params.merge({token: token}))
URI.encode_www_form(params.merge(token: token))
end

def base_url
Expand All @@ -44,12 +48,12 @@ def base_url

def handle_response(response)
case response.code.to_i
when 200
JSON.parse(response.body)
when 404
fail NotFound
else
fail RequestError, {status: response.message, code: response.code}
when 200
JSON.parse(response.body)
when 404
raise NotFound
else
raise RequestError, status: response.message, code: response.code
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/mailinator/config.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# frozen_string_literal: true

module Mailinator
class TokenError < StandardError; end

class Config
attr_accessor :token

def token
fail TokenError, 'Please provide a token' if @token.nil?
raise TokenError, 'Please provide a token' if @token.nil?

@token
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mailinator/email.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# frozen_string_literal: true

module Mailinator
class Email
class << self
def get(id)
api = Api.new
data = api.get('email', msgid: id)

populate(data)
end

def delete(id)
api = Api.new

api.get('delete', msgid: id)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/mailinator/inbox.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# frozen_string_literal: true

module Mailinator
class Inbox
class << self
def get(to)
api = Api.new
data = api.get('inbox', to: to)

populate(data)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/mailinator/model.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# frozen_string_literal: true

require 'hashie'

module Mailinator
module Models
class Base < Hashie::Mash
def initialize(data)
@data = data

super(transform_data)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/mailinator/models/email.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'date'

module Mailinator
Expand Down
2 changes: 2 additions & 0 deletions lib/mailinator/models/entry.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mailinator
module Models
class Entry < Base
Expand Down
2 changes: 2 additions & 0 deletions lib/mailinator/models/inbox.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mailinator
module Models
class Inbox < Base
Expand Down
2 changes: 2 additions & 0 deletions lib/mailinator/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mailinator
VERSION = '0.0.4'
end
7 changes: 4 additions & 3 deletions mailinator.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'mailinator/version'

Expand All @@ -8,7 +9,7 @@ Gem::Specification.new do |spec|
spec.version = Mailinator::VERSION
spec.authors = ['Alejandro Dev.']
spec.email = ['aeinformatico@gmail.com']
spec.summary = %q{Mailinator REST API wrapper}
spec.summary = 'Mailinator REST API wrapper'
spec.homepage = 'https://github.com/ainformatico/mailinator'
spec.license = 'MIT'

Expand Down