rails-blocks-cli 0.1.4 → 0.1.5

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/rails_blocks/cli.rb +30 -5
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 968eedc1f9c0ab74b6eea46839b1cc3fd797cbbad8e9e435fd941a9583ed80a6
4
- data.tar.gz: 2d4eeeeec278e666cdf0dfac50b0e8dc48ebf2907c09b53b189106511b83c95c
3
+ metadata.gz: 6c87aed14419d63248e9ef90191e488185d312908937f2b24893fc8b1d6c3bcc
4
+ data.tar.gz: f8ae64409d5cb609e397e463fdffbd4c3ce6f7028fb87e57bd54f4b4b4ed9f47
5
5
  SHA512:
6
- metadata.gz: 9f1340ade753c2ddbcf80a6722cb077b20205306f79f9d790188dd52d81b178e31f49e9d6f8968c23ec0f39384dab7b32fd4d5a20c5172816c8442b370d42bad
7
- data.tar.gz: e47e078588bf254704e7e59714429c87162f966f1adcaa8ff161bd2808f58b70a46da1e7853864e51cc22b2014a9fb9bfd6730b3c432f16edf758dbcba69adbd
6
+ metadata.gz: 5ec78cb9dd3561566105460a5aedc81a07c8a7ff4a3b22a3446a743eb457c3c7bb9b4fbabc9a73b1559d7e38f85e480e1adc37bf7bdfed32321985154ad71e51
7
+ data.tar.gz: 32ef4293378e1f9aee1a761d4d0ca3388d12267895be3ed218fa48394389a1a90fa1f1e294e53dd99528a851bac6183ad08807f650478fc03d4d1964f1c768ed
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Static-first installer for Rails Blocks components.
4
4
 
5
- Free component metadata and packages are read from the public `Rails-Blocks` GitHub artifact registry. The Rails Blocks app is only contacted for login, account status, and Pro component access.
5
+ Free components are installed from the public `Rails-Blocks/components` GitHub repo. Sign in only when you want account status or Pro component access.
6
6
 
7
7
  ## Example
8
8
 
@@ -8,10 +8,12 @@ require "zip"
8
8
 
9
9
  module RailsBlocks
10
10
  class CLI
11
- DownloadError = Class.new(StandardError)
11
+ class DownloadError < StandardError
12
+ end
12
13
 
13
14
  DEFAULT_REGISTRY_URL = "https://raw.githubusercontent.com/Rails-Blocks/components/main/registry.json".freeze
14
15
  DEFAULT_API_URL = "https://railsblocks.com".freeze
16
+ DEFAULT_PRO_URL = "https://railsblocks.com/pro".freeze
15
17
 
16
18
  def initialize(argv)
17
19
  @argv = argv.dup
@@ -223,7 +225,7 @@ module RailsBlocks
223
225
  end
224
226
 
225
227
  def logout
226
- save_config(config.reject { |key, _| key == "api_token" })
228
+ save_config(config.except("api_token"))
227
229
  puts "Logged out."
228
230
  end
229
231
 
@@ -441,7 +443,7 @@ module RailsBlocks
441
443
  end
442
444
 
443
445
  counts[:changed] += 1
444
- puts unified_diff(old_content, new_content, destination.exist? ? display_path(destination) : "/dev/null", display_path(destination))
446
+ puts unified_diff(old_content, new_content, destination.exist? ? display_path(destination) : File::NULL, display_path(destination))
445
447
  end
446
448
 
447
449
  def update_file(destination, new_content, counts)
@@ -543,7 +545,7 @@ module RailsBlocks
543
545
  return download(URI.join(url, response["location"]).to_s, redirects: redirects - 1)
544
546
  end
545
547
 
546
- raise DownloadError, "#{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
548
+ raise DownloadError, api_error_message(response) unless response.is_a?(Net::HTTPSuccess)
547
549
 
548
550
  response.body
549
551
  end
@@ -563,11 +565,34 @@ module RailsBlocks
563
565
  request["Authorization"] = "Bearer #{api_token}" if auth && api_token
564
566
  request.body = JSON.generate(body) if body
565
567
  response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
566
- abort(response.body) unless response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPCreated)
568
+ abort(api_error_message(response)) unless response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPCreated)
567
569
 
568
570
  JSON.parse(response.body)
569
571
  end
570
572
 
573
+ def api_error_message(response)
574
+ parsed = JSON.parse(response.body)
575
+ message = parsed["message"].to_s.strip
576
+
577
+ case parsed["error"]
578
+ when "pro_required"
579
+ upgrade_url = parsed["upgrade_url"].to_s.strip
580
+ [
581
+ message.empty? ? "Rails Blocks Pro is required for this component." : message,
582
+ "Upgrade to Rails Blocks Pro: #{upgrade_url.empty? ? DEFAULT_PRO_URL : upgrade_url}"
583
+ ].join("\n")
584
+ when "unauthorized"
585
+ [
586
+ message.empty? ? "Provide a valid Rails Blocks API token." : message,
587
+ "Run `rails-blocks login` if you already have Pro access, or upgrade at #{DEFAULT_PRO_URL}."
588
+ ].join("\n")
589
+ else
590
+ message.empty? ? "#{response.code} #{response.message}" : message
591
+ end
592
+ rescue JSON::ParserError
593
+ "#{response.code} #{response.message}"
594
+ end
595
+
571
596
  def api_url_for(path)
572
597
  return path if path.to_s.match?(%r{\Ahttps?://})
573
598
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-blocks-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Blocks
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '2.3'
18
+ version: '3.4'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '2.3'
25
+ version: '3.4'
26
26
  executables:
27
27
  - rails-blocks
28
28
  extensions: []
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubygems_version: 4.0.3
53
+ rubygems_version: 4.0.23
54
54
  specification_version: 4
55
55
  summary: Install Rails Blocks components from the command line
56
56
  test_files: []