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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43f46b8a26d9212610bf42a29f936120d72e9949
4
- data.tar.gz: b29a7252922b75171baf189d7f422c7fe2e99256
3
+ metadata.gz: 5513665964b20f6ce4101fdf4168296edf3d9229
4
+ data.tar.gz: 8e600929c59b0d54f88743791b0d573745c96185
5
5
  SHA512:
6
- metadata.gz: 1444296740ce2abfb68b4bdc980e5db28425ec197ddb29e70533878776c88ab5486f6088380a4d173dce5f792254087943c0a0baf96347eac96085db51a132e8
7
- data.tar.gz: 788e1dff7ad9ca0851d5b3ee56c778d0926a24b92565d59284d6bab8aa1c1d9104dfb8650f0a458f1631edd73162d2698dad85f1c6e7dc6db7f44e83dda2928a
6
+ metadata.gz: 60d3da5ce79daab9891160900f80c16458538f2eb16e79419faaa05e6351cdfe62875780045573a8a2576bb9be1663d64443ead0ab87eb99b118b04a5aa37025
7
+ data.tar.gz: d80037f9ac37505e3e888aa565831ca0b7fee6d20c97dd1a56c59237bc871700fa0731b2bccc5dd3c1b20130a4d6da1c96663f4f00d027fbace68ceb5ca68623
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Official IDoneThis Command Line Interface
1
+ # I Done This CLI
2
2
 
3
- The I Done This Command Line Interface for [IDoneThis](https://beta.idonethis.com)
3
+ A command line interface for [I Done This](https://home.idonethis.com)
4
4
 
5
5
  ## Installation
6
6
 
@@ -1,8 +1,7 @@
1
1
  require 'oauth2'
2
- require "idonethis_cli/command"
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
- # Obviiously could have subcommands for user like idt user login annd idt user logout
18
- desc "authorize", "you will be prompted to authorize with your iDoneThis credentials"
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 = oauth2_client.auth_code.authorize_url(redirect_uri: 'urn:ietf:wg:oauth:2.0:oob')
19
+ url = auth_client.url
21
20
  code = cli.ask ("Enter code from this URL:\n #{url}").chomp.strip
22
21
 
23
- oauth2_token = oauth2_client.auth_code.get_token(code, redirect_uri: 'urn:ietf:wg:oauth:2.0:oob')
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
- # Oauth2 Client
19
- def oauth2_client
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
- OAuth2::AccessToken.from_hash(oauth2_client, settings.oauth2_token)
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?
@@ -31,9 +31,13 @@ module IdonethisCli
31
31
  def list
32
32
  return nil unless authenticated?
33
33
  return nil unless team_set?
34
- # {"body"=>"Here it is", "created_at"=>"2016-07-22T07:17:12.688Z", "updated_at"=>"2016-07-22T07:17:12.688Z", "occurred_on"=>"2016-07-22", "status"=>"done", "hash_id"=>"b074cb2ff", "completed_on"=>nil, "archived_at"=>nil, "team"=>{"name"=>"Team Name", "hash_id"=>"6fbb"}, "user"=>{"email_address"=>"user@domain.com", "full_name"=>"Jonathan Siegel", "hash_id"=>"3e35"}}
35
- entries.each.with_index(1) do |entry, idx|
36
- cli.say "#{entry['created_at']} : #{entry['status']} : #{entry['body']}"
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
@@ -1,3 +1,3 @@
1
1
  module IdonethisCli
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-07-24 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor