zen_pro 0.1.0 → 0.2.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: '09bdf662ec106fd06acc6981f1f834c82ea21d8604b5b5cfee72ad3c83de0a50'
4
- data.tar.gz: fb856080fad9946ae7d32926226e566f1ae9abdf1617053a5cc3b1b648fc1aba
3
+ metadata.gz: 6717b4c7af84844b74a3e80afadc7dd796f60351df4a8d5ae8e661839ac250f9
4
+ data.tar.gz: f12c24be86c93f6f9fd9f91a7d998be75a94f68d0013a878a56f22d2fcd2d2ed
5
5
  SHA512:
6
- metadata.gz: e2dc2a15aa6a0ee277a0aa41bd44d24abc9a0abc16f72e4afd0c100dc36d53623b0158ffc13d182dd1a1572ec701d7eb6a7355a8a4f7f4c002eeba6b1189c169
7
- data.tar.gz: 66d71ffd60bf5bcd37326e3116d6acc509c7dae1b56a9d843e478831dd8b75cfb4fb334c3b2e808477c4ceae0d11b48b13a42c0457868e587b45df6aaecba074
6
+ metadata.gz: de210786b889dcbe52bc2fbe1f723995c9ff2d837bf06a903366b5b367a04b28aa5908a43e0d2034e6edb2c0f8a3d5170f45701b4ba2fec5facb011b330df6c8
7
+ data.tar.gz: dbf6da378c847c1ca21d01296692dd09f82f2508e74120e46fdccf3a951266725f0824b7e3e218f548900b56a0855f743842a59e4b03e7ff152d41bce46af574
data/CHANGELOG.md CHANGED
@@ -3,3 +3,9 @@
3
3
  ## [0.1.0] - 2024-05-04
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.2.0] - 2024-06-04
8
+
9
+ - Authenticate users with API token
10
+ - Show subscription inactive message if user is on Free plan or has cancelled their subscription
11
+ - Install and use Boring Generators from main branch instead of the latest released version of the gem
@@ -1,14 +1,37 @@
1
1
  require "rest-client"
2
+ require "tty-box"
2
3
 
3
4
  module ZenPro
4
5
  module Api
5
6
  class ProjectTemplate
6
7
  def fetch_details(id)
7
- response = RestClient.get("#{api_url}/#{id}")
8
+ response = RestClient.get("#{api_url}/#{id}", authorization_header(id))
8
9
 
9
10
  JSON.parse(response)
10
11
  rescue RestClient::ExceptionWithResponse => e
11
- raise e.response
12
+ prompt = TTY::Prompt.new
13
+
14
+ prompt.say <<~RE_LOGIN_MESSAGE if e.response.code == 401
15
+ You can logout and login again if the API Token had some typo/mistake:
16
+
17
+ 1. Logout first: zen_pro logout #{id}
18
+ 2. Login back and add correct API Token: zen_pro g #{id}
19
+ RE_LOGIN_MESSAGE
20
+
21
+ json_response = string_to_json(e.response)
22
+
23
+ if e.response.code == 403 && json_response &&
24
+ json_response["is_subscription_inactive"]
25
+ print TTY::Box.error <<~SUBSCRIPTION_EXPIRED_INSTRUCTIONS
26
+ It looks like your subscription has either expired or you are on Free plan.
27
+
28
+ You can upgrade your account from the following URL:
29
+
30
+ https://zeroconfigrails.com/account/teams/#{json_response["team_id"]}/billing/subscriptions
31
+ SUBSCRIPTION_EXPIRED_INSTRUCTIONS
32
+ end
33
+
34
+ raise(e)
12
35
  end
13
36
 
14
37
  private
@@ -23,6 +46,20 @@ module ZenPro
23
46
 
24
47
  "#{base_url}/api/v1/project_templates"
25
48
  end
49
+
50
+ def authorization_header(id)
51
+ netrc = Netrc.read
52
+
53
+ _project_template_id, api_token = netrc["zeroconfigrails.com/#{id}"]
54
+
55
+ { Authorization: "Bearer #{api_token}" }
56
+ end
57
+
58
+ def string_to_json(string)
59
+ JSON.parse(string)
60
+ rescue StandardError
61
+ false
62
+ end
26
63
  end
27
64
  end
28
65
  end
data/lib/zen_pro/cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "thor"
2
2
 
3
3
  require_relative "commands/generate"
4
+ require_relative "commands/session"
4
5
  require_relative "commands/configure"
5
6
 
6
7
  module ZenPro
@@ -11,9 +12,19 @@ module ZenPro
11
12
  desc "create project and configure gems",
12
13
  "Generate a Rails app and configure gems using Project Template configurations"
13
14
  def generate(project_template_id)
15
+ puts "Welcome to Zero Config Rails!\n\n"
16
+
17
+ Commands::Session.new(project_template_id).login
18
+
14
19
  Commands::Generate.run(project_template_id, options)
15
20
  end
16
21
 
22
+ desc "logout from the current session",
23
+ "Logout from the current session for a particular project template"
24
+ def logout(project_template_id)
25
+ Commands::Session.new(project_template_id).logout
26
+ end
27
+
17
28
  desc "version", "Display gem version", hide: true
18
29
  def version
19
30
  say "zen_pro/#{VERSION} #{RUBY_DESCRIPTION}"
@@ -17,9 +17,7 @@ module ZenPro
17
17
  def execute
18
18
  return unless Dir.exist?(app_name)
19
19
 
20
- if gems_configuration_commands.length.zero?
21
- return
22
- end
20
+ return if gems_configuration_commands.empty?
23
21
 
24
22
  confirm_commands_to_execute
25
23
 
@@ -47,7 +45,7 @@ module ZenPro
47
45
  .join("\n")
48
46
 
49
47
  prompt.say <<~BANNER
50
- \nRails app is now ready with initial configurations. Next, we will move on to configuring gems you have chosen by executing following commands:
48
+ \nRails app is now ready with initial configurations. Next, we will move on to configuring gems you have chosen by executing following commands:
51
49
 
52
50
  #{commands_to_display}
53
51
  BANNER
@@ -85,7 +85,7 @@ module ZenPro
85
85
  prompt.say message, color: :blue
86
86
 
87
87
  Dir.chdir(app_name) do
88
- system! "bundle add boring_generators --group=development"
88
+ system! "bundle add boring_generators --github=\"abhaynikam/boring_generators\" --branch=main"
89
89
  end
90
90
  end
91
91
 
@@ -1,7 +1,3 @@
1
- require "forwardable"
2
-
3
- require "thor"
4
-
5
1
  require_relative "create"
6
2
  require_relative "configure"
7
3
  require_relative "../api/project_template"
@@ -9,8 +5,6 @@ require_relative "../api/project_template"
9
5
  module ZenPro
10
6
  module Commands
11
7
  class Generate
12
- extend Forwardable
13
-
14
8
  def self.run(project_template_id, options)
15
9
  instance = new
16
10
 
@@ -35,15 +29,13 @@ module ZenPro
35
29
 
36
30
  prompt.error "\nOops, Zen encountered an error!"
37
31
 
38
- prompt.say "\n#{e.message}"
32
+ prompt.error "\n#{e.message}"
39
33
  end
40
34
 
41
35
  def welcome_message
42
36
  prompt.say <<~BANNER
43
- Welcome to Zero Config Rails!
44
-
45
- We will ask you a few questions while all other options will automatically be added as per application configurations in the Web App.
46
- BANNER
37
+ We will ask you few questions while all other options will automatically be added as per application configurations in the Web App.
38
+ BANNER
47
39
  end
48
40
 
49
41
  def ask_app_name
@@ -54,7 +46,7 @@ module ZenPro
54
46
  end
55
47
 
56
48
  def fetch_project_template_configurations(id)
57
- prompt.say "\nFetching your project's configurations from the server ..."
49
+ prompt.say "\nFetching your project's configurations from the server...\n\n"
58
50
 
59
51
  ZenPro::Api::ProjectTemplate.new.fetch_details(id)
60
52
  end
@@ -64,9 +56,9 @@ module ZenPro
64
56
  prompt.ok "Congratulations! Your app is fully configured.\n"
65
57
 
66
58
  prompt.say <<~BANNER
67
- 1. Run the rails server with `cd #{app_name} && rails s`
68
- 2. You can access the app at http://localhost:3000
69
- BANNER
59
+ 1. Run the rails server with `cd #{app_name} && rails s`
60
+ 2. You can access the app at http://localhost:3000
61
+ BANNER
70
62
  end
71
63
 
72
64
  private
@@ -0,0 +1,68 @@
1
+ require "netrc"
2
+
3
+ module ZenPro
4
+ module Commands
5
+ class Session
6
+ def initialize(project_template_id)
7
+ @project_template_id = project_template_id
8
+ end
9
+
10
+ def login
11
+ return api_token if logged_in?
12
+
13
+ api_token_to_save =
14
+ prompt.ask "Enter your API token for #{project_template_id}:"
15
+
16
+ netrc = Netrc.read
17
+
18
+ netrc[
19
+ "zeroconfigrails.com/#{project_template_id}"
20
+ ] = project_template_id,
21
+ api_token_to_save
22
+ netrc.save
23
+
24
+ prompt.ok "You are now logged in to the session for #{project_template_id}!\n"
25
+
26
+ api_token_to_save
27
+ rescue StandardError => e
28
+ prompt.error "\nOops, Zen encountered an error while logging you in!"
29
+
30
+ prompt.say "\n#{e.message}"
31
+
32
+ raise e
33
+ end
34
+
35
+ def logout
36
+ netrc = Netrc.read
37
+
38
+ netrc.delete("zeroconfigrails.com/#{project_template_id}")
39
+ netrc.save
40
+
41
+ prompt.ok "You are now logged out of the session for #{project_template_id}"
42
+ end
43
+
44
+ private
45
+
46
+ attr_reader :project_template_id
47
+
48
+ def prompt
49
+ return @prompt if defined?(@prompt)
50
+
51
+ TTY::Prompt.new
52
+ end
53
+
54
+ def logged_in?
55
+ !api_token.nil?
56
+ end
57
+
58
+ def api_token
59
+ netrc = Netrc.read
60
+
61
+ _project_template_id, api_token =
62
+ netrc["zeroconfigrails.com/#{project_template_id}"]
63
+
64
+ api_token
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZenPro
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zen_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prabin Poudel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-04 00:00:00.000000000 Z
11
+ date: 2024-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: thor
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,47 +39,47 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.3'
27
41
  - !ruby/object:Gem::Dependency
28
- name: tty-prompt
42
+ name: tty-box
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.23'
47
+ version: 0.7.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0.23'
54
+ version: 0.7.0
41
55
  - !ruby/object:Gem::Dependency
42
- name: tty-spinner
56
+ name: tty-prompt
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0.9'
61
+ version: '0.23'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0.9'
68
+ version: '0.23'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rest-client
70
+ name: tty-spinner
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '2.1'
75
+ version: '0.9'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '2.1'
82
+ version: '0.9'
69
83
  description: CLI for Zero Config Rails. Run the command and relax (zen mode).
70
84
  email:
71
85
  - probnpoudel@gmail.com
@@ -85,6 +99,7 @@ files:
85
99
  - lib/zen_pro/commands/configure.rb
86
100
  - lib/zen_pro/commands/create.rb
87
101
  - lib/zen_pro/commands/generate.rb
102
+ - lib/zen_pro/commands/session.rb
88
103
  - lib/zen_pro/version.rb
89
104
  homepage: https://zeroconfigrails.com
90
105
  licenses: