babot 0.3.1 → 0.4.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 (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/babot.gemspec +2 -2
  4. data/bin/babot +51 -21
  5. data/lib/babot.rb +2 -78
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d30a84bef581bba5e575f75254eddf1fa28dca37
4
- data.tar.gz: c9450ed722b8fcc6add142a6207ff9c95f2048df
3
+ metadata.gz: 53807523166eb1aa1598787184bcacf42dd60c83
4
+ data.tar.gz: 969f1946c3b071902ef1cb03102a29136bb99915
5
5
  SHA512:
6
- metadata.gz: f3226467734a2827f618b9a074d70f0f3aa23191478755631f82733800b83275832ce3e7da4ddedad54bd1f14c25359236ee4f950bdc04fa3d0aa0ab34eed01d
7
- data.tar.gz: 257cb4fffdd5c6eeb5df4d671ebff99b1ac859a39f46b16575a4af5ad52384514a8fa551f80320362557566359d60b6cf7cd464365abf9b7df8a7dd48ccc90c7
6
+ metadata.gz: 91f53fd6de6c569db584e07658254044ba769ae49095acd294c4216aeb1bc7cce73d5536c6f6dce50c5ff69c4c0fc022e647b9c83900327065a49f59b58aec25
7
+ data.tar.gz: ef00c38a7e27542ff1ea83f758b1970c0230fc45bd4444705a0c1ee4656c51a7bf909253570e67aa04454048d6d6c4626276d4056237d04b118e79eaef8b54dd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- babot (0.3.1)
4
+ babot (0.4.0)
5
5
  boson
6
6
  twitter
7
7
  whenever
@@ -22,7 +22,7 @@ GEM
22
22
  multipart-post (~> 1.2.0)
23
23
  i18n (0.6.4)
24
24
  minitest (4.7.5)
25
- multi_json (1.7.8)
25
+ multi_json (1.7.9)
26
26
  multipart-post (1.2.0)
27
27
  simple_oauth (0.2.0)
28
28
  thread_safe (0.1.2)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'babot'
3
- s.version = '0.3.1'
4
- s.date = '2013-09-08'
3
+ s.version = '0.4.0'
4
+ s.date = '2013-11-08'
5
5
  s.summary = "Babot"
6
6
  s.description = "A simple tool to manage Twitter bots"
7
7
  s.authors = ["Victor Goya"]
data/bin/babot CHANGED
@@ -1,62 +1,92 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'boson/runner'
4
+ require 'pathname'
5
+ require 'yaml'
4
6
 
5
7
  $:.unshift File.expand_path("../../lib", __FILE__)
6
8
  require 'babot'
7
9
 
8
- FileUtils.mkdir_p Babot.root
10
+ DEFAULT_CONFIG = {
11
+ 'consumer_key' => "",
12
+ 'consumer_secret' => "",
13
+ 'oauth_token' => "",
14
+ 'oauth_token_secret' => ""
15
+ }
9
16
 
10
17
  class BabotRunner < Boson::Runner
18
+ def initialize
19
+ cmd "mkdir -p '#{root}'"
20
+ end
21
+
22
+ desc "Add bot [name] from [repository]"
23
+ def add(name, repository)
24
+ if File.directory? repository
25
+ cmd "ln -s '#{File.realpath repository}' '#{root.join(name)}'"
26
+ else
27
+ cmd "git clone '#{repository}' '#{root.join(name)}'"
28
+ end
29
+ cmd "mkdir -p '#{Pathname.new(root).join name, 'config'}'"
30
+
31
+ File.open(root.join(name, "config", "credentials.yml").to_s, 'w') do |config|
32
+ config.write DEFAULT_CONFIG.to_yaml
33
+ end
34
+ configure name
35
+ end
36
+
11
37
  desc "Update bot [name]"
12
38
  def update(name)
13
- Babot.update(name)
39
+ cmd "cd '#{root.join(name)}' && git pull --rebase origin master && bundle install"
14
40
  end
15
41
 
16
42
  desc "Update crontab"
17
43
  def schedule
18
- Babot.schedule
44
+ `ls #{root}`.split.each do |name|
45
+ cmd "whenever -i #{name} -f #{root.join(name, 'config', 'schedule.rb')}"
46
+ end
19
47
  end
20
48
 
21
49
  desc "Run bot [name]"
22
50
  def run(name)
23
- Babot.run name
24
- end
51
+ options = YAML::load_file root.join(name, "config", 'credentials.yml')
25
52
 
26
- desc "Add bot [name] from [repository]"
27
- def add(name, repository)
28
- Babot.add name, repository
29
- Babot.configure name
53
+ Twitter.configure do |config|
54
+ config.consumer_key = options['consumer_key']
55
+ config.consumer_secret = options['consumer_secret']
56
+ config.oauth_token = options['oauth_token']
57
+ config.oauth_token_secret = options['oauth_token_secret']
58
+ end
59
+ load root.join(name, 'babot.run').to_s
30
60
  end
31
61
 
32
62
  desc "Delete bot [name]"
33
63
  def delete(name)
34
- Babot.delete name
64
+ cmd "rm -rf '#{root.join name}' '#{root.join name, 'config', 'credentials.yml'}'"
35
65
  end
36
66
 
37
67
  desc "Configure bot [name]"
38
68
  def configure(name)
39
- Babot.configure name
69
+ cmd "#{ENV['EDITOR'] || 'nano'} '#{root.join name, "config", 'credentials.yml'}'"
40
70
  end
41
71
 
42
72
  desc "List bots"
43
73
  def list
44
- puts Babot.list
74
+ cmd "ls '#{root}'"
45
75
  end
46
76
 
47
- desc "Dump bots and configuration in tar file"
48
- def dump
49
- Babot.dump
77
+ desc "Push to remote server [remote]"
78
+ def push(remote)
79
+ cmd "scp -qr '#{root}' '#{remote}:~/.' && ssh '#{remote}' 'babot schedule'"
50
80
  end
51
81
 
52
- desc "Install from tar file [path]"
53
- def install(path)
54
- Babot.install path
82
+ private
83
+ def root
84
+ Pathname.new(ENV["HOME"]).join ".babot"
55
85
  end
56
86
 
57
- desc "Push to remote server [remote]"
58
- def push(remote)
59
- Babot.push remote
87
+ def cmd(command)
88
+ puts command
89
+ system command
60
90
  end
61
91
  end
62
92
 
@@ -1,83 +1,7 @@
1
- require 'fileutils'
2
1
  require 'twitter'
3
- require 'pathname'
4
- require 'yaml'
5
2
 
6
3
  class Babot
7
-
8
- class << self
9
-
10
- def update(name)
11
- cmd "cd '#{root.join(name)}' && git pull --rebase origin master && bundle install"
12
- end
13
-
14
- def schedule
15
- list.each do |name|
16
- cmd "whenever -i #{name} -f #{root.join(name, 'config', 'schedule.rb')}"
17
- end
18
- end
19
-
20
- def add(name, repository)
21
- if repository =~ /^\//
22
- cmd "ln -s '#{repository}' '#{root.join(name)}'"
23
- else
24
- cmd "git clone '#{repository}' '#{root.join(name)}'"
25
- end
26
- File.open(root.join(name, "config", "credentials.yml").to_s, 'w') do |config|
27
- config.write({ 'consumer_key' => "",
28
- 'consumer_secret' => "",
29
- 'oauth_token' => "",
30
- 'oauth_token_secret' => "" }.to_yaml)
31
- end
32
- end
33
-
34
- def delete(name)
35
- cmd "rm -rf '#{root.join(name)}' '#{root.join(name, 'config', 'credentials.yml')}'"
36
- end
37
-
38
- def configure(name)
39
- cmd "#{ENV['EDITOR'] || 'nano'} '#{root.join(name, "config", 'credentials.yml')}'"
40
- end
41
-
42
- def run(name)
43
- options = YAML::load_file root.join(name, "config", 'credentials.yml')
44
-
45
- Twitter.configure do |config|
46
- config.consumer_key = options['consumer_key']
47
- config.consumer_secret = options['consumer_secret']
48
- config.oauth_token = options['oauth_token']
49
- config.oauth_token_secret = options['oauth_token_secret']
50
- end
51
- load Babot.root.join(name, 'babot.run').to_s
52
- end
53
-
54
- def list
55
- Dir.entries(root).reject { |name| name =~ /^\./ }
56
- end
57
-
58
- def dump
59
- cmd "cd ~ && tar --exclude=.git -cf '#{Dir.pwd}/babot-#{Time.now.to_i}.tar' .babot"
60
- end
61
-
62
- def install(dump)
63
- cmd "cd ~ && rm -rf '.babot' && tar -xf '#{Dir.pwd}/#{dump}'"
64
- end
65
-
66
- def push(remote)
67
- cmd "scp -qr '#{root}' '#{remote}:~/.' && ssh '#{remote}' 'babot schedule'"
68
- end
69
-
70
- def root
71
- Pathname.new(ENV["HOME"]).join ".babot"
72
- end
73
-
74
- def cmd(command)
75
- puts command
76
- system command
77
- end
78
-
79
- def run!
80
- Twitter.update new.call
81
- end
4
+ def Babot.run!
5
+ new.call
82
6
  end
83
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Goya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-08 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter