suc 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/suc +53 -0
- data/lib/mc.rb +51 -0
- data/lib/message.rb +31 -0
- data/lib/reports/email.rb +38 -0
- data/lib/reports/personal.rb +35 -0
- data/lib/suc.rb +29 -0
- data/lib/templates/personal_report.erb +8 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a636c52436504923f581c9d4cb467ae2fb4fd62a
|
4
|
+
data.tar.gz: 5e1c1dbfede2679f7ba872878e1df94f47adcb14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 692b373d71804d87a3e857d6a9b6ea1cfe67c6a9f87c0b660a51a617428986df7d7d9c1ad4b068418f69ddd50c008368dda497218abe09d54412930a6bb33ac1
|
7
|
+
data.tar.gz: 45a96ebd4aa5380c795e536ca430f56f4056e7c458f00fbd76f3faa4c512e96a68356a297f916be0648b463362f4ab75ba1afdda4fa63b9ce4f952eaf951629a
|
data/bin/suc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require 'gli'
|
6
|
+
require 'suc'
|
7
|
+
|
8
|
+
include GLI::App
|
9
|
+
|
10
|
+
program_desc 'Workreports manipulator'
|
11
|
+
|
12
|
+
pre do
|
13
|
+
Suc::Mc.new.ready?
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Live flow'
|
17
|
+
command :live do |c|
|
18
|
+
c.action do
|
19
|
+
Suc::Message.live
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Create message entry. Will open vi (for now) to collect body of a message'
|
24
|
+
command :create do |c|
|
25
|
+
c.desc 'color of the item (yellow red or green)'
|
26
|
+
c.flag [:color, :c], required: true, default_value: 'green', must_match: /green|yellow|red/
|
27
|
+
c.desc 'Header for the message, should be <= 80 characters'
|
28
|
+
c.flag [:tagline, :t], required: true, must_match: /\A.{1,80}\Z/
|
29
|
+
c.action do |_,options,_|
|
30
|
+
message = Suc::Message.new(tagline: options[:tagline], color: options[:color])
|
31
|
+
message.body_from_user
|
32
|
+
message.publish!
|
33
|
+
puts 'Thanks, your message just been published!'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Outputs week report for a given week'
|
38
|
+
command :workreport do |c|
|
39
|
+
c.desc 'week number to make report about. defaults to the current week'
|
40
|
+
c.flag [:week, :w], default_value: Date.today.cweek
|
41
|
+
c.desc 'If you want to look backwards in time'
|
42
|
+
c.flag [:year, :y], default_value: Date.today.year
|
43
|
+
c.desc 'send report NOTE: the whole idea is to get rid of that piece'
|
44
|
+
c.switch [:send], negatable: false, default_value: false
|
45
|
+
c.action do |_,options,_|
|
46
|
+
require 'reports/personal'
|
47
|
+
report = Suc::Reports::Personal.new(options[:year], options[:week])
|
48
|
+
report.print
|
49
|
+
report.export if options[:send]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
exit run(ARGV)
|
data/lib/mc.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
class Suc::Mc
|
2
|
+
|
3
|
+
CONFIG_LOCATION = '~/.suflow'
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@errors = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def ready?
|
10
|
+
configured? ? true : guide!
|
11
|
+
end
|
12
|
+
|
13
|
+
def configured?
|
14
|
+
config_file_present? && config_valid?
|
15
|
+
end
|
16
|
+
|
17
|
+
def guide!
|
18
|
+
info = %{
|
19
|
+
It seems your client is not configured. That's easy to solve!
|
20
|
+
Please visit #{Suc::DEFAULT_URL}, login with your account and populate #{CONFIG_LOCATION}
|
21
|
+
with received token.
|
22
|
+
}
|
23
|
+
puts(info)
|
24
|
+
@errors.each{|s| puts(s)}
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def config_file_present?
|
31
|
+
@config_expanded_location = File.expand_path(CONFIG_LOCATION)
|
32
|
+
if File.exist?(@config_expanded_location)
|
33
|
+
config_content = File.readlines(@config_expanded_location).map(&:chomp)
|
34
|
+
Suc.access_token = config_content[0]
|
35
|
+
Suc.email_client = config_content[1] if config_content[1]
|
36
|
+
Suc.email_recipients = config_content[2] if config_content[2]
|
37
|
+
Suc.email_cc_recipients = config_content[3] if config_content[3]
|
38
|
+
true
|
39
|
+
else
|
40
|
+
@errors << "#{@config_expanded_location} is not present"
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def config_valid?
|
46
|
+
return true if Suc.access_token && Suc.access_token.length.equal?(24)
|
47
|
+
@errors << "Configuration file #{@config_expanded_location} suppose to hold one line with 24 chars"
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/message.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Suc::Message < OpenStruct
|
2
|
+
def body_from_user
|
3
|
+
Tempfile.open('suflow', '/tmp') do |f|
|
4
|
+
system('vi', f.path)
|
5
|
+
self.body = f.read
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def publish!
|
10
|
+
RestClient.post(Suc.resource_url('api/messages').to_s, { message: self.to_h } , authorization: Suc.token_auth )
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def live
|
16
|
+
EM.run do
|
17
|
+
source = EventMachine::EventSource.new(Suc.resource_url('api/flows'), {}, { authorization: Suc.token_auth })
|
18
|
+
source.message do |message|
|
19
|
+
message = Suc::Message.new(JSON.parse(message))
|
20
|
+
puts message
|
21
|
+
end
|
22
|
+
source.start
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def from_json(json)
|
27
|
+
JSON.parse(json).map{|m| new(m)}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'uri/mailto'
|
2
|
+
|
3
|
+
module Suc
|
4
|
+
module Reports
|
5
|
+
class Email
|
6
|
+
|
7
|
+
def initialize(report)
|
8
|
+
@report = report
|
9
|
+
end
|
10
|
+
|
11
|
+
def subject
|
12
|
+
"Work Report week##{@report.week} #{@report.year}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def recipients
|
16
|
+
Suc.email_recipients || 'no-reply@example.com'
|
17
|
+
end
|
18
|
+
|
19
|
+
def cc_recipients
|
20
|
+
Suc.email_cc_recipients
|
21
|
+
end
|
22
|
+
|
23
|
+
def export
|
24
|
+
headers = { 'subject' => escape(subject), 'body' => escape(@report.body)}
|
25
|
+
headers.merge!({ 'cc' => cc_recipients }) if cc_recipients
|
26
|
+
escaped_email = URI::MailTo.build({to: recipients, headers: headers}).to_s
|
27
|
+
system(Suc.email_client, escaped_email)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def escape(string)
|
33
|
+
URI.escape(string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'reports/email'
|
2
|
+
|
3
|
+
module Suc
|
4
|
+
module Reports
|
5
|
+
class Personal
|
6
|
+
|
7
|
+
attr_reader :email, :year, :week, :body
|
8
|
+
|
9
|
+
def initialize(year, week, scope='person')
|
10
|
+
@week = week
|
11
|
+
@year = year
|
12
|
+
resource = '/api/years/%s/weeks/%s/messages' % [year, week]
|
13
|
+
response = RestClient.get(Suc.resource_url(resource).to_s, { params: { scope: scope }, authorization: Suc.token_auth })
|
14
|
+
@messages = Message.from_json(response)
|
15
|
+
@email = Email.new(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def grouped_by_color
|
19
|
+
@messages.group_by{|x| x.color}.sort_by{|x| x.first.length}
|
20
|
+
end
|
21
|
+
|
22
|
+
def print
|
23
|
+
file = File.read File.join(File.dirname(__FILE__), '../templates/personal_report.erb')
|
24
|
+
template = ERB.new(file, 0, '-<>')
|
25
|
+
@body = template.result(binding)
|
26
|
+
puts @body
|
27
|
+
end
|
28
|
+
|
29
|
+
def export
|
30
|
+
email.export
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/suc.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'em-eventsource'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
require 'uri'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'byebug'
|
7
|
+
require 'rest-client'
|
8
|
+
|
9
|
+
module Suc
|
10
|
+
require 'mc'
|
11
|
+
require 'message'
|
12
|
+
|
13
|
+
DEFAULT_URL = 'http://localhost:3000'
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
attr_accessor :access_token, :email_client, :email_recipients, :email_cc_recipients
|
18
|
+
|
19
|
+
def token_auth
|
20
|
+
"Token #{access_token}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def resource_url(resource)
|
24
|
+
URI.join(DEFAULT_URL, resource)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: suc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Artem Chernikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gli
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.13'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: em-eventsource
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
55
|
+
description: Allows to build and parse workreports
|
56
|
+
email: tema.chernikov@gmail.com
|
57
|
+
executables:
|
58
|
+
- suc
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- bin/suc
|
63
|
+
- lib/mc.rb
|
64
|
+
- lib/message.rb
|
65
|
+
- lib/reports/email.rb
|
66
|
+
- lib/reports/personal.rb
|
67
|
+
- lib/suc.rb
|
68
|
+
- lib/templates/personal_report.erb
|
69
|
+
homepage:
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.5.1
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: SUFlow client
|
93
|
+
test_files: []
|
94
|
+
has_rdoc:
|