boss-mailer 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 76a5bd9ab0f3c717dab3d910defef32a79ba9249
4
+ data.tar.gz: 9e79baf44bda8dc105d3b59b22f7b8d1381dc870
5
+ SHA512:
6
+ metadata.gz: ece63647fc0764e892f88e6805a1f0a10fbe54a43c962e2b2a4b8d020fca9243ccfd8720bed16d15efcd1d8e635bb7a4cb7a740f9323dc595fa187a8d9b2aecb
7
+ data.tar.gz: b71941d49cbc6ac2ebc18e4cb34d8de5727d3b8a69b435d8b6a7e4a48890d880d3df139c706b1431d98507d06770517b753722ff86082c45979dfcce50521a58
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --require pry
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'mail'
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ [![Build Status](https://magnum.travis-ci.com/DenniJensen/boss-mailer.svg?token=LXPadLLZHBGUqXF9dTdc)](https://magnum.travis-ci.com/DenniJensen/boss-mailer)
2
+
3
+ # Boss::Mailer
4
+ This is a gem to mail the working hours form the terminal
5
+ to your boss.
6
+
7
+
8
+ ## Installation
9
+
10
+ Just install via Rubygems
11
+
12
+ ```ruby
13
+ gem 'boss-mailer'
14
+ ```
15
+
16
+ ```ruby
17
+ boss-mailer --init
18
+ ```
19
+
20
+ In your home path you will find now a file like:
21
+
22
+ ```yaml
23
+ :mail_settings:
24
+ :from:
25
+ :to:
26
+ :subject:
27
+ :options:
28
+ :address: "smtp.gmail.com",
29
+ :port: 587
30
+ :user_name: '<username>',
31
+ :password: '<password>',
32
+ :authentication: 'plain',
33
+ :enable_starttls_auto: true
34
+ ```
35
+ Fill in your settings for you mailing hoster and the address for boss.
36
+
37
+ ## Usage
38
+ The Bossmailer provides a simple CLI. The boss-mailer needs 3 arguments.
39
+ The time from the beginning of the day, from the ending and you pause time.
40
+
41
+ For example
42
+ `boss-mailer HH:MM HH:MM HH:MM`
43
+
44
+ To provide a quick usage your can just time the hour and the boss-mailer will
45
+ parse it for you.
46
+
47
+ ```
48
+ boss-mailer 9 18 0055
49
+ ```
50
+ will be get translated into
51
+ ```
52
+ boss-mailer 09:00 18:00 00:55
53
+ ```
54
+
55
+ **Pause time** needs the leading zeros in this version (0.1.0)
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DenniJensen/boss-mailer.
60
+
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/boss-mailer ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'boss_mailer'
4
+ require 'boss_mailer/config_deliverer'
5
+ require 'boss_mailer/time_parser'
6
+ require 'boss_mailer/mailer'
7
+ require 'optparse'
8
+ require 'mail'
9
+ require 'yaml'
10
+
11
+ options = {}
12
+ OptionParser.new do |opts|
13
+ opts.on("--init", "inialize empty setting in home dir") do
14
+ options[:init] = true
15
+ end
16
+ opts.on("--force", 'forces to create a new config file') do
17
+ options[:force] = true
18
+ end
19
+ end.parse!
20
+
21
+ CONFIG_PATH = ENV['HOME'] + '/.boss-mailer.yml'
22
+
23
+ if options[:init]
24
+ if File.exists?(CONFIG_PATH) && !options[:force]
25
+ puts "file alread exists in #{CONFIG_PATH}"
26
+ puts "Use --init --force to reinstall config file"
27
+ exit 1
28
+ else
29
+ config = BossMailer::ConfigDeliverer.config
30
+ File.open(CONFIG_PATH, 'w') { |file| YAML.dump(config, file) }
31
+ puts "Config File created in #{CONFIG_PATH}"
32
+ puts "Please fill in all the information in this config file"
33
+ exit 0
34
+ end
35
+ end
36
+
37
+ unless File.exists? CONFIG_PATH
38
+ puts 'No Config file found, please use --init to initialize one'
39
+ puts 'After creating a config file, please fill in the mail informations'
40
+ exit 1
41
+ end
42
+
43
+ config = YAML.load_file(CONFIG_PATH)
44
+ mailer_settings = config[:mail_settings]
45
+
46
+ if mailer_settings[:to].blank? or mailer_settings[:from].blank? or mailer_settings[:subject].blank?
47
+ puts "Configuration is missing in: #{CONFIG_PATH}"
48
+ exit 1
49
+ end
50
+
51
+ if ARGV.size < 3
52
+ puts 'Need start, end and pause of work'
53
+ exit 1
54
+ end
55
+
56
+ time_parser = BossMailer::TimeParser.new
57
+ working_time = {
58
+ start: time_parser.parse(ARGV.shift),
59
+ end: time_parser.parse(ARGV.shift),
60
+ pause: time_parser.parse(ARGV.shift)
61
+ }
62
+
63
+ mailer = BossMailer::Mailer.new mailer_settings, working_time
64
+ mailer.mail
65
+
66
+
67
+ p working_time
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "boss/mailer"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boss_mailer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "boss-mailer"
8
+ spec.version = BossMailer::VERSION
9
+ spec.authors = ["Dennis Haegler"]
10
+ spec.email = ["d.haegler@hotmail.de"]
11
+ spec.licenses = ['MIT']
12
+
13
+ spec.summary = %q{
14
+ This is a gem to mail the working hours form the terminal to your boss. }
15
+ spec.description = %q{
16
+ This is a gem to mail the working hours form the terminal to your boss.
17
+ You can write email from the terminal to your boss. (Or anyone you want
18
+ to mail your working time)
19
+ }
20
+
21
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
22
+ # delete this section to allow pushing this gem to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
27
+ end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ spec.executables = ['boss-mailer']
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.10"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec"
36
+ spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "mailcatcher"
38
+ end
@@ -0,0 +1,11 @@
1
+ :mail_settings:
2
+ :from:
3
+ :to:
4
+ :subject:
5
+ :options:
6
+ :address: "smtp.gmail.com",
7
+ :port: 587
8
+ :user_name: '<username>',
9
+ :password: '<password>',
10
+ :authentication: 'plain',
11
+ :enable_starttls_auto: true
@@ -0,0 +1,6 @@
1
+ require "boss_mailer/version"
2
+
3
+ module BossMailer
4
+ puts "The version #{BossMailer::VERSION}"
5
+ puts "mailing ..."
6
+ end
@@ -0,0 +1,5 @@
1
+ module BossMailer
2
+ class ArgumentFetcher
3
+
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module BossMailer
2
+ class ConfigDeliverer
3
+ def self.config
4
+ {
5
+ mail_settings: {
6
+ from: '',
7
+ to: '',
8
+ subject: '',
9
+ options: {
10
+ address: "smtp.gmail.com",
11
+ port: 587,
12
+ user_name: "<username>",
13
+ password: "<password>",
14
+ authentication: "plain",
15
+ enable_starttls_auto: true
16
+ }
17
+ }
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ module BossMailer
4
+ class ConfigFetcher
5
+ attr_accessor :mail_settings
6
+ attr_accessor :working_hours
7
+
8
+ def initialize
9
+ @mail_settings = fetch_mail_settings
10
+ @working_hours = fetch_working_hours
11
+ end
12
+
13
+ private
14
+
15
+ def fetch_mail_settings
16
+ settings[:mail_settings]
17
+ end
18
+
19
+ def fetch_working_hours
20
+ settings[:working_hours]
21
+ end
22
+
23
+ def settings
24
+ YAML.load_file(config_path)
25
+ end
26
+
27
+ def config_path
28
+ 'not yet implemented'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module BossMailer
2
+ class Mailer
3
+ def initialize(mail_settings, working_hours)
4
+ @working_hours = working_hours
5
+ @mail_settings = mail_settings
6
+ @options = @mail_settings.delete :options
7
+ @mail_settings[:body] = mail_body
8
+ @mailer = Mail.new @mail_settings
9
+ end
10
+
11
+ def mail
12
+ @mailer.delivery_method :smtp, @options
13
+ @mailer.deliver
14
+ end
15
+
16
+ private
17
+
18
+ def mail_body
19
+ "#{Time.now.strftime("%a: %d/%m/%Y")}\n\
20
+ \nStart #{@working_hours[:start]}\
21
+ \nEnde #{@working_hours[:end]}\
22
+ \nPause #{@working_hours[:pause]}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ module BossMailer
2
+ class TimeParser
3
+ def parse(time)
4
+ raise if time.size > 5
5
+ @time = time.split ":"
6
+ return parse_seperated_time unless @time.first == time
7
+ parse_mixed_time
8
+ end
9
+
10
+ private
11
+
12
+ def parse_mixed_time
13
+ return parse_hours_only_time if @time.first.size < 3
14
+ digits = @time.first.chars
15
+ @time[1] = digits.pop(2).join
16
+ @time[0] = digits.first(2).join
17
+ parse_seperated_time
18
+ end
19
+
20
+ def parse_hours_only_time
21
+ @time[1] = '00'
22
+ parse_seperated_time
23
+ end
24
+
25
+ def parse_seperated_time
26
+ hours = digit_to_two @time.first
27
+ minutes = digit_to_two @time.last
28
+ "#{hours}:#{minutes}"
29
+ end
30
+
31
+ def digit_to_two(digit)
32
+ return digit if digit.size == 2
33
+ "0#{digit}"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module BossMailer
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boss-mailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Haegler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-31 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mailcatcher
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: "\n This is a gem to mail the working hours form the terminal to your
84
+ boss.\n You can write email from the terminal to your boss. (Or anyone you want\n
85
+ \ to mail your working time)\n "
86
+ email:
87
+ - d.haegler@hotmail.de
88
+ executables:
89
+ - boss-mailer
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - README.md
98
+ - Rakefile
99
+ - bin/boss-mailer
100
+ - bin/console
101
+ - bin/setup
102
+ - boss-mailer.gemspec
103
+ - config_file_example.yml
104
+ - lib/boss_mailer.rb
105
+ - lib/boss_mailer/argument_fetcher.rb
106
+ - lib/boss_mailer/config_deliverer.rb
107
+ - lib/boss_mailer/config_fetcher.rb
108
+ - lib/boss_mailer/mailer.rb
109
+ - lib/boss_mailer/time_parser.rb
110
+ - lib/boss_mailer/version.rb
111
+ homepage:
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ allowed_push_host: https://rubygems.org
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.8
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: This is a gem to mail the working hours form the terminal to your boss.
136
+ test_files: []