pairing_shuffler 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pairing_shuffler/version.rb +3 -0
- data/lib/pairing_shuffler.rb +95 -0
- data.tar.gz.sig +0 -0
- metadata +96 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
require "pairing_shuffler/version"
|
2
|
+
require "google_drive"
|
3
|
+
require "net/smtp"
|
4
|
+
|
5
|
+
module PairingShuffler
|
6
|
+
def self.shuffle(config)
|
7
|
+
Shuffler.new(config).send_emails
|
8
|
+
end
|
9
|
+
|
10
|
+
class Shuffler
|
11
|
+
def initialize(config)
|
12
|
+
@config = config
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_emails
|
16
|
+
Mailer.new(@config).session do |mailer|
|
17
|
+
list.each do |emails|
|
18
|
+
mailer.notify(emails)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def content
|
26
|
+
@content ||= begin
|
27
|
+
session = GoogleDrive.login(@config.fetch(:username), @config.fetch(:password))
|
28
|
+
cells = session.spreadsheet_by_key(@config[:doc]).worksheets[0].cells
|
29
|
+
data = []
|
30
|
+
cells.each do |(row, column), value|
|
31
|
+
data[row - 1] ||= []
|
32
|
+
data[row - 1][column - 1] = value
|
33
|
+
end
|
34
|
+
data
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def list
|
39
|
+
emails = content[2..-1].map(&:first)
|
40
|
+
emails.sort_by{ rand }.each_slice(2).to_a.reject { |group| group.size == 1 }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Mailer
|
45
|
+
attr_reader :config
|
46
|
+
|
47
|
+
def initialize(config)
|
48
|
+
@config = config
|
49
|
+
end
|
50
|
+
|
51
|
+
# Google returns 535-5.7.1 on to frequent auth -> only do it once
|
52
|
+
def session
|
53
|
+
@session = true
|
54
|
+
yield self
|
55
|
+
ensure
|
56
|
+
@session = false
|
57
|
+
stop_smtp
|
58
|
+
end
|
59
|
+
|
60
|
+
def notify(emails)
|
61
|
+
subject = "PairingShuffler winners"
|
62
|
+
# FYI: if the first line is a url the email is blank in gmail
|
63
|
+
body = "Hello there!\nYou both singed up for PairingShuffler at https://docs.google.com/spreadsheet/ccc?key=#{config[:doc]}\nso let's pair!\n\nGreetings PairingShuffler"
|
64
|
+
send_email(emails, :subject => subject, :body => body)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def send_email(to, options={})
|
70
|
+
message = <<-MESSAGE.gsub(/^\s+/, "")
|
71
|
+
From: PairingShuffler <#{config.fetch(:username)}>
|
72
|
+
To: #{to.join(", ")}
|
73
|
+
Subject: #{options.fetch(:subject)}
|
74
|
+
|
75
|
+
#{options.fetch(:body)}
|
76
|
+
MESSAGE
|
77
|
+
|
78
|
+
smtp.send_message message, config.fetch(:username), to
|
79
|
+
end
|
80
|
+
|
81
|
+
def smtp
|
82
|
+
raise unless @session
|
83
|
+
@smtp ||= begin
|
84
|
+
smtp = Net::SMTP.new "smtp.gmail.com", 587
|
85
|
+
smtp.enable_starttls
|
86
|
+
smtp.start("gmail.com", config.fetch(:username), config.fetch(:password), :login)
|
87
|
+
smtp
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def stop_smtp
|
92
|
+
@smtp.finish if @smtp && @smtp.started?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pairing_shuffler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Grosser
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- !binary |-
|
13
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0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0RUZn
|
29
|
+
UVVzaU5uWEh0S2VNWVljcjR5SlZtUQpXT05MK0l3d0N3WURWUjBQQkFRREFn
|
30
|
+
U3dNQTBHQ1NxR1NJYjNEUUVCQlFVQUE0SUJBUUFseU43a0tvL05RQ1EwCkFP
|
31
|
+
elpMWjNXQWVQdlN0a0NGSUo1M3RzdjVLeW80cE1BbGx2K0JnUHp6QnQ3cWk2
|
32
|
+
MDVtRlNMNnpCZDl1TG91K1cKQ28zczQ4cDFkeTdDampBZlZRZG1WTkhGM013
|
33
|
+
WHRmQzJPRXl2U1FQaTR4S1I4aWJhOHdhM3hwOUxWbzFQdUxwdwovNkRzckNo
|
34
|
+
V3c3NEhmc0pONnFKT0s2ODRoSmVUOGxCWUFVZmlDM3dEMG93b1BTZytYdHlB
|
35
|
+
QWRkaXNSK0tWNVkxCk5tVkh1THRRY05UWnkrZ1JodDNhaEpSTXVDNlF5TG1r
|
36
|
+
VHNmKzZNYWVud0FNa0FnSGRzd0dzSnp0T25ObkJhM0YKeTBrQ1NXbUs2RCt4
|
37
|
+
L1NiZlM2cjdLZTA3TVJxemlKZEI5R3VFMSswY0lSdUZoOEVRK0xONkhYQ0tN
|
38
|
+
NXBvbi9HVQp5Y3dNWGZsMAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
40
|
+
dependencies:
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: google_drive
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
description:
|
58
|
+
email: michael@grosser.it
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- lib/pairing_shuffler/version.rb
|
64
|
+
- lib/pairing_shuffler.rb
|
65
|
+
homepage: http://github.com/grosser/pairing_shuffler
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
hash: 1949107773261800780
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
hash: 1949107773261800780
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.8.25
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Assign random pairs from a google docs spreadsheet
|
96
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|