worque 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 567433182ef250050cd55e4142292a4e5c583aea
4
- data.tar.gz: 56a867bb80135417507a4b81808965d56d26f172
3
+ metadata.gz: 9e69180a79a7932c847b6cd6d1ca3858449cc153
4
+ data.tar.gz: c28418960047a74bc6e571657bc0ff1e4e6cb694
5
5
  SHA512:
6
- metadata.gz: 19ac08d6b0f7815b4e8390a4b2c14655378e45ca822088885310af3c88fe16dfb142f66bec665427956b269d8d4e7dfa43cedca289196ed4ddd666c8feaa9a59
7
- data.tar.gz: f4171311af2b16fab768588ba4d692e57633dbd1fa3fb46fe3c06a35e3f3a6b67ab2dd65e44008fe296e0b3c5f0cada01e57b2afee5bf270cca2c9f6bc939747
6
+ metadata.gz: f094c9d4e657115a7f1454348be306e99d89981e843477fd8ca054666921cc383c7684b91f934754f7b1f72c532071526ad3373ebb690350d453025ec873d3bd
7
+ data.tar.gz: b9529cb56dcd47374310f4b8524b03c96e346fab1f70714dab910b6faa491acd162f4ec875dcb869fedb978d1fa38bb992383a73b9de5da020b86759908a012b
data/README.md CHANGED
@@ -77,6 +77,26 @@ alias today="vim $(worque todo) +':cd $WORQUE_PATH'"
77
77
  alias ytd="vim $(worque todo) +':cd $WORQUE_PATH'"
78
78
  ```
79
79
 
80
+ #### `worque todo`
81
+
82
+ Please remember to add `SLACK_API_TOKEN` in your `.bash_profile`
83
+
84
+ ```sh
85
+ export SLACK_API_TOKEN=very-$3Cr3T
86
+ ```
87
+
88
+ Then the note for today will be automatically posted to the channel specified.
89
+
90
+ ```sh
91
+ worque push --channel=daily-report
92
+ ```
93
+
94
+ Alternatively, you can choose to push the note for yesterday
95
+
96
+ ```sh
97
+ worque push --channel daily-report --for yesterday
98
+ ```
99
+
80
100
  ### VIM Integration
81
101
 
82
102
  Add this to your VIM plugin manager
@@ -105,7 +125,6 @@ Something in my plan:
105
125
  * Test suites: Embarrassingly there's no test currently, but this will be my
106
126
  first priority.
107
127
  * `worque list`: List all notes you have.
108
- * `worque push`: Push your daily notes to your specified Slack channel.
109
128
  * `worque changelog`: Sync your Git commits to daily notes.
110
129
 
111
130
  ## Contributing
data/lib/worque/cli.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  require 'thor'
2
2
  require 'worque/command/todo'
3
3
  require 'worque/command/todo/options'
4
+ require 'worque/command/push'
5
+ require 'worque/command/push/options'
4
6
 
5
7
  module Worque
6
8
  class CLI < ::Thor
9
+ package_name 'Worque CLI'
10
+
7
11
  desc 'todo', 'Make a todo'
8
12
 
9
13
  method_option :for, force: false, type: :string, enum: ['today', 'yesterday'], default: 'today'
@@ -13,5 +17,14 @@ module Worque
13
17
  def todo
14
18
  $stdout.puts Worque::Command::Todo.run(options)
15
19
  end
20
+
21
+ desc 'push', 'Push your notes to Slack channel'
22
+
23
+ method_option :for, force: false, type: :string, enum: ['today', 'yesterday'], default: 'today'
24
+ method_option :channel, force: true, required: true, type: :string, desc: 'Can be channel, private group ID or name. E.g. #daily-report'
25
+
26
+ def push
27
+ $stdout.puts Worque::Command::Push.run(options)
28
+ end
16
29
  end
17
30
  end
@@ -0,0 +1,15 @@
1
+ module Worque
2
+ module Command
3
+ class Push::Options
4
+ attr_reader :channel
5
+ attr_reader :token
6
+ attr_reader :for
7
+
8
+ def initialize(options)
9
+ @channel = options[:channel]
10
+ @for = options[:for]
11
+ @token = ENV['SLACK_API_TOKEN']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ require 'worque/utils/slack'
2
+ require 'worque/utils/business_day'
3
+ require 'json'
4
+
5
+ module Worque
6
+ module Command
7
+ class Push
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def call
13
+ slack = Worque::Utils::Slack.new(options.token)
14
+ JSON.dump(slack.post(options.channel, report_file_content))
15
+ end
16
+
17
+ def self.run(options)
18
+ require 'worque/command/push/options'
19
+
20
+ Worque::Command::Push.new(
21
+ Worque::Command::Push::Options.new(options)
22
+ ).call()
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :options
28
+
29
+ def date_for
30
+ case options.for.to_sym
31
+ when :today
32
+ Date.today
33
+ when :yesterday
34
+ Worque::Utils::BusinessDay.previous(Date.today, true)
35
+ end
36
+ end
37
+
38
+ def report_file_content
39
+ File.open(report_file_path).read
40
+ end
41
+
42
+ def report_file_path
43
+ "#{ ENV['WORQUE_PATH'] }/notes-#{date_for}.md"
44
+ end
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ module Worque
5
+ module Utils
6
+ class Slack
7
+ def initialize(token)
8
+ @token = token
9
+ end
10
+
11
+ def post(channel, message)
12
+ JSON.parse(post_form(channel, message).body)
13
+ end
14
+
15
+ private
16
+
17
+ def post_form(channel, message)
18
+ uri = URI('https://slack.com/api/chat.postMessage')
19
+ Net::HTTP.post_form(uri, as_user: true, channel: channel, token: @token, text: message)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Worque
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/worque.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "worque/version"
2
- require 'worque/command'
3
2
  require 'worque/cli'
4
3
 
5
4
  module Worque; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cam Huynh
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.8.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
83
97
  description: Manage your daily working list in Ruby
84
98
  email:
85
99
  - huynhquancam@gmail.com
@@ -94,11 +108,13 @@ files:
94
108
  - bin/worque
95
109
  - lib/worque.rb
96
110
  - lib/worque/cli.rb
97
- - lib/worque/command.rb
111
+ - lib/worque/command/push.rb
112
+ - lib/worque/command/push/options.rb
98
113
  - lib/worque/command/todo.rb
99
114
  - lib/worque/command/todo/options.rb
100
115
  - lib/worque/utils/business_day.rb
101
116
  - lib/worque/utils/command.rb
117
+ - lib/worque/utils/slack.rb
102
118
  - lib/worque/version.rb
103
119
  homepage: https://github.com/huynhquancam/worque
104
120
  licenses:
@@ -1,10 +0,0 @@
1
- require 'worque/command/todo'
2
- module Worque
3
- module Command
4
- extend self
5
-
6
- def run(options)
7
- Todo.new(options).call()
8
- end
9
- end
10
- end