wip-cli 1.1.0 → 1.2.0

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
  SHA256:
3
- metadata.gz: f6769807e30279443f27ef2ebdee3380ba941aade21d5787338ea28e0eb81c2d
4
- data.tar.gz: 61e38788589c5ca17f83c86d725a52687f1b5793cc1647f291577c4bfcdea2e3
3
+ metadata.gz: bb9c05cd1f964991c2b44e8d235846ebaf3da18dd2ab0c47d8731801a75c4232
4
+ data.tar.gz: 6d439e90a3ad971779e7cabbde4f4790f4a3884286c9ec70d97954f8e13ec81d
5
5
  SHA512:
6
- metadata.gz: 8e6d780083b9b5da3fa9c4a3865c4ddcb7a9b1cd0c2466e19dfbe87719dbd1403d419ad72ef413ef2a8765e00e9e465039cc116fc25c27c59a093ca58f3749fd
7
- data.tar.gz: 6e702061b7662cc33d7e4bd54605659666f974e89e002e94df889725bbb392b8cb2ec0f7f2529b806a2e75f5f2904349b2252f6d664e36a95ae96d8c131d8d81
6
+ metadata.gz: '059174a36ae832449877c49cf88695c9530006c04737702dc60e593e092194ebb5aa8af38c0e648eda813cbd01f829a6aa135bb81d7b5c7e316c0ae041f53f97'
7
+ data.tar.gz: f2a19480b29b25bb41dc0ad35336e127b737bbfa0ecf671fff8ea2dd8e596fbb08a09aa2a178274901743d74f29175e3107bc0958373a8bb607b763458675ec4
data/.gitignore CHANGED
@@ -10,4 +10,5 @@
10
10
  .byebug_history
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
- .ruby-version
13
+ .ruby-version
14
+ .vscode
@@ -2,8 +2,20 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [1.2.0] - 2020-11-12
6
+
7
+ ### Added
8
+
9
+ - Added options to uncomplete a todo: `wip complete -u 123 `
10
+ - Added command to delete a todo: `wip delete 123`
11
+ - Added command to get any users todos: `wip todos -u sowenjub`
12
+ - Added command to get viewer todos: `wip todos`
13
+ - Added method to get viewer: `Wip::User.viewer`
14
+
5
15
  ## [1.1.0] - 2020-11-11
6
16
 
17
+ ### Changed
18
+
7
19
  - Renamed command from wipco to wip
8
20
  - Renamed gem from wipco to wip-cli
9
21
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wip-cli (1.1.0)
4
+ wip-cli (1.2.0)
5
5
  thor (~> 1.0)
6
6
 
7
7
  GEM
@@ -35,4 +35,4 @@ DEPENDENCIES
35
35
  wip-cli!
36
36
 
37
37
  BUNDLED WITH
38
- 2.1.1
38
+ 2.1.4
data/README.md CHANGED
@@ -22,11 +22,20 @@ Or install it yourself as:
22
22
 
23
23
  Define an ENV var named `WIP_API_KEY` with your [api key](https://wip.co/api).
24
24
 
25
- `wip todo "Grab a cup of ☕️"`
25
+ ### Adding a todo & completing it
26
26
 
27
- `wip complete 123`
27
+ * `wip todo "Grab a cup of ☕️"`
28
+ * `wip complete 123`
29
+ * `wip complete -u 123` to uncomplete a todo
30
+ * `wip delete 123`
28
31
 
29
- `wip done "Installed wip-cli gem"`
32
+ And to log a completed todo:
33
+ * `wip done "Installed wip-cli gem"`
34
+
35
+ ### Managing todos
36
+
37
+ You can list your todos (see `wip help todos` for all the options):
38
+ `wip todos -u sowenjub -f "#nomeattoday" -l 10`
30
39
 
31
40
  ## Development
32
41
 
@@ -3,7 +3,6 @@
3
3
  require "bundler/setup"
4
4
  require "byebug"
5
5
  require "wip"
6
- require "wip/todo"
7
6
 
8
7
  # You can add fixtures and/or initialization code here to make experimenting
9
8
  # with your gem easier. You can also use a different console, if you like.
data/lib/wip.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require "wip/helpers/graphql_helper"
2
+ require "wip/todo"
3
+ require "wip/user"
1
4
  require "wip/version"
2
5
 
3
6
  module Wip
@@ -1,7 +1,7 @@
1
- require "wip"
2
-
3
- class Wip::Auth
4
- def self.api_key
5
- ENV['WIP_API_KEY']
1
+ module Wip
2
+ class Auth
3
+ def self.api_key
4
+ ENV['WIP_API_KEY']
5
+ end
6
6
  end
7
7
  end
@@ -7,8 +7,9 @@ class Wip::CLI < Thor
7
7
  class_option :verbose, :type => :boolean, :aliases => "-v"
8
8
 
9
9
  desc "complete [ID]", "Mark a todo as completed"
10
+ method_option :undo, type: :boolean, aliases: '-u'
10
11
  def complete(todo_id)
11
- todo = Wip::Todo.complete(todo_id)
12
+ todo = options.undo ? Wip::Todo.uncomplete(todo_id) : Wip::Todo.complete(todo_id)
12
13
  puts todo.description
13
14
  end
14
15
 
@@ -18,9 +19,29 @@ class Wip::CLI < Thor
18
19
  puts todo.description
19
20
  end
20
21
 
22
+ desc "delete [ID]", "Delete a todo"
23
+ def delete(todo_id)
24
+ todo = Wip::Todo.delete(todo_id)
25
+ puts todo.description
26
+ end
27
+
21
28
  desc "todo [BODY]", "Create a new todo"
22
29
  def todo(body)
23
30
  todo = Wip::Todo.create(body: body)
24
31
  puts todo.description
25
32
  end
33
+
34
+ desc "todos", "List viewer todos"
35
+ method_option :completed, type: :boolean, aliases: '-c'
36
+ method_option :filter, type: :string, aliases: '-f'
37
+ method_option :limit, type: :numeric, aliases: '-l', default: 5
38
+ method_option :order, type: :string, aliases: '-o', default: "completed_at:desc"
39
+ method_option :username, type: :string, aliases: '-u'
40
+ def todos
41
+ todos_options = options.slice("completed", "filter", "limit", "order")
42
+ user = options.username.nil? ? Wip::User.viewer(todos: todos_options) : Wip::User.find(username: options.username, todos: todos_options)
43
+ user.todos.each do |todo|
44
+ puts todo.description
45
+ end
46
+ end
26
47
  end
@@ -3,7 +3,7 @@ require "uri"
3
3
  require "json"
4
4
  require "wip"
5
5
  require "wip/auth"
6
- require "byebug"
6
+
7
7
  class Wip::Client
8
8
  API_ENDPOINT = "https://wip.co/graphql"
9
9
 
@@ -0,0 +1,11 @@
1
+ module Wip
2
+ class GraphqlHelper
3
+ def self.query_conditions(**args)
4
+ return "" if args.empty?
5
+ args.collect do |k,v|
6
+ value = v.kind_of?(String) ? "\"#{v}\"" : v
7
+ [k, value].join(":")
8
+ end.join(", ").yield_self{ |s| '(%s)' % s }
9
+ end
10
+ end
11
+ end
@@ -3,18 +3,27 @@ require "wip"
3
3
  require "wip/client"
4
4
 
5
5
  class Wip::Todo
6
- attr_accessor :id, :body, :completed_at
6
+
7
+ ATTRIBUTES = %i(id body completed_at)
8
+
9
+ attr_accessor *ATTRIBUTES
10
+ attr_accessor :deleted
7
11
  attr_reader :client
8
12
 
13
+ def self.collection_query(**args)
14
+ conditions = Wip::GraphqlHelper.query_conditions(**args)
15
+ %{ todos#{conditions} { #{default_selection} } }
16
+ end
17
+
18
+ def self.default_selection
19
+ ATTRIBUTES.join("\n ")
20
+ end
21
+
9
22
  def self.find(id)
10
23
  client = Wip::Client.new
11
24
  find_query = %{
12
25
  {
13
- todo(id: \"#{id}\") {
14
- id
15
- body
16
- completed_at
17
- }
26
+ todo(id: \"#{id}\") {#{default_selection}}
18
27
  }
19
28
  }
20
29
  client.request find_query
@@ -37,6 +46,18 @@ class Wip::Todo
37
46
  todo
38
47
  end
39
48
 
49
+ def self.uncomplete(id)
50
+ todo = find id
51
+ todo.uncomplete
52
+ todo
53
+ end
54
+
55
+ def self.delete(id)
56
+ todo = find id
57
+ todo.delete
58
+ todo
59
+ end
60
+
40
61
 
41
62
  def initialize(id: nil, body: nil, completed_at: nil)
42
63
  @id = id
@@ -58,7 +79,7 @@ class Wip::Todo
58
79
  end
59
80
 
60
81
  def icon
61
- done? ? "✅" : "🚧"
82
+ deleted ? "🗑" : (done? ? "✅" : "🚧")
62
83
  end
63
84
 
64
85
  def complete
@@ -68,6 +89,13 @@ class Wip::Todo
68
89
  end
69
90
  end
70
91
 
92
+ def uncomplete
93
+ client.request uncomplete_query
94
+ client.data("uncompleteTodo").tap do |params|
95
+ @completed_at = nil
96
+ end
97
+ end
98
+
71
99
  def save
72
100
  client.request create_query
73
101
  client.data("createTodo").tap do |params|
@@ -75,6 +103,11 @@ class Wip::Todo
75
103
  end
76
104
  end
77
105
 
106
+ def delete
107
+ client.request delete_query
108
+ @deleted = !client.data("deleteTodo").nil?
109
+ end
110
+
78
111
  private
79
112
  def create_query
80
113
  %{
@@ -88,6 +121,14 @@ class Wip::Todo
88
121
  }
89
122
  end
90
123
 
124
+ def delete_query
125
+ %{
126
+ mutation deleteTodo {
127
+ deleteTodo(id: #{id})
128
+ }
129
+ }
130
+ end
131
+
91
132
  def complete_query
92
133
  %{
93
134
  mutation completeTodo {
@@ -100,6 +141,18 @@ class Wip::Todo
100
141
  }
101
142
  end
102
143
 
144
+ def uncomplete_query
145
+ %{
146
+ mutation uncompleteTodo {
147
+ uncompleteTodo(id: #{id}) {
148
+ id
149
+ body
150
+ completed_at
151
+ }
152
+ }
153
+ }
154
+ end
155
+
103
156
  def to_params
104
157
  [:body, :completed_at].collect do |key|
105
158
  value = send(key).nil? ? "null" : "\"#{send(key)}\""
@@ -0,0 +1,79 @@
1
+ require "date"
2
+ require "wip"
3
+ require "wip/client"
4
+
5
+ class Wip::User
6
+ attr_accessor :avatar_url, :best_streak, :completed_todos_count, :first_name, :id, :last_name, :streak, :streaking, :time_zone, :url, :username, :todos
7
+
8
+ def self.default_selection(todos: {})
9
+ todos_selection = Wip::Todo.collection_query(**todos)
10
+ %{
11
+ avatar_url
12
+ best_streak
13
+ completed_todos_count
14
+ first_name
15
+ id
16
+ last_name
17
+ streak
18
+ streaking
19
+ time_zone
20
+ #{todos_selection}
21
+ url
22
+ username
23
+ }
24
+ end
25
+
26
+ def self.viewer(todos: {})
27
+ client = Wip::Client.new
28
+ find_query = %{
29
+ {
30
+ viewer {#{default_selection(todos: todos)}}
31
+ }
32
+ }
33
+ client.request find_query
34
+ parse client.data("viewer")
35
+ end
36
+
37
+ def self.find(id = nil, username: nil, todos: {})
38
+ client = Wip::Client.new
39
+ find_by = id.nil? ? "username: \"#{username}\"" : "id: #{id}"
40
+ find_query = %{
41
+ {
42
+ user(#{find_by}) {#{default_selection(todos: todos)}}
43
+ }
44
+ }
45
+ client.request find_query
46
+ parse client.data("user")
47
+ end
48
+
49
+ def initialize(avatar_url: nil, best_streak: nil, completed_todos_count: nil, first_name: nil, id: nil, last_name: nil, streak: nil, streaking: nil, time_zone: nil, url: nil, username: nil, todos: [])
50
+ @avatar_url = avatar_url
51
+ @best_streak = best_streak
52
+ @completed_todos_count = completed_todos_count
53
+ @first_name = first_name
54
+ @id = id
55
+ @last_name = last_name
56
+ @streak = streak
57
+ @streaking = streaking
58
+ @time_zone = time_zone
59
+ @url = url
60
+ @username = username
61
+ @todos = todos
62
+ end
63
+
64
+ def self.parse(data)
65
+ new.tap do |user|
66
+ data.each do |key, raw_value|
67
+ value = case key
68
+ when "id"
69
+ raw_value.to_i
70
+ when "todos"
71
+ raw_value.collect { |v| Wip::Todo.parse v }
72
+ else
73
+ raw_value
74
+ end
75
+ user.send("#{key}=", value)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -1,3 +1,3 @@
1
1
  module Wip
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wip-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Joubay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -89,7 +89,9 @@ files:
89
89
  - lib/wip/auth.rb
90
90
  - lib/wip/cli.rb
91
91
  - lib/wip/client.rb
92
+ - lib/wip/helpers/graphql_helper.rb
92
93
  - lib/wip/todo.rb
94
+ - lib/wip/user.rb
93
95
  - lib/wip/version.rb
94
96
  - wip-cli.gemspec
95
97
  homepage: https://github.com/sowenjub/wip-cli