idid 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/idid +18 -0
- data/idid.gemspec +23 -0
- data/lib/idid/configuration.rb +74 -0
- data/lib/idid/interactive.rb +63 -0
- data/lib/idid/version.rb +3 -0
- data/lib/idid.rb +58 -0
- data/spec/idid/configuration_spec.rb +28 -0
- data/spec/spec_helper.rb +4 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Wouter de Vos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Idid
|
2
|
+
|
3
|
+
Ruby CLI to [iDoneThis](http://idonethis.com).
|
4
|
+
|
5
|
+
## Usage (easy)
|
6
|
+
|
7
|
+
$ idid Something awesome that my colleagues should know about.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'idid'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install idid
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/idid
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/idid', __FILE__)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
begin
|
8
|
+
config = Idid::Configuration.new
|
9
|
+
rescue
|
10
|
+
config = Idid::Interactive.create_config
|
11
|
+
config.write
|
12
|
+
end
|
13
|
+
|
14
|
+
puts ARGV
|
15
|
+
Idid.configuration = config
|
16
|
+
Idid.send ARGV
|
17
|
+
|
18
|
+
puts 'done'
|
data/idid.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'idid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "idid"
|
8
|
+
gem.version = Idid::VERSION
|
9
|
+
gem.authors = ["Wouter de Vos"]
|
10
|
+
gem.email = ["wrdevos@gmail.com"]
|
11
|
+
gem.description = %q{A Ruby CLI for iDoneThis}
|
12
|
+
gem.summary = %q{Post to iDoneThis from your command line.}
|
13
|
+
gem.homepage = "https://github.com/foxycoder/idid"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec', '~> 2.12.0'
|
21
|
+
|
22
|
+
gem.add_runtime_dependency 'mail', '~> 2.5.3'
|
23
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Idid
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
SMTP_DEFAULTS = {
|
5
|
+
:address => 'smtp.gmail.com',
|
6
|
+
:port => '587',
|
7
|
+
:user_name => ENV['GMAIL_SMTP_USER'],
|
8
|
+
:password => ENV['GMAIL_SMTP_PASSWORD'],
|
9
|
+
:authentication => :plain,
|
10
|
+
:enable_starttls_auto => true
|
11
|
+
}
|
12
|
+
|
13
|
+
EXIM_DEFAULTS = {
|
14
|
+
:location => '/usr/bin/exim'
|
15
|
+
}
|
16
|
+
|
17
|
+
# Public: Name of the project to post to (e.g. project.idonethis.com)
|
18
|
+
attr_accessor :project
|
19
|
+
# Public: Email address String to use when sending mail.
|
20
|
+
attr_accessor :email
|
21
|
+
# Public: Email delivery configuration
|
22
|
+
attr_accessor :delivery
|
23
|
+
|
24
|
+
# Public: configuration to use with iDoneThis
|
25
|
+
#
|
26
|
+
# options - Hash with configuration options
|
27
|
+
# project - Name of the project to post to (e.g.
|
28
|
+
# project.idonethis.com)
|
29
|
+
# email - Email address to use when sending mail.
|
30
|
+
# delivery - Email delivery configuration Hash:
|
31
|
+
# method - Symbol (:smtp|:sendmail|:exim)
|
32
|
+
# options - Configuration Hash for the
|
33
|
+
# delivery method (see:
|
34
|
+
# https://github.com/mikel/mail).
|
35
|
+
#
|
36
|
+
# Returns a new Idid::Configuration instance
|
37
|
+
def initialize options = {}
|
38
|
+
options = options.merge(read_config) if read_config
|
39
|
+
raise ArgumentError.new("Provide a project to use.") unless options['project']
|
40
|
+
raise ArgumentError.new("Provide an email address.") unless options['email']
|
41
|
+
raise ArgumentError.new("Provide a delivery method.") unless options['delivery']
|
42
|
+
|
43
|
+
@project = options['project']
|
44
|
+
@email = options['email']
|
45
|
+
@delivery = options['delivery']
|
46
|
+
end
|
47
|
+
|
48
|
+
def write
|
49
|
+
config = {
|
50
|
+
'project' => project,
|
51
|
+
'email' => email,
|
52
|
+
'delivery' => delivery
|
53
|
+
}
|
54
|
+
|
55
|
+
File.open(self.class.config_file, 'w') do |f|
|
56
|
+
f.write config.to_yaml
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def read_config
|
61
|
+
@config ||= self.class.read_config
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.read_config
|
65
|
+
if File.exist? config_file
|
66
|
+
config = YAML.load_file config_file
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.config_file
|
71
|
+
File.join( ENV['HOME'], '.idid.yml' )
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Idid
|
2
|
+
module Interactive
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def create_config
|
6
|
+
status "Please take a moment to create a new configuration.."
|
7
|
+
config = user_config
|
8
|
+
config['delivery'] ||= {}
|
9
|
+
user_config_from_key 'project',
|
10
|
+
"What is the name of your iDoneThis project (look at the url: <project>.idonethis.com)", nil, config
|
11
|
+
user_config_from_key 'email', "What is your associated email address for this iDoneThis project?", nil, config
|
12
|
+
user_config_from_key 'method', "How do you want to send emails to iDoneThis? (smtp, sendmail, exim)", 'smtp', config['delivery']
|
13
|
+
|
14
|
+
case config['delivery']['method']
|
15
|
+
when 'smtp'
|
16
|
+
delivery_options = Idid::Configuration::SMTP_DEFAULTS
|
17
|
+
when 'exim'
|
18
|
+
delivery_options = Idid::Configuration::EXIM_DEFAULTS
|
19
|
+
else
|
20
|
+
delivery_options = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
config['delivery']['options'] ||= {}
|
24
|
+
delivery_options.each do |key, default|
|
25
|
+
user_config_from_key key, key.to_s, default, config['delivery']['options']
|
26
|
+
end
|
27
|
+
|
28
|
+
Idid::Configuration.new(config)
|
29
|
+
end
|
30
|
+
|
31
|
+
def user_config_from_key(key, text, default, config = nil)
|
32
|
+
config ||= user_config
|
33
|
+
|
34
|
+
config[key.to_s] ||=
|
35
|
+
begin
|
36
|
+
ask "#{text} [#{default}]:"
|
37
|
+
input_or_default default
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def user_config
|
42
|
+
Idid::Configuration.read_config || {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def status(text)
|
46
|
+
puts "\e[36m#{text}\e[0m"
|
47
|
+
end
|
48
|
+
|
49
|
+
def fail(text='Failed!')
|
50
|
+
puts "\e[31m#{text}\e[0m"
|
51
|
+
end
|
52
|
+
|
53
|
+
def ask(question)
|
54
|
+
puts "\e[32m#{question}\e[0m"
|
55
|
+
end
|
56
|
+
|
57
|
+
def input_or_default(default)
|
58
|
+
val = STDIN.gets.chomp
|
59
|
+
val.size == 0 ? default : val
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/idid/version.rb
ADDED
data/lib/idid.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'mail'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
Dir[File.expand_path("../idid/**/*.rb", __FILE__)].each {|f| require f}
|
5
|
+
|
6
|
+
module Idid
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
|
10
|
+
def send *words
|
11
|
+
setup_delivery
|
12
|
+
Mail.deliver do
|
13
|
+
from Idid.configuration.email
|
14
|
+
to "#{Idid.configuration.project}@team.idonethis.com"
|
15
|
+
subject "I did this"
|
16
|
+
body words.flatten.join(" ")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup_delivery
|
21
|
+
method = Idid.configuration.delivery['method']
|
22
|
+
options = Idid.configuration.delivery['options'] || {}
|
23
|
+
|
24
|
+
options.keys.each do |key|
|
25
|
+
options[(key.to_sym rescue key) || key] = options.delete(key)
|
26
|
+
end
|
27
|
+
|
28
|
+
puts options
|
29
|
+
|
30
|
+
case method
|
31
|
+
when 'smtp'
|
32
|
+
setup_smtp options
|
33
|
+
when 'sendmail'
|
34
|
+
setup_sendmail
|
35
|
+
when 'exim'
|
36
|
+
setup_exim options
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup_smtp options = {}
|
41
|
+
Mail.defaults do
|
42
|
+
delivery_method :smtp, Idid::Configuration::SMTP_DEFAULTS.merge(options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def setup_sendmail
|
47
|
+
Mail.defaults do
|
48
|
+
delivery_method :sendmail
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_exim options={}
|
53
|
+
Mail.defaults do
|
54
|
+
delivery_method :exim, Idid::Configuration::EXIM_DEFAULTS.merge(options)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Idid::Configuration do
|
4
|
+
subject { Idid::Configuration.new('project' => project, 'email' => email, 'delivery' => delivery) }
|
5
|
+
let(:email) { 'foo@example.com' }
|
6
|
+
let(:project) { 'foobar' }
|
7
|
+
let(:delivery) { {:method => :sendmail} }
|
8
|
+
|
9
|
+
before { Idid::Configuration.any_instance.stub(:read_config) { nil } }
|
10
|
+
|
11
|
+
its('project') { should eq project }
|
12
|
+
its('email') { should eq email }
|
13
|
+
|
14
|
+
it 'raises ArgumentError if no email option is passed' do
|
15
|
+
expect { Idid::Configuration.new('project' => project, 'delivery' => delivery) }.
|
16
|
+
to raise_error(ArgumentError, /email/)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raises ArgumentError if no project option is passed' do
|
20
|
+
expect { Idid::Configuration.new('email' => email, 'delivery' => delivery) }.
|
21
|
+
to raise_error(ArgumentError, /project/)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raises ArgumentError if no delivery option is passed' do
|
25
|
+
expect { Idid::Configuration.new('email' => email, 'project' => project) }.
|
26
|
+
to raise_error(ArgumentError, /delivery/)
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wouter de Vos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.12.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.12.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mail
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.5.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.3
|
46
|
+
description: A Ruby CLI for iDoneThis
|
47
|
+
email:
|
48
|
+
- wrdevos@gmail.com
|
49
|
+
executables:
|
50
|
+
- idid
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/idid
|
60
|
+
- idid.gemspec
|
61
|
+
- lib/idid.rb
|
62
|
+
- lib/idid/configuration.rb
|
63
|
+
- lib/idid/interactive.rb
|
64
|
+
- lib/idid/version.rb
|
65
|
+
- spec/idid/configuration_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: https://github.com/foxycoder/idid
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.23
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Post to iDoneThis from your command line.
|
91
|
+
test_files:
|
92
|
+
- spec/idid/configuration_spec.rb
|
93
|
+
- spec/spec_helper.rb
|