todo_api_cli 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/create_list +24 -0
- data/bin/sign_up +7 -8
- data/bin/todo_log_out +9 -0
- data/bin/todo_login +37 -0
- data/lib/todo_api_cli.rb +31 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bed1ce52acc5561850698b869b92f34da86fdf82a6c62745659dfe9e84af594f
|
4
|
+
data.tar.gz: 9aaf0c6bda9f6b9e348be1072ec3cd6d7e2bf1fcb8fbf70a50fcbf4d308a6484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4a22a2f46ed0ed51a95e97a7fd0aa11f0a2a9faf63e1fc623b0ec26797317dc0bd39fd7babf6c2615f9f88abf73dcd57a350b219fcbf168dd212c5c3614602b
|
7
|
+
data.tar.gz: 94d64236a5dfdc7eab9dc76b73a477f8de01b898c917c6ee8ddcf9e61dbd32a257b0f794988482411c9e831d5cc10212314fb0a68a90bc67cb6e0dd602d0922c
|
data/bin/create_list
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'todo_api_cli'
|
4
|
+
require 'keychain'
|
5
|
+
|
6
|
+
if ARGV.size != 1
|
7
|
+
puts 'You must specify the list name'
|
8
|
+
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
name = ARGV[0]
|
13
|
+
|
14
|
+
response = TodoApi::Cli::Lists.create(name: name)
|
15
|
+
|
16
|
+
if response.success?
|
17
|
+
puts 'Your list has been created'
|
18
|
+
# TODO: We should also check that we have a token before initiating the call
|
19
|
+
elsif response.status == 401
|
20
|
+
puts 'You need to be signed up before you can create lists'
|
21
|
+
else
|
22
|
+
puts 'There was an error creating your list. Please try again later.'
|
23
|
+
end
|
24
|
+
|
data/bin/sign_up
CHANGED
@@ -9,16 +9,18 @@ def prompt(*args)
|
|
9
9
|
end
|
10
10
|
|
11
11
|
if ARGV.size != 3
|
12
|
-
name = prompt
|
13
|
-
email = prompt
|
14
|
-
password = prompt
|
12
|
+
name = prompt('Enter name: ').chomp
|
13
|
+
email = prompt('Enter email: ').chomp
|
14
|
+
password = prompt('Enter password: ').chomp
|
15
15
|
else
|
16
|
+
# This should be handled using options e.g -p -n -e
|
17
|
+
# look into http://ruby-doc.org/stdlib-1.9.3/libdoc/optparse/rdoc/OptionParser.html#class-OptionParser-label-Minimal+example
|
16
18
|
name = ARGV[0]
|
17
19
|
email = ARGV[1]
|
18
20
|
password = ARGV[2]
|
19
21
|
end
|
20
22
|
|
21
|
-
response = TodoApi::Cli::Users.create(name:
|
23
|
+
response = TodoApi::Cli::Users.create(name: name, email: email, password: password)
|
22
24
|
|
23
25
|
# stores the token in the computer keychain
|
24
26
|
key_chain_item = Keychain.generic_passwords.where(service: 'todo-api').first
|
@@ -28,7 +30,4 @@ if key_chain_item
|
|
28
30
|
key_chain_item.save!
|
29
31
|
else
|
30
32
|
Keychain.generic_passwords.create(service: 'todo-api', password: response.body['session_token'])
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
end
|
data/bin/todo_log_out
ADDED
data/bin/todo_login
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'todo_api_cli'
|
4
|
+
require 'keychain'
|
5
|
+
|
6
|
+
def prompt(*args)
|
7
|
+
print(*args)
|
8
|
+
gets
|
9
|
+
end
|
10
|
+
|
11
|
+
if ARGV.size != 2
|
12
|
+
email = prompt('Enter email: ').chomp
|
13
|
+
password = prompt('Enter password: ').chomp
|
14
|
+
else
|
15
|
+
# TODO: This should be handled using options e.g -p -n -e
|
16
|
+
# look into http://ruby-doc.org/stdlib-1.9.3/libdoc/optparse/rdoc/OptionParser.html#class-OptionParser-label-Minimal+example
|
17
|
+
email = ARGV[0]
|
18
|
+
password = ARGV[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
response = TodoApi::Cli::Users.login(email: email, password: password)
|
22
|
+
|
23
|
+
# stores the token in the computer keychain
|
24
|
+
if response.success?
|
25
|
+
key_chain_item = Keychain.generic_passwords.where(service: 'todo-api').first
|
26
|
+
|
27
|
+
if key_chain_item
|
28
|
+
key_chain_item.password = response.body['session_token']
|
29
|
+
key_chain_item.save!
|
30
|
+
else
|
31
|
+
Keychain.generic_passwords.create(service: 'todo-api', password: response.body['session_token'])
|
32
|
+
end
|
33
|
+
|
34
|
+
puts 'You have succesfully logged in!'
|
35
|
+
else
|
36
|
+
puts response.body['error']
|
37
|
+
end
|
data/lib/todo_api_cli.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'faraday_middleware'
|
3
3
|
|
4
|
+
#TODO: this should be top level that requires all the other scopes e.g users, lists etc.
|
5
|
+
|
4
6
|
module TodoApi
|
5
7
|
API_URL='http://localhost:9393'
|
6
8
|
|
@@ -13,6 +15,35 @@ module TodoApi
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
def self.login(email:, password:)
|
19
|
+
client.post do |req|
|
20
|
+
req.url '/login'
|
21
|
+
req.body = { email: email, password: password }.to_json
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.client
|
26
|
+
@@conn ||= Faraday.new(url: TodoApi::API_URL) do |f|
|
27
|
+
f.request :url_encoded
|
28
|
+
f.adapter Faraday.default_adapter
|
29
|
+
f.request :url_encoded
|
30
|
+
f.request :json
|
31
|
+
f.response :json, content_type: /\bjson$/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Lists
|
37
|
+
def self.create(name:)
|
38
|
+
client.post do |req|
|
39
|
+
req.url '/lists'
|
40
|
+
req.body = { name: name }.to_json
|
41
|
+
req.headers['Authorization'] = Keychain.generic_passwords.where(:service =>'todo-api').first.password
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# ugly as fuck. Need to split this classes into different scopes
|
46
|
+
# and extrac this into a Faraday client module
|
16
47
|
def self.client
|
17
48
|
@@conn ||= Faraday.new(url: TodoApi::API_URL) do |f|
|
18
49
|
f.request :url_encoded
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo_api_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Poleo
|
@@ -84,10 +84,16 @@ description:
|
|
84
84
|
email:
|
85
85
|
executables:
|
86
86
|
- sign_up
|
87
|
+
- todo_login
|
88
|
+
- create_list
|
89
|
+
- todo_log_out
|
87
90
|
extensions: []
|
88
91
|
extra_rdoc_files: []
|
89
92
|
files:
|
93
|
+
- bin/create_list
|
90
94
|
- bin/sign_up
|
95
|
+
- bin/todo_log_out
|
96
|
+
- bin/todo_login
|
91
97
|
- lib/todo_api_cli.rb
|
92
98
|
homepage:
|
93
99
|
licenses: []
|