macbot 0.1.3
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/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/macbot +3 -0
- data/bin/setup +7 -0
- data/lib/macbot.rb +49 -0
- data/lib/macbot/cli.rb +109 -0
- data/lib/macbot/metadata.rb +13 -0
- data/macbot.gemspec +30 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 29689ea45d4761c102cd780670100ec1ec28b5bb
|
4
|
+
data.tar.gz: f803acc1edd89e031551d90b18b6e74312b83bc0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 664b9559471b608bdb088f65fa5912cf7c05ba60e3d489d9f8a7f33ad658bde0c7887e3e2cf01264cf711622a34090152fb5c5a833e0af063f67a6665a0a9ccf
|
7
|
+
data.tar.gz: 7f67484c32779cd36a30047b59a2b6419e485e17efff8daa6e247136f554cf34db67255b524a0786923e623b512b86ff2c5577d7dec023d157791fc277683921
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Macbot
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/macbot`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'macbot'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install macbot
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/macbot/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "macbot"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/macbot
ADDED
data/bin/setup
ADDED
data/lib/macbot.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'macbot/metadata'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Macbot
|
5
|
+
# Your code goes here...
|
6
|
+
|
7
|
+
MAIL_START = <<-END
|
8
|
+
tell application "Mail"
|
9
|
+
END
|
10
|
+
|
11
|
+
MAIL_END = <<-END
|
12
|
+
end tell
|
13
|
+
END
|
14
|
+
|
15
|
+
def self.accounts(type, options)
|
16
|
+
enable = enabled(options)
|
17
|
+
data = YAML.load_file(Macbot::YAML_PATH)
|
18
|
+
emails = data[type]
|
19
|
+
string = ''
|
20
|
+
string += build_string(emails, enable)
|
21
|
+
string += enable_zen(emails, enable) if options.zen
|
22
|
+
|
23
|
+
MAIL_START + string + MAIL_END
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.enabled(options)
|
29
|
+
return true if options.enable
|
30
|
+
return false if options.disable
|
31
|
+
puts 'what?'
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.enable_zen(const, enable)
|
35
|
+
puts 'enable zen mode'
|
36
|
+
build_string((Macbot::EMAIL_GROUPS - const), !enable)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.build_string(arr, enable)
|
40
|
+
string = ''
|
41
|
+
arr.each do |account|
|
42
|
+
puts "set #{account} to #{enable}"
|
43
|
+
string << <<-END
|
44
|
+
set enabled of account "#{account.to_s}" to #{enable}
|
45
|
+
END
|
46
|
+
end
|
47
|
+
string
|
48
|
+
end
|
49
|
+
end
|
data/lib/macbot/cli.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'macbot'
|
2
|
+
require 'pathname'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Macbot
|
6
|
+
class Cli
|
7
|
+
require 'commander/import'
|
8
|
+
require 'commander/user_interaction'
|
9
|
+
|
10
|
+
program :name, 'macbot'
|
11
|
+
program :version, Macbot::VERSION
|
12
|
+
program :description, Macbot::SUMMARY
|
13
|
+
|
14
|
+
Macbot::EMAIL_GROUPS.each do |type|
|
15
|
+
command type.to_sym do |c|
|
16
|
+
c.syntax = "#{type} [options]"
|
17
|
+
c.description = "Enable/disable #{type}-accounts"
|
18
|
+
c.option '--zen', 'Enter zen mode, disable all other accounts'
|
19
|
+
c.option '--enable', 'Enable accounts'
|
20
|
+
c.option '--disable', 'Disable accounts'
|
21
|
+
c.action do |_args, options|
|
22
|
+
applescript Macbot.accounts(type, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
command :add do |c|
|
28
|
+
c.syntax = 'add [options]'
|
29
|
+
c.description = 'add values to yml file'
|
30
|
+
c.option '--group STRING', String, 'Create email group'
|
31
|
+
c.option '--account STING', String, 'Add email to group'
|
32
|
+
c.action do |args, options|
|
33
|
+
abort("Missing group") unless options.group
|
34
|
+
data = YAML.load_file(Macbot::YAML_PATH)
|
35
|
+
|
36
|
+
unless data[options.group]
|
37
|
+
data[options.group] = []
|
38
|
+
puts "Created new email group: #{options.group}"
|
39
|
+
end
|
40
|
+
|
41
|
+
if options.account
|
42
|
+
data[options.group].each do |h|
|
43
|
+
if h.to_s == options.account.to_s
|
44
|
+
abort "The email #{options.account} is already in group #{options.group}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
data[options.group] << options.account
|
48
|
+
puts "Added #{options.account} to group #{options.group}"
|
49
|
+
else
|
50
|
+
abort("This group already exist, add email to group by writing \nmacbot add --group #{options.group} --account your email address")
|
51
|
+
end
|
52
|
+
|
53
|
+
File.open(Macbot::YAML_PATH, 'w') { |f| YAML.dump(data, f) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
command :remove do |c|
|
58
|
+
c.syntax = 'remove [options]'
|
59
|
+
c.description = 'remove values from yml file'
|
60
|
+
c.option '--group STRING', String, 'remove email group'
|
61
|
+
c.option '--account STING', String, 'remove email from group'
|
62
|
+
c.action do |args, options|
|
63
|
+
abort("Missing group") unless options.group
|
64
|
+
data = YAML.load_file(Macbot::YAML_PATH)
|
65
|
+
|
66
|
+
if options.account
|
67
|
+
data[options.group].each do |e|
|
68
|
+
if e.to_s == options.account
|
69
|
+
data[options.group].delete(e)
|
70
|
+
File.open(Macbot::YAML_PATH, 'w') { |f| YAML.dump(data, f) }
|
71
|
+
puts "The email #{options.account} was deleted from group #{options.group}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
if agree("Are u sure? This will remove affect these emails #{data[options.group]}")
|
76
|
+
data.delete(options.group)
|
77
|
+
File.open(Macbot::YAML_PATH, 'w') { |f| YAML.dump(data, f) }
|
78
|
+
puts "Removed group #{options.group}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
command :setup do |c|
|
85
|
+
c.syntax = 'setup'
|
86
|
+
c.description = 'creat yml file'
|
87
|
+
c.action do |args, options|
|
88
|
+
if File.exists? Macbot::YAML_PATH
|
89
|
+
unless agree("Are u sure?")
|
90
|
+
abort "Ok, I didn't remove anything"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
out_file = File.new(Macbot::YAML_PATH, "w")
|
94
|
+
out_file.puts('work:')
|
95
|
+
out_file.puts('private:')
|
96
|
+
out_file.close
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
command :read do |c|
|
101
|
+
c.syntax = 'read'
|
102
|
+
c.description = 'read yml file'
|
103
|
+
c.action do |args, options|
|
104
|
+
data = YAML.load_file(Macbot::YAML_PATH)
|
105
|
+
puts data
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Macbot
|
4
|
+
VERSION = '0.1.3'
|
5
|
+
NAME = 'Macbot'
|
6
|
+
SUMMARY = 'Set it up to disable/enable accounts'
|
7
|
+
YAML_PATH = 'email.yml'
|
8
|
+
EMAIL_GROUPS = if File.exists? Macbot::YAML_PATH
|
9
|
+
YAML.load_file(Macbot::YAML_PATH).keys
|
10
|
+
else
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
end
|
data/macbot.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'macbot/metadata'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "macbot"
|
8
|
+
spec.version = Macbot::VERSION
|
9
|
+
spec.authors = ["Hilde Vestol"]
|
10
|
+
spec.email = ["hilde@rubynor.com"]
|
11
|
+
|
12
|
+
spec.summary = Macbot::SUMMARY
|
13
|
+
spec.description = Macbot::SUMMARY
|
14
|
+
spec.homepage = "https://github.com/hildevestol/macbot"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "bin"
|
18
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.executables = ["macbot"]
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# if spec.respond_to?(:metadata)
|
23
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.add_dependency 'commander', '~> 4.1.5'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: macbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hilde Vestol
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-05 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.1.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.1.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Set it up to disable/enable accounts
|
56
|
+
email:
|
57
|
+
- hilde@rubynor.com
|
58
|
+
executables:
|
59
|
+
- macbot
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/macbot
|
71
|
+
- bin/setup
|
72
|
+
- lib/macbot.rb
|
73
|
+
- lib/macbot/cli.rb
|
74
|
+
- lib/macbot/metadata.rb
|
75
|
+
- macbot.gemspec
|
76
|
+
homepage: https://github.com/hildevestol/macbot
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.2.0
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Set it up to disable/enable accounts
|
99
|
+
test_files: []
|