secretsanta 1.0.0

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
+ SHA256:
3
+ metadata.gz: cbcf51da2f07ca310dfd840ad9f2a3e74d3e78a42fee8a8f9f9b08f9c2cd6820
4
+ data.tar.gz: a83d8971943f61a728ae651ca6b079420be9efd6eb8ec871652b281da69683ae
5
+ SHA512:
6
+ metadata.gz: 672007cf00c50a4133d71a58e6bf50735112f44df171888957bb67002ca545365bd6d2e920f0ba9f6bf13e3914fd81768aae1a7099fb992860bef08371f498b5
7
+ data.tar.gz: b1726b59b5c68b058296887a3e852403f8c4db194546a4b24a9b15a6b3ceef5893185f2101ce6295447e9022e29dc602a20c739c058ad34c9c244951ef5522a7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .env
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ Layout/IndentationWidth:
2
+ Width: 2
3
+
4
+ Metrics/AbcSize:
5
+ Max: 20
6
+
7
+ Metrics/BlockLength:
8
+ Max: 50
9
+
10
+ Metrics/LineLength:
11
+ Max: 120
12
+
13
+ Metrics/MethodLength:
14
+ Max: 25
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Style/TrailingCommaInHashLiteral:
20
+ EnforcedStyleForMultiline: consistent_comma
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ secretsanta (1.0.0)
5
+ dotenv
6
+ twilio-ruby
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ansi (1.5.0)
12
+ ast (2.4.0)
13
+ builder (3.2.3)
14
+ coderay (1.1.2)
15
+ dotenv (2.5.0)
16
+ faraday (0.15.4)
17
+ multipart-post (>= 1.2, < 3)
18
+ jaro_winkler (1.5.1)
19
+ jwt (2.1.0)
20
+ method_source (0.9.2)
21
+ mini_portile2 (2.3.0)
22
+ minitest (5.11.3)
23
+ minitest-reporters (1.3.5)
24
+ ansi
25
+ builder
26
+ minitest (>= 5.0)
27
+ ruby-progressbar
28
+ multipart-post (2.0.0)
29
+ nokogiri (1.8.5)
30
+ mini_portile2 (~> 2.3.0)
31
+ parallel (1.12.1)
32
+ parser (2.5.3.0)
33
+ ast (~> 2.4.0)
34
+ powerpack (0.1.2)
35
+ pry (0.12.2)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.9.0)
38
+ rainbow (3.0.0)
39
+ rake (10.5.0)
40
+ rubocop (0.60.0)
41
+ jaro_winkler (~> 1.5.1)
42
+ parallel (~> 1.10)
43
+ parser (>= 2.5, != 2.5.1.1)
44
+ powerpack (~> 0.1)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (~> 1.4.0)
48
+ ruby-progressbar (1.10.0)
49
+ twilio-ruby (5.17.0)
50
+ faraday (~> 0.9)
51
+ jwt (>= 1.5, <= 2.5)
52
+ nokogiri (>= 1.6, < 2.0)
53
+ unicode-display_width (1.4.0)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ bundler (~> 1.17)
60
+ minitest (~> 5.0)
61
+ minitest-reporters (~> 1.3)
62
+ pry
63
+ rake (~> 10.0)
64
+ rubocop
65
+ secretsanta!
66
+
67
+ BUNDLED WITH
68
+ 1.17.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ty-Lucas Kelley <tylucaskelley@gmail.com> (https://tylucaskelley.com)
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.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # SecretSanta
2
+
3
+ > Send a text message to let everyone know their Secret Santa recipient!
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'secretsanta'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install secretsanta
22
+
23
+ ## Usage
24
+
25
+ First, head on over to [Twilio](https://www.twilio.com/console) and get a phone number with texting capabilities. You
26
+ can then run `secretsanta` from the command line (see below).
27
+
28
+ Example:
29
+
30
+ $ secretsanta -a ACCOUNT_SID -t AUTH_TOKEN -f FROM_NUMBER -p PARTICIPANTS_FILE
31
+
32
+ Alternatively, set the following environment variables:
33
+
34
+ - `TWILIO_ACCOUNT_SID`
35
+ - `TWILIO_AUTH_TOKEN`
36
+ - `TWILIO_PHONE_NUMBER`
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
41
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
44
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
45
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/tylucaskelley/secret-santa).
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ task default: :test
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'test'
10
+ t.libs << 'lib'
11
+ t.test_files = FileList['test/**/*_test.rb']
12
+ end
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'pry'
7
+
8
+ require 'secretsanta'
9
+
10
+ Pry.start
data/bin/secretsanta ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'dotenv'
6
+ require 'optparse'
7
+ require 'ostruct'
8
+
9
+ require_relative '../lib/secretsanta'
10
+
11
+ Dotenv.load
12
+
13
+ begin
14
+ options = OpenStruct.new
15
+
16
+ options.twilio_account_sid = ENV['TWILIO_ACCOUNT_SID']
17
+ options.twilio_auth_token = ENV['TWILIO_AUTH_TOKEN']
18
+ options.from_number = ENV['TWILIO_PHONE_NUMBER']
19
+ options.dry_run = ENV['ENVIRONMENT'] == 'TEST'
20
+ options.participants = nil
21
+
22
+ opt_parser = OptionParser.new do |opts|
23
+ opts.banner = SecretSanta.help_text
24
+
25
+ opts.on '-h', '--help', 'Show this help message' do
26
+ puts opts
27
+ exit
28
+ end
29
+
30
+ opts.on '-a', '--twilio-account-sid=SID', 'Twilio AccountSID' do |sid|
31
+ options.twilio_account_sid = sid
32
+ end
33
+
34
+ opts.on '-t', '--twilio-auth-token=TOKEN', 'Twilio authentication token' do |token|
35
+ options.twilio_auth_token = token
36
+ end
37
+
38
+ opts.on '-f', '--from_number=NUM', 'Twilio phone number' do |num|
39
+ options.from_number = num
40
+ end
41
+
42
+ opts.on '-p', '--participants=JSON_FILE', 'JSON file with participants' do |participants_file|
43
+ options.participants = JSON.parse(File.read(participants_file), symbolize_names: true)[:participants]
44
+ rescue StandardError => e
45
+ puts e
46
+ exit 1
47
+ end
48
+ end
49
+
50
+ opt_parser.parse!(ARGV)
51
+
52
+ raise OptionParser::MissingArgument if options.to_h.values.any?(&:nil?)
53
+
54
+ begin
55
+ puts SecretSanta.notify_participants!(options)
56
+ rescue SecretSanta::Error => e
57
+ puts e
58
+ exit 1
59
+ end
60
+ rescue OptionParser::MissingArgument
61
+ puts "All options are required, see help below:\n\n"
62
+ puts opt_parser.help
63
+ end
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+ set -vx
6
+
7
+ bundle check || bundle install
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'twilio-ruby'
4
+
5
+ require_relative 'secretsanta/version'
6
+
7
+ module SecretSanta
8
+ class Error < StandardError; end
9
+
10
+ module_function
11
+
12
+ def notify_participants!(options)
13
+ client = Twilio::REST::Client.new(options.twilio_account_sid, options.twilio_auth_token)
14
+ pairs = generate_pairs(options.participants)
15
+
16
+ return pairs if options.dry_run
17
+
18
+ pairs.each do |pair|
19
+ client.messages.create(
20
+ body: "Happy holidays! You have been assigned to give a gift to #{pair.recipient_name} this year.",
21
+ from: options.from_number,
22
+ to: pair.sender_number
23
+ )
24
+ rescue Twilio::Rest::TwilioError => e
25
+ puts e.message
26
+ end
27
+
28
+ "\nAll participants have been notified - happy holidays! 🎅 🎄 🎁\n\n"
29
+ end
30
+
31
+ def generate_pairs(participants)
32
+ [].tap do |list|
33
+ loop do
34
+ participants.each do |participant|
35
+ index = rand 0..participants.length - 1
36
+ recipient = participants[index]
37
+
38
+ next if try_again?(participant, recipient)
39
+
40
+ list << { sender_number: participant[:number], recipient_name: recipient[:name] }
41
+
42
+ participant[:has_assignment] = true
43
+ participants[index][:is_assigned] = true
44
+ end
45
+
46
+ break if done?(participants)
47
+ end
48
+ end
49
+ end
50
+
51
+ def try_again?(sender, recipient)
52
+ disallowed = !sender[:disallow].nil? && sender[:disallow].include?(recipient[:name])
53
+
54
+ return true if disallowed || sender[:has_assignment] || recipient[:is_assigned]
55
+ end
56
+
57
+ def done?(participants)
58
+ participants.all? { |p| p[:has_assignment] && p[:is_assigned] }
59
+ end
60
+
61
+ def help_text
62
+ <<~HEREDOC
63
+ SecretSanta, version #{VERSION}
64
+
65
+ To run, provide command-line arguments or set corresponding environment variables:
66
+
67
+ - TWILIO_ACCOUNT_SID
68
+ - TWILIO_AUTH_TOKEN
69
+ - TWILIO_PHONE_NUMBER
70
+
71
+ Command-line arguments:
72
+
73
+ HEREDOC
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module SecretSanta
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'secretsanta/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'secretsanta'
9
+ spec.version = SecretSanta::VERSION
10
+ spec.authors = ['Ty-Lucas Kelley']
11
+ spec.email = ['tylucaskelley@gmail.com']
12
+
13
+ spec.summary = 'Start a gift exchange from the command line'
14
+ spec.homepage = 'https://github.com/tylucaskelley/secret-santa'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.executables = ['secretsanta']
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'dotenv'
24
+ spec.add_dependency 'twilio-ruby'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.17'
27
+ spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'minitest-reporters', '~> 1.3'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rubocop'
32
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: secretsanta
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ty-Lucas Kelley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: twilio-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - tylucaskelley@gmail.com
128
+ executables:
129
+ - secretsanta
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/secretsanta
143
+ - bin/setup
144
+ - lib/secretsanta.rb
145
+ - lib/secretsanta/version.rb
146
+ - secretsanta.gemspec
147
+ homepage: https://github.com/tylucaskelley/secret-santa
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.7.6
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Start a gift exchange from the command line
171
+ test_files: []