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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/lard +27 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb8adc7d1714d35d1dbf4407d142a7344dc46d4be2d0f2cf5a6ea7c0b064b683
4
- data.tar.gz: 0b68c1d08cc99264b70e77e2f087044e5a6459c4865fb28209eb915dbbd07b73
3
+ metadata.gz: 7f852d0bc375caa5f0e0fb5eba5d1072bfaacf1b40effe0cb94b68739b53e070
4
+ data.tar.gz: '085514e8aa946f7e993bc6f414324b0b68dfbe57970373879a9700c1a8b804d6'
5
5
  SHA512:
6
- metadata.gz: 34d871021eab9850c6c5c4a16e5c39e18367bd6674c7fa7faa413219044c088ce63f73ed68fbeb5567d33ea15bbd453f67928f025d6b905a2d250b8dae99af84
7
- data.tar.gz: 325d73f06dfff40b8617cfbdbc71d3e55895e1c5f01800c8b9aaf070f56af462db7d59f325e678edd3a4c2afd8b89358f3e192267281ab325ef74d2020c516ce
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
- STDERR.puts 'Unable to find your .lard.yml!'
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
- STDERR.puts 'No token in ~/.lard.yml!'
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hawkins