secret_santa_client 0.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 +7 -0
- data/README.md +54 -0
- data/lib/mobile/secret_santa.rb +70 -0
- data/spec/mobile/secret_santa_spec.rb +102 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e67311c748ff4dd088b8ff7a34325568e2d95342
|
4
|
+
data.tar.gz: c87d4b6673889d0910abe3cf7f681518654e94c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 336adf8659d7327c31ff58aca3d03d12ddec8d13bc0f4547be11b959974e0b87512959302b679aac5107f5bf15110a744fc16da166b94795e05f66983203c082
|
7
|
+
data.tar.gz: 24eb51b5ede23d8b5c50faf950872ca228ed8b0af2afb72c2b68511f7681340418bd47d697101ee8c6fffbc64492663046842da2f082119958801f7893b2eab1
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
secret_santa
|
2
|
+
============
|
3
|
+
|
4
|
+
## About
|
5
|
+
|
6
|
+
Use this to randomly generator pairing of people for Secret Santa.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Uses Twilio API to send the texts. If you want to use this you will need a [Twilio](http://www.twilio.com) account.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
|
14
|
+
```
|
15
|
+
|
16
|
+
require 'mobile/secret_santa'
|
17
|
+
|
18
|
+
list = {
|
19
|
+
"Tak" => "+13302370308",
|
20
|
+
"Sarah" => "+12079327441",
|
21
|
+
"Tania" => "+11306358563",
|
22
|
+
"Clint" => "+12212318187",
|
23
|
+
"Lydia" => "+19439348292",
|
24
|
+
"Donovan" => "+16305302371"
|
25
|
+
}
|
26
|
+
|
27
|
+
logger = Logger.new("2015_secret_santa.txt")
|
28
|
+
|
29
|
+
twilio_config = {
|
30
|
+
:account_sid => 'account-sid',
|
31
|
+
:auth_token => 'auth-token',
|
32
|
+
:host_number => 'your-twilio-host-number'
|
33
|
+
}
|
34
|
+
|
35
|
+
secret_santa = Mobile::SecretSanta.new(:list => list, :logger => logger, :twilio_config => twilio_config)
|
36
|
+
|
37
|
+
secret_santa.pair_list.send
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
## Logging
|
42
|
+
|
43
|
+
Logging is optional, but in case something goes wrong, for example someone didn't get a text, you can log the pairing. The names of the secret santa is hexdigested, in case you don't want to accidently see who everyone has.
|
44
|
+
|
45
|
+
## Features
|
46
|
+
|
47
|
+
1. Twilio Integration
|
48
|
+
2. Logging
|
49
|
+
|
50
|
+
## Future Features
|
51
|
+
|
52
|
+
1. Resend email by phone number by looking through logs
|
53
|
+
2. Blacklist pairs.
|
54
|
+
3. Any other thoughts?
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'json'
|
3
|
+
require 'digest'
|
4
|
+
require 'twilio-ruby'
|
5
|
+
|
6
|
+
module Mobile
|
7
|
+
class SecretSanta
|
8
|
+
attr_reader :names, :pairs, :logger
|
9
|
+
|
10
|
+
def initialize(options)
|
11
|
+
@list = options[:list]
|
12
|
+
@logger = options[:logger] || NoopLogger.new
|
13
|
+
@host_number = options[:twilio_config][:host_number]
|
14
|
+
@twilio_client = Twilio::REST::Client.new(options[:twilio_config][:account_sid], options[:twilio_config][:auth_token])
|
15
|
+
end
|
16
|
+
|
17
|
+
def pair_list
|
18
|
+
shuffled_names = names.shuffle
|
19
|
+
@pairs = shuffled_names.each.with_index.reduce([]) do |pair, (person, index)|
|
20
|
+
pair << {
|
21
|
+
:santa => {
|
22
|
+
:name => person, :number => @list[person]
|
23
|
+
},
|
24
|
+
:person => shuffled_names[next_person(index)]
|
25
|
+
}
|
26
|
+
pair
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def send(options = {})
|
31
|
+
pairs = @pairs.clone
|
32
|
+
pairs.each { |pair| pair[:santa][:name] = Digest::SHA256.hexdigest(pair[:santa][:name]) }
|
33
|
+
@logger.info(pairs.to_json)
|
34
|
+
|
35
|
+
pairs.each { |pair|
|
36
|
+
@twilio_client
|
37
|
+
.account
|
38
|
+
.messages
|
39
|
+
.create(payload(pair[:santa][:number], pair[:person], options[:text_body]))
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def names
|
44
|
+
@names ||= @list.keys
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def payload(number, person, text_body)
|
50
|
+
{
|
51
|
+
:from => @host_number,
|
52
|
+
:to => number,
|
53
|
+
:body => text_body != nil ? text_body.call(person) : default_text_body(person)
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def next_person(index)
|
58
|
+
(index + 1) == names.size ? 0 : index + 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_text_body(person)
|
62
|
+
"Yo Secret Santa, give this whiny little kid #{person} a gift, because we all know #{person} was a bad person this year and will be getting coal from the real Santa. Sincerly, The Cool Tak's Secret Santa #{Time.now.year}."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class NoopLogger
|
68
|
+
def initialize; end
|
69
|
+
def info(body); end
|
70
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'mobile/secret_santa'
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'logger'
|
5
|
+
require 'digest'
|
6
|
+
require 'twilio-ruby'
|
7
|
+
|
8
|
+
describe Mobile::SecretSanta do
|
9
|
+
let(:list) { {"taka" => "123-123-1234", "dave" => "321-321-4321", "eric" => "098-098-0987", "joe" => "456-456-4567"} }
|
10
|
+
let(:logger) { TestLogger.new }
|
11
|
+
let(:twilio_config) { {:account_sid => 'account-sid', :auth_token => 'auth-token', :host_number => 'host-number'} }
|
12
|
+
let(:santa) { Mobile::SecretSanta.new(:list => list, :logger => logger, :twilio_config => twilio_config) }
|
13
|
+
|
14
|
+
describe '#pair_list' do
|
15
|
+
it 'pairs up people' do
|
16
|
+
results = santa.pair_list
|
17
|
+
|
18
|
+
expect(results.length).to eq(4)
|
19
|
+
|
20
|
+
names = ["taka", "dave", "eric", "joe"]
|
21
|
+
numbers = ["123-123-1234", "321-321-4321", "098-098-0987", "456-456-4567"]
|
22
|
+
|
23
|
+
results.each do |result|
|
24
|
+
expect(numbers).to include(result[:santa][:number])
|
25
|
+
expect(names).to include(result[:santa][:name])
|
26
|
+
expect(names).to include(result[:person])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'shuffles the list' do
|
31
|
+
expect(santa.names).to receive(:shuffle).and_return([])
|
32
|
+
santa.pair_list
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'uses NoOp Logger if no logger is passed' do
|
37
|
+
secret_santa = Mobile::SecretSanta.new(:list => {}, :logger => nil, :twilio_config => twilio_config)
|
38
|
+
|
39
|
+
expect(secret_santa.logger.class).to be(NoopLogger)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'sends a text message' do
|
43
|
+
client = Twilio::REST::Client.new('account-sid', 'auth-token')
|
44
|
+
expect(Twilio::REST::Client).to receive(:new).with('account-sid', 'auth-token').and_return(client)
|
45
|
+
|
46
|
+
santa.pair_list
|
47
|
+
|
48
|
+
santa.pairs.each do |pair|
|
49
|
+
expect(client.account.messages).to receive(:create)
|
50
|
+
.with({:from => 'host-number', :to => pair[:santa][:number], :body => text_body(pair[:person])})
|
51
|
+
end
|
52
|
+
|
53
|
+
santa.send
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'can have optional block sent for building dynamic text body' do
|
57
|
+
client = Twilio::REST::Client.new('account-sid', 'auth-token')
|
58
|
+
expect(Twilio::REST::Client).to receive(:new).with('account-sid', 'auth-token').and_return(client)
|
59
|
+
|
60
|
+
santa.pair_list
|
61
|
+
|
62
|
+
santa.pairs.each do |pair|
|
63
|
+
expect(client.account.messages).to receive(:create)
|
64
|
+
.with({:from => 'host-number', :to => pair[:santa][:number], :body => "yar #{pair[:person]}"})
|
65
|
+
end
|
66
|
+
|
67
|
+
santa.send(:text_body => Proc.new {|person| "yar #{person}"})
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'logs the pairing with digested names' do
|
71
|
+
client = Twilio::REST::Client.new('account-sid', 'auth-token')
|
72
|
+
expect(Twilio::REST::Client).to receive(:new).with('account-sid', 'auth-token').and_return(client)
|
73
|
+
allow(client.account.messages).to receive(:create)
|
74
|
+
|
75
|
+
santa.pair_list
|
76
|
+
santa.send
|
77
|
+
|
78
|
+
digested_names = list.keys.reduce([]) do |names, name|
|
79
|
+
names << Digest::SHA256.hexdigest(name)
|
80
|
+
names
|
81
|
+
end
|
82
|
+
|
83
|
+
digested_names.each do |digested_name|
|
84
|
+
expect(logger.messages).to include(digested_name)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class TestLogger < Logger
|
90
|
+
def initialize
|
91
|
+
@stringIO = StringIO.new
|
92
|
+
super(@stringIO)
|
93
|
+
end
|
94
|
+
|
95
|
+
def messages
|
96
|
+
@stringIO.string
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def text_body(person)
|
101
|
+
"Yo Secret Santa, give this whiny little kid #{person} a gift, because we all know #{person} was a bad person this year and will be getting coal from the real Santa. Sincerly, The Cool Tak's Secret Santa 2015."
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secret_santa_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taka Goto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: twilio-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.6.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.6.2
|
27
|
+
description: Secret Santa Generator
|
28
|
+
email: tak.yuki@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- lib/mobile/secret_santa.rb
|
35
|
+
- spec/mobile/secret_santa_spec.rb
|
36
|
+
homepage: http://www.gototaka.com
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.4.6
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Randomly pairs your list and sends out via text.
|
60
|
+
test_files: []
|