lolcommits 0.5.2 → 0.5.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.
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'yaml'
2
3
  require 'oauth'
3
4
 
@@ -8,7 +9,6 @@ $VERBOSE = original_verbose # activate warning messages again.
8
9
 
9
10
  module Lolcommits
10
11
  class LolTwitter < Plugin
11
-
12
12
  TWITTER_CONSUMER_KEY = 'qc096dJJCxIiqDNUqEsqQ'
13
13
  TWITTER_CONSUMER_SECRET = 'rvjNdtwSr1H0TvBvjpk6c4bvrNydHmmbvv7gXZQI'
14
14
  TWITTER_RETRIES = 2
@@ -28,18 +28,18 @@ module Lolcommits
28
28
  puts "\t--> Tweet Sent!"
29
29
  end
30
30
  rescue Twitter::Error::InternalServerError,
31
- Twitter::Error::BadRequest,
32
- Twitter::Error::ClientError => e
31
+ Twitter::Error::BadRequest,
32
+ Twitter::Error::ClientError => e
33
33
  debug "Tweet FAILED! #{e.class} - #{e.message}"
34
34
  retry if attempts < TWITTER_RETRIES
35
35
  puts "ERROR: Tweet FAILED! (after #{attempts} attempts) - #{e.message}"
36
36
  end
37
37
  end
38
38
 
39
- def build_tweet(commit_message, tag = "#lolcommits")
39
+ def build_tweet(commit_message, tag = '#lolcommits')
40
40
  available_commit_msg_size = max_tweet_size - (tag.length + 1)
41
41
  if commit_message.length > available_commit_msg_size
42
- commit_message = "#{commit_message[0..(available_commit_msg_size-3)]}..."
42
+ commit_message = "#{commit_message[0..(available_commit_msg_size - 3)]}..."
43
43
  end
44
44
  "#{commit_message} #{tag}"
45
45
  end
@@ -48,25 +48,25 @@ module Lolcommits
48
48
  options = super
49
49
  # ask user to configure tokens if enabling
50
50
  if options['enabled'] == true
51
- if auth_config = configure_auth!
51
+ auth_config = configure_auth!
52
+ if auth_config
52
53
  options.merge!(auth_config)
53
54
  else
54
- # return nil if configure_auth failed
55
- return
55
+ return # return nil if configure_auth failed
56
56
  end
57
57
  end
58
- return options
58
+ options
59
59
  end
60
60
 
61
61
  def configure_auth!
62
- puts "---------------------------"
63
- puts "Need to grab twitter tokens"
64
- puts "---------------------------"
62
+ puts '---------------------------'
63
+ puts 'Need to grab twitter tokens'
64
+ puts '---------------------------'
65
65
 
66
66
  consumer = OAuth::Consumer.new(TWITTER_CONSUMER_KEY,
67
67
  TWITTER_CONSUMER_SECRET,
68
- :site => 'http://api.twitter.com',
69
- :request_endpoint => 'http://api.twitter.com',
68
+ :site => 'https://api.twitter.com',
69
+ :request_endpoint => 'https://api.twitter.com',
70
70
  :sign_in => true)
71
71
 
72
72
  request_token = consumer.get_request_token
@@ -99,7 +99,7 @@ module Lolcommits
99
99
  end
100
100
  end
101
101
 
102
- def is_configured?
102
+ def configured?
103
103
  !configuration['enabled'].nil? &&
104
104
  configuration['access_token'] &&
105
105
  configuration['secret']
@@ -1,45 +1,45 @@
1
- require "rest_client"
2
- require "pp"
3
- require "json"
4
- require "logger"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rest_client'
3
+ require 'pp'
4
+ require 'json'
5
+ require 'logger'
5
6
 
6
7
  module Lolcommits
7
8
  class Lolsrv < Plugin
8
-
9
9
  def initialize(runner)
10
10
  super
11
11
  self.options << 'server'
12
12
  if self.runner
13
- @logger = Logger.new(File.new(self.runner.config.loldir + "/lolsrv.log", "a+"))
13
+ @logger = Logger.new(File.new(self.runner.config.loldir + '/lolsrv.log', 'a+'))
14
14
  end
15
15
  end
16
16
 
17
17
  def run
18
18
  return unless valid_configuration?
19
- fork { sync() }
19
+ fork { sync }
20
20
  end
21
21
 
22
- def is_configured?
23
- !configuration["enabled"].nil? && configuration["server"]
22
+ def configured?
23
+ !configuration['enabled'].nil? && configuration['server']
24
24
  end
25
25
 
26
26
  def sync
27
- existing = get_existing_lols
27
+ existing = existing_lols
28
28
  unless existing.nil?
29
- Dir[self.runner.config.loldir + "/*.{jpg,gif}"].each do |item|
30
- sha = File.basename(item, ".*")
31
- unless existing.include?(sha) || sha == "tmp_snapshot"
29
+ Dir[self.runner.config.loldir + '/*.{jpg,gif}'].each do |item|
30
+ sha = File.basename(item, '.*')
31
+ unless existing.include?(sha) || sha == 'tmp_snapshot'
32
32
  upload(item, sha)
33
33
  end
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
- def get_existing_lols
38
+ def existing_lols
39
39
  begin
40
40
  lols = JSON.parse(
41
- RestClient.get(configuration['server'] + "/lols"))
42
- lols.map { |lol| lol["sha"] }
41
+ RestClient.get(configuration['server'] + '/lols'))
42
+ lols.map { |lol| lol['sha'] }
43
43
  rescue => e
44
44
  log_error(e, "ERROR: existing lols could not be retrieved #{e.class} - #{e.message}")
45
45
  return nil
@@ -49,12 +49,14 @@ module Lolcommits
49
49
  def upload(file, sha)
50
50
  begin
51
51
  RestClient.post(
52
- configuration["server"] + "/uplol",
52
+ configuration['server'] + '/uplol',
53
53
  :lol => File.new(file),
54
- :sha => sha
55
- )
54
+ :url => self.runner.url + sha,
55
+ :repo => self.runner.repo,
56
+ :date => File.ctime(file),
57
+ :sha => sha)
56
58
  rescue => e
57
- log_error(e,"ERROR: Upload of lol #{sha} FAILED #{e.class} - #{e.message}")
59
+ log_error(e, "ERROR: Upload of lol #{sha} FAILED #{e.class} - #{e.message}")
58
60
  return
59
61
  end
60
62
  end
@@ -66,7 +68,7 @@ module Lolcommits
66
68
  end
67
69
 
68
70
  def self.name
69
- "lolsrv"
71
+ 'lolsrv'
70
72
  end
71
73
  end
72
74
  end
@@ -1,23 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Lolcommits
2
3
  class Loltext < Plugin
3
-
4
4
  def initialize(runner)
5
5
  super
6
6
  @font_location = runner ? runner.font : nil
7
7
  end
8
8
 
9
9
  # enabled by default (if no configuration exists)
10
- def is_enabled?
11
- !is_configured? || super
10
+ def enabled?
11
+ !configured? || super
12
12
  end
13
13
 
14
14
  def run
15
15
  font_location = @font_location || File.join(Configuration::LOLCOMMITS_ROOT,
16
- "vendor",
17
- "fonts",
18
- "Impact.ttf")
16
+ 'vendor',
17
+ 'fonts',
18
+ 'Impact.ttf')
19
19
 
20
- debug "Annotating image via MiniMagick"
20
+ debug 'Annotating image via MiniMagick'
21
21
  image = MiniMagick::Image.open(self.runner.main_image)
22
22
  image.combine_options do |c|
23
23
  c.gravity 'SouthWest'
@@ -45,10 +45,9 @@ module Lolcommits
45
45
  end
46
46
 
47
47
  def self.name
48
- 'loltext'
48
+ 'loltext'
49
49
  end
50
50
 
51
-
52
51
  private
53
52
 
54
53
  # do whatever is required to commit message to get it clean and ready for imagemagick
@@ -1,9 +1,9 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  # Adapted and expanded from https://github.com/rwtnorton/moar-lolspeak
2
3
  # which was largely taken from an old Perl script and is sadly is not
3
4
  # available via rubygems
4
5
 
5
6
  module Lolspeak
6
-
7
7
  LOL_DICTIONARY = {
8
8
  /what/ => %w{wut whut},
9
9
  /you\b/ => %w{yu yous yoo u yooz},
@@ -33,7 +33,7 @@ module Lolspeak
33
33
  /age/ => %w{uj},
34
34
  /like/ => %w{likez liek licks},
35
35
  /love/ => %w{lovez lub lubs luv lurve lurves},
36
- /\bis\b/ => ['ar teh','ar'],
36
+ /\bis\b/ => ['ar teh', 'ar'],
37
37
  /nd\b/ => %w{n n'},
38
38
  /who/ => %w{hoo},
39
39
  /'/ => [''],
@@ -78,13 +78,13 @@ module Lolspeak
78
78
  /ea/ => %w{ee},
79
79
  /can\si\s(?:ple(?:a|e)(?:s|z)e?)?\s?have\sa/ => ['i can haz'],
80
80
  /(?:hello|\bhi\b|\bhey\b|howdy|\byo\b),?/ => ['oh hai,'],
81
- /(?:god\b|allah|buddah?|diety|lord)/ => ['ceiling cat'],
81
+ /(?:god\b|allah|buddah?|diety|lord)/ => ['ceiling cat']
82
82
  }
83
83
 
84
84
  def tranzlate(str)
85
85
  lolstr = str.dup
86
86
  LOL_DICTIONARY.each do |english, lolspeak|
87
- #ghetto ruby1.8/1.9 agnostic version of choice vs sample
87
+ # ghetto ruby1.8/1.9 agnostic version of choice vs sample
88
88
  lolstr.gsub!(english, lolspeak.shuffle.first)
89
89
  end
90
90
 
@@ -97,7 +97,6 @@ end
97
97
 
98
98
  module Lolcommits
99
99
  class Tranzlate < Plugin
100
-
101
100
  extend Lolspeak
102
101
 
103
102
  def run
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'rest_client'
2
3
 
3
4
  module Lolcommits
@@ -6,7 +7,7 @@ module Lolcommits
6
7
 
7
8
  def initialize(runner)
8
9
  super
9
- self.options << 'endpoint'
10
+ self.options.concat(['endpoint', 'optional_key'])
10
11
  end
11
12
 
12
13
  def run
@@ -14,17 +15,18 @@ module Lolcommits
14
15
 
15
16
  repo = self.runner.repo.to_s
16
17
  if repo.empty?
17
- puts "Repo is empty, skipping upload"
18
+ puts 'Repo is empty, skipping upload'
18
19
  else
19
- debug "Calling " + configuration['endpoint'] + " with repo " + repo
20
+ debug 'Calling ' + configuration['endpoint'] + ' with repo ' + repo
20
21
  RestClient.post(configuration['endpoint'],
21
- :file => File.new(self.runner.main_image),
22
- :repo => repo)
22
+ :file => File.new(self.runner.main_image),
23
+ :repo => repo,
24
+ :key => configuration['optional_key'])
23
25
  end
24
26
  end
25
27
 
26
- def is_configured?
27
- !configuration["enabled"].nil? && configuration["endpoint"]
28
+ def configured?
29
+ !configuration['enabled'].nil? && configuration['endpoint']
28
30
  end
29
31
 
30
32
  def self.name
@@ -1,10 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Lolcommits
2
3
  PLUGINS = Lolcommits::Plugin.subclasses
3
4
 
4
5
  class Runner
5
6
  attr_accessor :capture_delay, :capture_stealth, :capture_device, :message, :sha,
6
- :snapshot_loc, :main_image, :repo, :config, :repo_internal_path,
7
- :font, :capture_animate
7
+ :snapshot_loc, :main_image, :repo, :config, :repo_internal_path,
8
+ :font, :capture_animate, :url
8
9
 
9
10
  include Methadone::CLILogging
10
11
  include ActiveSupport::Callbacks
@@ -20,7 +21,7 @@ module Lolcommits
20
21
  set_callback :run, :after, :execute_lolcommits_loltext
21
22
  # Executed First
22
23
 
23
- def initialize(attributes={})
24
+ def initialize(attributes = {})
24
25
  attributes.each do |attr, val|
25
26
  self.send("#{attr}=", val)
26
27
  end
@@ -31,6 +32,7 @@ module Lolcommits
31
32
  self.message = git_info.message if self.message.nil?
32
33
  self.repo_internal_path = git_info.repo_internal_path
33
34
  self.repo = git_info.repo
35
+ self.url = git_info.url
34
36
  end
35
37
  end
36
38
 
@@ -38,7 +40,7 @@ module Lolcommits
38
40
  die_if_rebasing!
39
41
 
40
42
  run_callbacks :run do
41
- puts "*** Preserving this moment in history." unless capture_stealth
43
+ puts '*** Preserving this moment in history.' unless capture_stealth
42
44
  self.snapshot_loc = self.config.raw_image(image_file_type)
43
45
  self.main_image = self.config.main_image(self.sha, image_file_type)
44
46
  capturer = capturer_class.new(
@@ -60,6 +62,7 @@ module Lolcommits
60
62
  end
61
63
 
62
64
  private
65
+
63
66
  def capturer_class
64
67
  "Lolcommits::Capture#{Configuration.platform}#{animate? ? 'Animated' : nil}".constantize
65
68
  end
@@ -70,22 +73,23 @@ module Lolcommits
70
73
  end
71
74
 
72
75
  protected
76
+
73
77
  def die_if_rebasing!
74
78
  debug "Runner: Making sure user isn't rebasing"
75
79
  if not self.repo_internal_path.nil?
76
- mergeclue = File.join self.repo_internal_path, "rebase-merge"
80
+ mergeclue = File.join self.repo_internal_path, 'rebase-merge'
77
81
  if File.directory? mergeclue
78
- debug "Runner: Rebase detected, silently exiting!"
82
+ debug 'Runner: Rebase detected, silently exiting!'
79
83
  exit 0
80
84
  end
81
85
  end
82
86
  end
83
87
 
84
88
  def resize_snapshot!
85
- debug "Runner: resizing snapshot"
89
+ debug 'Runner: resizing snapshot'
86
90
  image = MiniMagick::Image.open(self.snapshot_loc)
87
- if (image[:width] > 640 || image[:height] > 480)
88
- #this is ghetto resize-to-fill
91
+ if image[:width] > 640 || image[:height] > 480
92
+ # this is ghetto resize-to-fill
89
93
  image.combine_options do |c|
90
94
  c.resize '640x480^'
91
95
  c.gravity 'center'
@@ -99,7 +103,7 @@ module Lolcommits
99
103
  end
100
104
 
101
105
  def cleanup!
102
- debug "Runner: running cleanup"
106
+ debug 'Runner: running cleanup'
103
107
  # clean up the captured image and any other raw assets
104
108
  FileUtils.rm(self.snapshot_loc)
105
109
  FileUtils.rm_f(self.config.video_loc)
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Lolcommits
2
- VERSION = "0.5.2"
3
+ VERSION = '0.5.3'
3
4
  end
data/lolcommits.gemspec CHANGED
@@ -30,11 +30,15 @@ Gem::Specification.new do |s|
30
30
  # development dependencies
31
31
  s.add_development_dependency('rdoc')
32
32
  s.add_development_dependency('aruba', '~> 0.5.1')
33
- s.add_development_dependency('rake',' ~> 10.0.2')
33
+ s.add_development_dependency('rake', '~> 10.0.2')
34
34
  s.add_development_dependency('fivemat')
35
35
  s.add_development_dependency('faker')
36
36
  s.add_development_dependency('travis')
37
37
  s.add_development_dependency('coveralls')
38
+ s.add_development_dependency('magic_encoding')
39
+ if RUBY_VERSION >= '1.9.2'
40
+ s.add_development_dependency('rubocop', '~> 0.18.1')
41
+ end
38
42
 
39
43
  # plugin dependencies
40
44
  s.add_runtime_dependency('twitter', '~> 4.8.1') #twitter
data/rubocop-todo.yml ADDED
@@ -0,0 +1,249 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-02-10 12:40:38 -0500 using RuboCop version 0.18.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offences are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offence count: 22
9
+ AmbiguousRegexpLiteral:
10
+ Enabled: false
11
+
12
+ # Offence count: 1
13
+ CaseEquality:
14
+ Enabled: false
15
+
16
+ # Offence count: 1
17
+ # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
18
+ # NOTE: Not sure I agree with this one. -mroth
19
+ CaseIndentation:
20
+ Enabled: false
21
+
22
+ # Offence count: 2
23
+ FavorSprintf:
24
+ Enabled: false
25
+
26
+ # Offence count: 8
27
+ FavorUnlessOverNegatedIf:
28
+ Enabled: false
29
+
30
+ # Offence count: 7
31
+ IfUnlessModifier:
32
+ Enabled: false
33
+
34
+ # Offence count: 8
35
+ Not:
36
+ Enabled: false
37
+
38
+ # Offence count: 1
39
+ # Cop supports --auto-correct.
40
+ Proc:
41
+ Enabled: false
42
+
43
+ # Offence count: 3
44
+ RedundantBegin:
45
+ Enabled: false
46
+
47
+ # Offence count: 67
48
+ # Cop supports --auto-correct.
49
+ # NOTE: I want to understand this one better before auto it -mroth
50
+ RedundantSelf:
51
+ Enabled: false
52
+
53
+ # Offence count: 1
54
+ # NOTE: Eh, I don't like this one, I think they are more readable? -mroth
55
+ OneLineConditional:
56
+ Enabled: false
57
+
58
+ # Offence count: 2
59
+ UselessAssignment:
60
+ Enabled: false
61
+
62
+ # Offence count: 23
63
+ Documentation:
64
+ Enabled: false
65
+
66
+ # Offence count: 1
67
+ # Configuration parameters: CountComments.
68
+ ClassLength:
69
+ Max: 169
70
+
71
+ # Offence count: 73
72
+ LineLength:
73
+ Max: 179
74
+
75
+ # Offence count: 19
76
+ # Configuration parameters: CountComments.
77
+ MethodLength:
78
+ Max: 32
79
+
80
+ # Offence count: 2
81
+ # Cop supports --auto-correct.
82
+ WordArray:
83
+ MinSize: 3
84
+
85
+ # Offence count: 1
86
+ RegexpLiteral:
87
+ MaxSlashes: 2
88
+
89
+ # Offence count: 3
90
+ CyclomaticComplexity:
91
+ Max: 10
92
+
93
+ # Offence count: 2
94
+ # Cop supports --auto-correct.
95
+ # Configuration parameters: AllowMultipleReturnValues.
96
+ # RedundantReturn:
97
+ # Enabled: true
98
+
99
+ # Offence count: 1
100
+ # AccessorMethodName:
101
+ # Enabled: true
102
+
103
+ # Offence count: 2
104
+ # Cop supports --auto-correct.
105
+ # AlignArray:
106
+ # Enabled: true
107
+
108
+ # Offence count: 7
109
+ # Cop supports --auto-correct.
110
+ # AlignParameters:
111
+ # Enabled: true
112
+
113
+ # Offence count: 3
114
+ # Configuration parameters: AllowSafeAssignment.
115
+ # AssignmentInCondition:
116
+ # Enabled: true
117
+
118
+ # Offence count: 2
119
+ # Cop supports --auto-correct.
120
+ # Blocks:
121
+ # Enabled: true
122
+
123
+ # Offence count: 1
124
+ # Cop supports --auto-correct.
125
+ # Configuration parameters: PreferredMethods.
126
+ # CollectionMethods:
127
+ # Enabled: true
128
+
129
+ # Offence count: 1
130
+ # Cop supports --auto-correct.
131
+ # ColonMethodCall:
132
+ # Enabled: true
133
+
134
+ # Offence count: 1
135
+ # Cop supports --auto-correct.
136
+ # EmptyLines:
137
+ # Enabled: true
138
+
139
+ # Offence count: 3
140
+ # EmptyLinesAroundAccessModifier:
141
+ # Enabled: true
142
+
143
+ # Offence count: 19
144
+ # Cop supports --auto-correct.
145
+ # EmptyLinesAroundBody:
146
+ # Enabled: true
147
+
148
+ # Offence count: 4
149
+ # Cop supports --auto-correct.
150
+ # EmptyLiteral:
151
+ # Enabled: true
152
+
153
+ # Offence count: 2
154
+ # IndentationWidth:
155
+ # Enabled: true
156
+
157
+ # Offence count: 8
158
+ # Cop supports --auto-correct.
159
+ # LeadingCommentSpace:
160
+ # Enabled: true
161
+
162
+ # Offence count: 7
163
+ # Cop supports --auto-correct.
164
+ # MethodCallParentheses:
165
+ # Enabled: true
166
+
167
+ # Offence count: 1
168
+ # Cop supports --auto-correct.
169
+ # Configuration parameters: AllowSafeAssignment.
170
+ # ParenthesesAroundCondition:
171
+ # Enabled: true
172
+
173
+ # Offence count: 13
174
+ # Configuration parameters: NamePrefixBlacklist.
175
+ # PredicateName:
176
+ # Enabled: true
177
+
178
+ # Offence count: 1
179
+ # Cop supports --auto-correct.
180
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
181
+ # SignalException:
182
+ # Enabled: true
183
+
184
+ # Offence count: 7
185
+ # Cop supports --auto-correct.
186
+ # SpaceAfterComma:
187
+ # Enabled: true
188
+
189
+ # Offence count: 1
190
+ # Cop supports --auto-correct.
191
+ # SpaceAfterControlKeyword:
192
+ # Enabled: true
193
+
194
+ # Offence count: 1
195
+ # Cop supports --auto-correct.
196
+ # SpaceAfterNot:
197
+ # Enabled: true
198
+
199
+ # Offence count: 4
200
+ # Cop supports --auto-correct.
201
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
202
+ # SpaceAroundBlockBraces:
203
+ # Enabled: true
204
+
205
+ # Offence count: 2
206
+ # Cop supports --auto-correct.
207
+ # SpaceAroundEqualsInParameterDefault:
208
+ # Enabled: true
209
+
210
+ # Offence count: 4
211
+ # Cop supports --auto-correct.
212
+ # SpaceAroundOperators:
213
+ # Enabled: true
214
+
215
+ # Offence count: 1
216
+ # Cop supports --auto-correct.
217
+ # SpaceInsideBrackets:
218
+ # Enabled: true
219
+
220
+ # Offence count: 5
221
+ # Cop supports --auto-correct.
222
+ # SpaceInsideParens:
223
+ # Enabled: true
224
+
225
+ # Offence count: 1
226
+ # Cop supports --auto-correct.
227
+ # SpecialGlobalVars:
228
+ # Enabled: true
229
+
230
+ # Offence count: 178
231
+ # Cop supports --auto-correct.
232
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
233
+ # StringLiterals:
234
+ # Enabled: true
235
+
236
+ # Offence count: 1
237
+ # Cop supports --auto-correct.
238
+ # TrailingBlankLines:
239
+ # Enabled: true
240
+
241
+ # Offence count: 1
242
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
243
+ # TrailingComma:
244
+ # Enabled: true
245
+
246
+ # Offence count: 1
247
+ # Cop supports --auto-correct.
248
+ # TrailingWhitespace:
249
+ # Enabled: true