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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5263128c0393604a7bded499596d8dfa6e892714014f0492f54f83d8ba723e0c
4
- data.tar.gz: d0f077d8994c18eaeff508d1537a2aaa314c09330f295e52eef9dae0866b6d48
3
+ metadata.gz: bed1ce52acc5561850698b869b92f34da86fdf82a6c62745659dfe9e84af594f
4
+ data.tar.gz: 9aaf0c6bda9f6b9e348be1072ec3cd6d7e2bf1fcb8fbf70a50fcbf4d308a6484
5
5
  SHA512:
6
- metadata.gz: 4d02c0227c39de50a8f646a76f84dd71b9b895175ed8b5716a60befad915ba4829613db4ea3c21f823ccef768051dcc985948fdd9470717afc24aa3477755339
7
- data.tar.gz: 787f8a07ac3a07189c5e9bae7593ac6234169694d20c04edc6d476bfc4b187e910e5ba1ea0ac68797e5099d47513cb8fba9f1b45ea412d9b3ecfb571b24b01ae
6
+ metadata.gz: c4a22a2f46ed0ed51a95e97a7fd0aa11f0a2a9faf63e1fc623b0ec26797317dc0bd39fd7babf6c2615f9f88abf73dcd57a350b219fcbf168dd212c5c3614602b
7
+ data.tar.gz: 94d64236a5dfdc7eab9dc76b73a477f8de01b898c917c6ee8ddcf9e61dbd32a257b0f794988482411c9e831d5cc10212314fb0a68a90bc67cb6e0dd602d0922c
@@ -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
+
@@ -9,16 +9,18 @@ def prompt(*args)
9
9
  end
10
10
 
11
11
  if ARGV.size != 3
12
- name = prompt 'Enter name: '
13
- email = prompt 'Enter email: '
14
- password = prompt 'Enter password: '
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: ARGV[0], email: ARGV[1], password: ARGV[2])
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
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ item = Keychain.generic_passwords.where(service: 'todo-api').first
4
+
5
+ if item
6
+ item.delete
7
+ end
8
+
9
+ puts "You've successfully logged out"
@@ -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
@@ -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.3
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: []