envirobly 1.6.1 → 1.7.0

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: 49c3237a5570bb1839a02b5cbdfb3c70725c6e200841a09b7299b46e62efb3c2
4
- data.tar.gz: b90bcd5afcf383bfdac23320870c3c420cf30b842f1ec67dba152f94a9382ef3
3
+ metadata.gz: 89cfd488c2765b1d8bc3205d34cf6d4e49230f4eb3a371cdb05b6785d690c955
4
+ data.tar.gz: f52f5be5eaf21eb35273f3d5d9da22af91ca2d6078faedcd1e875ebbcdab13e1
5
5
  SHA512:
6
- metadata.gz: c57b8f6e3e791afc1d392db80f501e1ee10cc7229465b3c3e10e300fe3f786ace269b79660b624ef099b2e0e1eddc8c9d4e03e8ac05d20b73f824f896223b6b9
7
- data.tar.gz: 448da4b7847e9d067e722bbfcb1b011e3573259225a0ff2bf0114b8c757195d9b4d78096c47fccd137aade3d5508acafb19fba73a00a55b14454618b882c6ef7
6
+ metadata.gz: 9f8e1e766e47c1a7765cf96c0b893ab8cec55a16feb1916423f944396bdf9c1c17c215b4ed7f415217ccc8bb4c559331b687e3c91e71b698ea9ed34d81ec2c48
7
+ data.tar.gz: 2c0d7c929da365fa21c4a946049da551c6ab5eb6c6492babf138b64a01d0f7f43f5c99693989c65bb260ac7ebbc1a0ed47d7bccea633df6ecbedcd2afe4ad0ed
@@ -3,86 +3,98 @@
3
3
  require "fileutils"
4
4
  require "pathname"
5
5
 
6
- class Envirobly::AccessToken
7
- include Envirobly::Colorize
6
+ module Envirobly
7
+ class AccessToken
8
+ include Colorize
8
9
 
9
- attr_reader :shell
10
+ APP_NAME = "envirobly"
10
11
 
11
- class << self
12
- def destroy
13
- if File.exist?(path)
14
- FileUtils.rm path
15
- end
16
- end
12
+ attr_reader :shell
17
13
 
18
- def dir
19
- if ENV["XDG_CONFIG_HOME"]
20
- Pathname.new(ENV["XDG_CONFIG_HOME"]).join("envirobly")
21
- else
22
- Pathname.new(Dir.home).join(".envirobly")
14
+ class << self
15
+ def destroy
16
+ if File.exist?(path)
17
+ FileUtils.rm path
18
+ end
23
19
  end
24
- end
25
20
 
26
- def path
27
- dir.join "access_token"
28
- end
29
- end
21
+ def storage_base_dir
22
+ if dir = ENV["ENVIROBLY_CLI_DATA_HOME"].presence
23
+ return dir
24
+ end
30
25
 
31
- def initialize(token = ENV["ENVIROBLY_ACCESS_TOKEN"].presence, shell: nil)
32
- @shell = shell
26
+ if Gem.win_platform?
27
+ ENV["APPDATA"] || File.join(Dir.home, "AppData", "Roaming")
28
+ else
29
+ ENV["XDG_DATA_HOME"] || File.join(Dir.home, ".local", "share")
30
+ end
31
+ end
33
32
 
34
- if token.blank? && File.exist?(self.class.path)
35
- @token = File.read(self.class.path)
36
- else
37
- @token = token
38
- end
39
- end
33
+ def storage_dir
34
+ File.join(storage_base_dir, APP_NAME)
35
+ end
40
36
 
41
- def save
42
- FileUtils.mkdir_p self.class.dir
43
- File.write self.class.path, @token
44
- File.chmod 0600, self.class.path
45
- end
37
+ def path
38
+ Pathname.new(storage_dir).join "access_token"
39
+ end
40
+ end
46
41
 
47
- def as_http_bearer
48
- "Bearer #{@token}"
49
- end
42
+ def initialize(token = ENV["ENVIROBLY_ACCESS_TOKEN"].presence, shell: nil)
43
+ @shell = shell
50
44
 
51
- def require!
52
- return if @token.present?
45
+ if token.blank? && File.exist?(self.class.path)
46
+ @token = File.read(self.class.path)
47
+ else
48
+ @token = token
49
+ end
50
+ end
53
51
 
54
- shell.say "This action requires you to be signed in."
55
- shell.say "Please visit https://on.envirobly.com/profile/access_tokens"
56
- shell.say "to generate an access token and then paste it in here."
57
- shell.say
52
+ def save
53
+ FileUtils.mkdir_p self.class.storage_dir
54
+ File.write self.class.path, @token
55
+ File.chmod 0600, self.class.path
56
+ end
58
57
 
59
- set
60
- end
58
+ def as_http_bearer
59
+ "Bearer #{@token}"
60
+ end
61
61
 
62
- def set
63
- @token = nil
62
+ def require!
63
+ return if @token.present?
64
64
 
65
- while @token.blank?
66
- begin
67
- @token = shell.ask("Access Token:", echo: false)
68
- rescue Interrupt
69
- shell.say
70
- shell.say_error "Cancelled"
71
- exit
72
- end
65
+ shell.say "This action requires you to be signed in."
66
+ shell.say "Please visit https://on.envirobly.com/profile/access_tokens"
67
+ shell.say "to generate an access token and then paste it in here."
68
+ shell.say
73
69
 
74
- api = Envirobly::Api.new(access_token: self, exit_on_error: false)
70
+ set
71
+ end
75
72
 
76
- # TODO: Eventually replace with custom `whoami` API that returns name, email...
77
- if api.list_accounts.success?
78
- save
79
- shell.say
80
- shell.say "Successfully signed in "
81
- shell.say green_check
82
- else
83
- shell.say
84
- shell.say_error "This token is invalid. Please try again"
85
- @token = nil
73
+ def set
74
+ @token = nil
75
+
76
+ while @token.blank?
77
+ begin
78
+ @token = shell.ask("Access Token:", echo: false)
79
+ rescue Interrupt
80
+ shell.say
81
+ shell.say_error "Cancelled"
82
+ exit
83
+ end
84
+
85
+ api = Api.new(access_token: self, exit_on_error: false)
86
+
87
+ # TODO: Eventually replace with custom `whoami` API that returns name, email...
88
+ if api.list_accounts.success?
89
+ save
90
+ shell.say
91
+ shell.say "Successfully signed in "
92
+ shell.say green_check
93
+ else
94
+ shell.say
95
+ shell.say_error "This token is invalid. Please try again"
96
+ @token = nil
97
+ end
86
98
  end
87
99
  end
88
100
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Envirobly
4
- VERSION = "1.6.1"
4
+ VERSION = "1.7.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envirobly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starsi
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.7.1
217
+ rubygems_version: 3.7.2
218
218
  specification_version: 4
219
219
  summary: Envirobly command line interface
220
220
  test_files: []