File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1
1
require 'thor'
2
+ require 'weekdone'
2
3
3
4
module Weekdone ::Cli
4
5
class Command < Thor
6
+ desc "login" , "oauth login to weekdone"
7
+ def login
8
+ client_id = ENV [ 'WEEKDONE_CLIENT_ID' ]
9
+ client_secret = ENV [ 'WEEKDONE_CLIENT_SECRET' ]
10
+
11
+ client = Weekdone ::Api . new ( client_id , client_secret )
12
+ puts "open URL to authorize:"
13
+ puts client . authorization_request
14
+
15
+ print "\n input authorization code: "
16
+ auth_code = STDIN . gets . chomp
17
+ client . authorization_grant ( auth_code )
18
+
19
+ File . open ( ENV [ 'HOME' ] + "/.weekdone/credentials" , "w" ) do |f |
20
+ f . puts ( client . token_code )
21
+ end
22
+ end
23
+
24
+
25
+ desc "searchForItems" , "search for items"
26
+ method_options userid : :string
27
+ def searchForItems
28
+ client = Weekdone ::Api . new ( nil , nil )
29
+ File . open ( ENV [ 'HOME' ] + "/.weekdone/credentials" , "r" ) do |f |
30
+ @token_code = f . gets ( client . token_code )
31
+ end
32
+ client . token_code = @token_code
33
+
34
+ items = client . searchForItems ( user_id : options [ :userid ] )
35
+ print JSON . dump ( items )
36
+ end
5
37
end
6
38
end
You can’t perform that action at this time.
0 commit comments