idonethis-official-cli 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/idonethis_cli/cli.rb +6 -6
- data/lib/idonethis_cli/client/auth.rb +16 -0
- data/lib/idonethis_cli/command.rb +6 -4
- data/lib/idonethis_cli/entry.rb +7 -7
- data/lib/idonethis_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5513665964b20f6ce4101fdf4168296edf3d9229
|
4
|
+
data.tar.gz: 8e600929c59b0d54f88743791b0d573745c96185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60d3da5ce79daab9891160900f80c16458538f2eb16e79419faaa05e6351cdfe62875780045573a8a2576bb9be1663d64443ead0ab87eb99b118b04a5aa37025
|
7
|
+
data.tar.gz: d80037f9ac37505e3e888aa565831ca0b7fee6d20c97dd1a56c59237bc871700fa0731b2bccc5dd3c1b20130a4d6da1c96663f4f00d027fbace68ceb5ca68623
|
data/README.md
CHANGED
data/lib/idonethis_cli/cli.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'oauth2'
|
2
|
-
require
|
2
|
+
require 'idonethis_cli/command'
|
3
3
|
require 'idonethis_cli/team'
|
4
4
|
require 'idonethis_cli/entry'
|
5
|
-
require "idonethis_cli/client/auth"
|
6
5
|
|
7
6
|
module IdonethisCli
|
8
7
|
|
@@ -14,13 +13,14 @@ module IdonethisCli
|
|
14
13
|
subcommand "entry", IdonethisCli::Entry
|
15
14
|
|
16
15
|
# TODO not sure how to separate this out as a class like the subcommands to
|
17
|
-
#
|
18
|
-
desc "authorize", "you will be prompted to authorize with your
|
16
|
+
# Obviously could have subcommands for user like idt user login annd idt user logout
|
17
|
+
desc "authorize", "you will be prompted to authorize with your I Done This credentials"
|
19
18
|
def authorize
|
20
|
-
url =
|
19
|
+
url = auth_client.url
|
21
20
|
code = cli.ask ("Enter code from this URL:\n #{url}").chomp.strip
|
22
21
|
|
23
|
-
oauth2_token =
|
22
|
+
oauth2_token = auth_client.oauth2_token(code)
|
23
|
+
|
24
24
|
if oauth2_token
|
25
25
|
settings.save_oauth2_token(oauth2_token.to_hash)
|
26
26
|
cli.say "Login successful"
|
@@ -7,6 +7,22 @@ module IdonethisCli
|
|
7
7
|
# TODO
|
8
8
|
end
|
9
9
|
|
10
|
+
def oauth2_client
|
11
|
+
@oauth2_client ||= OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET, site: BASE_URL)
|
12
|
+
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
oauth2_client.auth_code.authorize_url(redirect_uri: 'urn:ietf:wg:oauth:2.0:oob')
|
16
|
+
end
|
17
|
+
|
18
|
+
def oauth2_token(code)
|
19
|
+
oauth2_client.auth_code.get_token(code, redirect_uri: 'urn:ietf:wg:oauth:2.0:oob')
|
20
|
+
end
|
21
|
+
|
22
|
+
def token(oauth2_token)
|
23
|
+
current_token = OAuth2::AccessToken.from_hash(oauth2_client, oauth2_token)
|
24
|
+
current_token.expired? ? current_token.refresh! : current_token
|
25
|
+
end
|
10
26
|
end
|
11
27
|
end
|
12
28
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require "idonethis_cli/settings"
|
3
|
+
require "idonethis_cli/client/auth"
|
3
4
|
require 'highline'
|
4
5
|
|
5
6
|
module IdonethisCli
|
@@ -15,14 +16,15 @@ module IdonethisCli
|
|
15
16
|
@settings ||= Settings.new
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET, site: BASE_URL)
|
19
|
+
def auth_client
|
20
|
+
@auth_client ||= IdonethisCli::Client::Auth.new
|
21
21
|
end
|
22
22
|
|
23
23
|
# This token is used to access things
|
24
24
|
def token
|
25
|
-
|
25
|
+
auth_client.token(settings.oauth2_token).tap do |token|
|
26
|
+
settings.save_oauth2_token(token.to_hash)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
def authenticated?
|
data/lib/idonethis_cli/entry.rb
CHANGED
@@ -31,9 +31,13 @@ module IdonethisCli
|
|
31
31
|
def list
|
32
32
|
return nil unless authenticated?
|
33
33
|
return nil unless team_set?
|
34
|
-
|
35
|
-
entries.
|
36
|
-
|
34
|
+
|
35
|
+
if entries = entry_client.list(settings.team['hash_id'])
|
36
|
+
entries.each.with_index(1) do |entry, idx|
|
37
|
+
cli.say "#{entry['created_at']} : #{entry['status']} : #{entry['body']}"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
cli.say "Could not retrieve entries. #{entry_client.error}"
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
@@ -42,10 +46,6 @@ module IdonethisCli
|
|
42
46
|
@client ||= IdonethisCli::Client::Entry.new(token)
|
43
47
|
end
|
44
48
|
|
45
|
-
def entries
|
46
|
-
entry_client.list(settings.team['hash_id'])
|
47
|
-
end
|
48
|
-
|
49
49
|
def post_entry(body)
|
50
50
|
response = entry_client.create(settings.team['hash_id'], body)
|
51
51
|
if response
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idonethis-official-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Mingins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|