lard 0.0.2 → 0.0.3
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/lard +27 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f852d0bc375caa5f0e0fb5eba5d1072bfaacf1b40effe0cb94b68739b53e070
|
4
|
+
data.tar.gz: '085514e8aa946f7e993bc6f414324b0b68dfbe57970373879a9700c1a8b804d6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0976e09f1788a462d4edafc82710c5a98791b2c43acf66d98da85deb79baf29933e56c28e537f3676d8af32fd4e604d030ee09ad7a4b8d5593afb19b0413464
|
7
|
+
data.tar.gz: ee4995a6e20bd35c07a15c1fbf2d0c253cfef7b93984e935bd518339ea02069bb2e06f8879ed242138d68d2da2d41a8e73ed855309de990772ebeac2cb064d5b
|
data/bin/lard
CHANGED
@@ -4,24 +4,19 @@ require 'paint'
|
|
4
4
|
require 'thor'
|
5
5
|
require 'yaml'
|
6
6
|
|
7
|
+
# Try to authenticate with ~/.lard.yml
|
8
|
+
$authenticated = false
|
7
9
|
begin
|
8
10
|
config = YAML.load_file File.expand_path('~/.lard.yml')
|
9
11
|
rescue
|
10
|
-
|
11
|
-
STDERR.puts ' Please double-check this file:'
|
12
|
-
STDERR.puts ' ~/.lard.yml'
|
13
|
-
STDERR.puts ' And make sure it has your auth token:'
|
14
|
-
STDERR.puts ' token: yourhashgoeshere'
|
15
|
-
exit 1
|
12
|
+
config = {}
|
16
13
|
end
|
17
|
-
|
18
14
|
begin
|
19
15
|
token = config['token']
|
16
|
+
$authenticated = true if token
|
20
17
|
rescue
|
21
|
-
|
22
|
-
exit 1
|
18
|
+
token = nil
|
23
19
|
end
|
24
|
-
|
25
20
|
$options = {
|
26
21
|
headers: {
|
27
22
|
'Authorization' => "Token #{token}"
|
@@ -31,6 +26,8 @@ $folders = []
|
|
31
26
|
|
32
27
|
module LardHTTP
|
33
28
|
def get(endpoint, params = nil)
|
29
|
+
puts $authenticated
|
30
|
+
raise "You're not logged in! Run 'lard login' first." unless $authenticated
|
34
31
|
query = { query: params }
|
35
32
|
opts = $options.merge query
|
36
33
|
res = self.class.get "#{prefix}#{endpoint}", opts
|
@@ -38,6 +35,7 @@ module LardHTTP
|
|
38
35
|
end
|
39
36
|
|
40
37
|
def post(endpoint, args = {})
|
38
|
+
raise "You're not logged in! Run 'lard login' first." unless $authenticated
|
41
39
|
opts = { body: args.to_json, headers: {"Content-Type" => "application/json"} }
|
42
40
|
opts[:headers].merge! $options[:headers]
|
43
41
|
res = self.class.post "#{prefix}#{endpoint}", opts
|
@@ -49,6 +47,7 @@ module LardHTTP
|
|
49
47
|
end
|
50
48
|
|
51
49
|
def raw_get(url)
|
50
|
+
raise "You're not logged in! Run 'lard login' first." unless $authenticated
|
52
51
|
JSON.parse self.class.get(url, $options).body, symbolize_names: true
|
53
52
|
end
|
54
53
|
|
@@ -234,6 +233,24 @@ class Lard < Thor
|
|
234
233
|
print_bookmark b
|
235
234
|
end
|
236
235
|
end
|
236
|
+
|
237
|
+
desc 'login [TOKEN]', 'Log in to larder with your API token'
|
238
|
+
def login(token = nil)
|
239
|
+
unless token
|
240
|
+
puts "Enter your token to save to ~/.lard.yml for lard to authenticate you with."
|
241
|
+
puts "Note: You can retrive your API token from https://larder.io/apps/clients/"
|
242
|
+
token = STDIN.readline
|
243
|
+
end
|
244
|
+
|
245
|
+
if token
|
246
|
+
if system "echo \"token: #{token}\" > $HOME/.lard.yml"
|
247
|
+
puts 'Saved token to ~/.lard.yml'
|
248
|
+
else
|
249
|
+
STDERR.puts 'Failed to save token to ~/.lard.yml!'
|
250
|
+
exit 1
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
237
254
|
end
|
238
255
|
|
239
256
|
Lard.start(ARGV)
|