trikle-mail 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/trikle-mail +83 -0
  3. metadata +74 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 938e28752ad9c882ad4194f0ddc3b58885c88e59
4
+ data.tar.gz: 64f9649f7e02182b4c6c6ec137d78ff4c56b3bbf
5
+ SHA512:
6
+ metadata.gz: 8aad80a56e53f0cefa51fa6996f9f49c0be3fe909aecf8a4948415cf8dfd89bd87bc48130bfbdce405c6f569110140ae630ddd6d9cc3b0dcfa4a77d56eca662a
7
+ data.tar.gz: ffaf61553fd8323f83567788d8623f1d80bb891f29e93b30ef05e0f98ad9bef6032bd9ffc5fdfe8a0b37ccda561479c25c29b33cef629784a5cc8dbb5c5e7051
data/bin/trikle-mail ADDED
@@ -0,0 +1,83 @@
1
+ #! /usr/bin/env ruby
2
+ require 'commander'
3
+ require 'mandrill'
4
+ require 'csv'
5
+
6
+ class TrikleMail
7
+ extend Commander::Methods
8
+
9
+ program :name, 'Trikle Mail'
10
+ program :version, '0.0.0'
11
+ program :description, 'Send your bulk email in a trikle over the mandril api'
12
+
13
+ default_command :run
14
+
15
+ command :run do |c|
16
+ c.syntax = 'trikle-mail csv_of_emails.csv [options]'
17
+ c.description = 'Send a message to each email address in the csv'
18
+ c.option '--apikey STRING', String, 'The Mandrill API key'
19
+ c.option '--from_email STRING', String, 'The email address of the sender'
20
+ c.option '--from_name STRING', String, 'The name of the sender'
21
+ c.option '--subject STRING', String, 'The subject line of the message'
22
+ c.option '--template STRING', String, 'The template slug of the message template'
23
+ c.option '--hours INTEGER', Integer, 'The number of hours over which to send the emails'
24
+ c.option '--minutes INTEGER', Integer, 'The number of minutes over which to send the emails'
25
+
26
+ c.action do |args, options|
27
+ api = Mandrill::API.new(options.apikey)
28
+
29
+ title_row, *data_rows = CSV.read(args[0])
30
+
31
+ data_hashes = data_rows.map do |row|
32
+ title_row.map.with_index do |title, index|
33
+ [title.downcase, row[index]]
34
+ end.to_h
35
+ end
36
+
37
+ options.default({hours: 0, minutes: 0})
38
+ time_range = ((options.hours * 60 * 60) + (options.minutes * 60)) /
39
+ data_hashes.length.to_f
40
+
41
+ data_hashes.each do |hash|
42
+ response = api.messages.send_template(
43
+ hash['template'] || options.template,
44
+ [],
45
+ {
46
+ subject: hash['subject'] || options.subject,
47
+ from_email: hash['from_email'] || options.from_email,
48
+ from_name: hash['from_name'] || options.from_name,
49
+ to: [{
50
+ email: hash['email'],
51
+ name: hash['name'],
52
+ type: 'to'
53
+ }],
54
+ merge_vars: [{
55
+ rcpt: hash['email'],
56
+ vars: hash.map { |key, value| { name: key, content: value } }
57
+ }]
58
+ }
59
+ )
60
+ TrikleMail.log(response)
61
+ random_wait_time = rand(0..time_range)
62
+ puts "waiting #{random_wait_time} seconds"
63
+ sleep(random_wait_time)
64
+ end
65
+ end
66
+ end
67
+
68
+ def self.log(json)
69
+ Array(json).each do |entry|
70
+ # write to log file
71
+ File.open('./log.json', 'a') { |f| f.write(JSON.dump(entry) + "\n") }
72
+ # write nicely to cli
73
+ puts [
74
+ entry['status'],
75
+ 'email to',
76
+ entry['email'],
77
+ entry['reject_reason'] ? "becuase #{entry['reject_reason']}" : ''
78
+ ].join(' ')
79
+ end
80
+ end
81
+ end
82
+
83
+ TrikleMail.run!
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trikle-mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jasper Lyons
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mandrill-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ description: Send bulk email in a trickle over mandrill
42
+ email: jasper.lyons@gmail.com
43
+ executables:
44
+ - trikle-mail
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/trikle-mail
49
+ homepage: ''
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.5.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Send a trickle of mail
73
+ test_files: []
74
+ has_rdoc: