Skip to content

Commit 34454af

Browse files
committed
impl login and searchForItems command
1 parent 227af86 commit 34454af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/weekdone/cli/command.rb

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
require 'thor'
2+
require 'weekdone'
23

34
module Weekdone::Cli
45
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 "\ninput 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
537
end
638
end

0 commit comments

Comments
 (0)