secret_santa_picker 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c28fc8d636bda7e25291799188ccfaa999c1e5bcd3d44c99b291dc5f1954d1c
4
+ data.tar.gz: 5c878d5b45e1ef65e29cd73d848ffbba8f89f58b7ea193f639b55a40e81d68db
5
+ SHA512:
6
+ metadata.gz: e35764c00e62ec072805525852661651fb8b818c4b1ed8c9a4a8f68ac0f08e6914bfb679ef9cb5cab98d39a0b6a0173c94ac70fb4e666fe9ae963e52b1031c70
7
+ data.tar.gz: 567b6d884b623409cc2142adec904a2f6229fd96dca37573f7bd349cb8e459e33fb2d0bf2ccdc248836be0f7b0e04bcad476e44adb2d24ad1612e84619831aa2
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ *.csv
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 1.16.4
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 secret_santa_picker.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sean
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,39 @@
1
+ # SecretSantaPicker
2
+
3
+ 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/secret_santa_picker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'secret_santa_picker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install secret_santa_picker
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/secret_santa_picker.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "secret_santa_picker"
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__)
@@ -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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "secret_santa_picker"
4
+
5
+ cli = SecretSantaPicker::Cli.new ARGV
6
+
7
+ cli.run
@@ -0,0 +1,5 @@
1
+ require "secret_santa_picker/version"
2
+ require "secret_santa_picker/configuration"
3
+ require "secret_santa_picker/cli"
4
+
5
+ module SecretSantaPicker; end
@@ -0,0 +1,63 @@
1
+ require 'optparse'
2
+
3
+ require 'secret_santa_picker'
4
+ require 'secret_santa_picker/const'
5
+ require 'secret_santa_picker/configuration'
6
+ require 'secret_santa_picker/processor'
7
+
8
+ module SecretSantaPicker
9
+ class Cli
10
+ def initialize(argv)
11
+ @argv = argv.dup
12
+ @conf = nil
13
+ @parser = nil
14
+ setup_options
15
+
16
+ begin
17
+ @parser.parse! @argv
18
+ rescue UnsupportedOption
19
+ exit 1
20
+ end
21
+
22
+ @processor = SecretSantaPicker::Processor.new(@conf)
23
+ end
24
+
25
+ def run
26
+ @processor.run
27
+ end
28
+
29
+ def setup_options
30
+ @conf = Configuration.new do |config|
31
+ @parser = OptionParser.new do |o|
32
+ o.on "-c", "--csv-file PATH", "Load csv file as participants in secret santa" do |arg|
33
+ config.csv_file_path = arg
34
+ end
35
+
36
+ o.on "-s", "--sender-email EMAIL", "Who to send email from" do |arg|
37
+ config.sender_email = arg
38
+ end
39
+
40
+ o.on "-p", "--sender-password PASSWORD", "The password for email account being used to send email" do |arg|
41
+ config.sender_password = arg
42
+ end
43
+
44
+ o.on "-d", "--debug", "Will disable external communication" do |d|
45
+ config.debug = d
46
+ end
47
+
48
+ o.on "-V", "--version", "Print the version information" do
49
+ puts "secret_santa_picker version #{SecretSantaPicker::VERSION}"
50
+ exit 0
51
+ end
52
+
53
+ o.banner = "secret_santa_picker <options>"
54
+
55
+ o.on_tail "-h", "--help", "Show help" do
56
+ $stdout.puts o
57
+ exit 0
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,24 @@
1
+ module SecretSantaPicker
2
+ module ConfigDefault
3
+ DefaultCSVFilePath = "secret_santa.csv"
4
+ end
5
+
6
+ class Configuration
7
+ include ConfigDefault
8
+
9
+ attr_accessor :csv_file_path, :sender_email, :sender_password, :debug
10
+
11
+ def initialize(&block)
12
+ @csv_file_path = DefaultCSVFilePath
13
+ @sender_email = ENV['SENDER_EMAIL']
14
+ @sender_password = ENV['SENDER_PASSWORD']
15
+ @debug = false
16
+
17
+ configure(&block) if block
18
+ end
19
+
20
+ def configure
21
+ yield self
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module SecretSantaPicker
2
+ class UnsupportedOption < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module SecretSantaPicker
2
+ class Pair
3
+ attr_accessor :from, :to
4
+
5
+ def self.generate(persons:)
6
+ all_people = persons.dup.shuffle
7
+
8
+ all_people.map.with_index do |person, index|
9
+ to_person = index == (all_people.count - 1) ? all_people[0] : all_people[index + 1]
10
+
11
+ Pair.new(from: person, to: to_person)
12
+ end
13
+ end
14
+
15
+ def initialize(from:, to:)
16
+ @from = from
17
+ @to = to
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module SecretSantaPicker
2
+ class Person
3
+ attr_accessor :name, :email
4
+
5
+ def self.generate(csv_array:)
6
+ csv_array.map do |name, email|
7
+ Person.new(name: name, email: email)
8
+ end
9
+ end
10
+
11
+ def initialize(name:, email:)
12
+ @name = name
13
+ @email = email
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,51 @@
1
+ require 'mail'
2
+ require 'csv'
3
+
4
+ require 'secret_santa_picker/person'
5
+ require 'secret_santa_picker/pair'
6
+
7
+ module SecretSantaPicker
8
+ class Processor
9
+ def initialize(conf)
10
+ @conf = conf
11
+ end
12
+
13
+ def run
14
+ pairs.each { |pair| send_mail(pair: pair) }
15
+ end
16
+
17
+ private
18
+
19
+ def send_mail(pair:)
20
+ sender_email = @conf.sender_email
21
+ mail = Mail.new do
22
+ from sender_email
23
+ to pair.from.email
24
+ subject "Cashin Family Secret Santa #{Date.today.strftime('%Y')}"
25
+ body "Hey #{pair.from.name},\n\nYou are the secret Santa for #{pair.to.name}.\n\nGood Luck!"
26
+ end
27
+
28
+ if @conf.debug
29
+ $stdout.puts(mail)
30
+ return
31
+ end
32
+
33
+ mail.delivery_method :smtp, address: 'smtp.gmail.com',
34
+ port: 587,
35
+ user_name: @conf.sender_email,
36
+ password: @conf.sender_password,
37
+ authentication: :plain,
38
+ enable_starttls_auto: true
39
+ mail.deliver
40
+ end
41
+
42
+ def pairs
43
+ return @pairs if defined?(@pairs)
44
+
45
+ array_of_arrays = CSV.read(@conf.csv_file_path)
46
+ persons = Person.generate(csv_array: array_of_arrays)
47
+
48
+ @pairs = Pair.generate(persons: persons)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module SecretSantaPicker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "secret_santa_picker/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "secret_santa_picker"
8
+ spec.version = SecretSantaPicker::VERSION
9
+ spec.authors = ["Sean"]
10
+ spec.email = ["scashin133@gmail.com"]
11
+
12
+ spec.summary = %q{Quickly and secretly do secret santa}
13
+ spec.description = %q{Send emails to a list of secret santa participants}
14
+ spec.homepage = "https://github.com/scashin133/secret_santa_picker"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "mail", ">= 2.7"
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: secret_santa_picker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mail
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Send emails to a list of secret santa participants
70
+ email:
71
+ - scashin133@gmail.com
72
+ executables:
73
+ - secret_santa_picker
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/secret_santa_picker
87
+ - lib/secret_santa_picker.rb
88
+ - lib/secret_santa_picker/cli.rb
89
+ - lib/secret_santa_picker/configuration.rb
90
+ - lib/secret_santa_picker/const.rb
91
+ - lib/secret_santa_picker/pair.rb
92
+ - lib/secret_santa_picker/person.rb
93
+ - lib/secret_santa_picker/processor.rb
94
+ - lib/secret_santa_picker/version.rb
95
+ - secret_santa_picker.gemspec
96
+ homepage: https://github.com/scashin133/secret_santa_picker
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
+ rubygems_version: 3.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Quickly and secretly do secret santa
119
+ test_files: []