razor-client 1.9.1 → 1.9.4

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 (66) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/release.yml +24 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +4 -0
  5. data/.yardopts +2 -0
  6. data/CODEOWNERS +1 -0
  7. data/Gemfile +42 -0
  8. data/NEWS.md +24 -0
  9. data/Rakefile +69 -0
  10. data/bin/razor +10 -13
  11. data/ext/build_defaults.yaml +20 -0
  12. data/ext/project_data.yaml +38 -0
  13. data/lib/razor/cli.rb +6 -0
  14. data/lib/razor/cli/command.rb +3 -3
  15. data/lib/razor/cli/navigate.rb +28 -19
  16. data/lib/razor/cli/parse.rb +18 -25
  17. data/lib/razor/cli/version.rb +1 -1
  18. data/razor-client.gemspec +35 -0
  19. data/spec/cli/command_spec.rb +21 -0
  20. data/spec/cli/format_spec.rb +10 -16
  21. data/spec/cli/navigate_spec.rb +10 -12
  22. data/spec/cli/parse_spec.rb +5 -3
  23. data/spec/fixtures/vcr/Razor_CLI_Navigate/accept-language_header/should_allow_other_accept-language_headers.yml +10 -10
  24. data/spec/fixtures/vcr/Razor_CLI_Navigate/accept-language_header/should_set_the_accept-language_header.yml +10 -10
  25. data/spec/fixtures/vcr/Razor_CLI_Navigate/argument_formatting/should_allow_in_string.yml +37 -39
  26. data/spec/fixtures/vcr/Razor_CLI_Navigate/argument_formatting/should_allow_single-dash_with_single_character_flag.yml +39 -41
  27. data/spec/fixtures/vcr/Razor_CLI_Navigate/argument_formatting/should_allow_spaces.yml +111 -117
  28. data/spec/fixtures/vcr/Razor_CLI_Navigate/argument_formatting/should_not_allow_double-dash_with_single_character_flag.yml +21 -21
  29. data/spec/fixtures/vcr/Razor_CLI_Navigate/argument_formatting/should_not_allow_single-dash_with_multiple_character_flag.yml +21 -21
  30. data/spec/fixtures/vcr/Razor_CLI_Navigate/for_command_help/should_provide_command_help_for_razor_--help_command_.yml +19 -19
  31. data/spec/fixtures/vcr/Razor_CLI_Navigate/for_command_help/should_provide_command_help_for_razor_-h_command_.yml +19 -19
  32. data/spec/fixtures/vcr/Razor_CLI_Navigate/for_command_help/should_provide_command_help_for_razor_command_--help_.yml +19 -19
  33. data/spec/fixtures/vcr/Razor_CLI_Navigate/for_command_help/should_provide_command_help_for_razor_command_-h_.yml +19 -19
  34. data/spec/fixtures/vcr/Razor_CLI_Navigate/for_command_help/should_provide_command_help_for_razor_command_help_.yml +19 -19
  35. data/spec/fixtures/vcr/Razor_CLI_Navigate/for_command_help/should_provide_command_help_for_razor_help_command_.yml +19 -19
  36. data/spec/fixtures/vcr/Razor_CLI_Navigate/positional_arguments/should_allow_the_use_of_positional_arguments.yml +136 -144
  37. data/spec/fixtures/vcr/Razor_CLI_Navigate/positional_arguments/should_fail_with_too_many_positional_arguments.yml +21 -21
  38. data/spec/fixtures/vcr/Razor_CLI_Navigate/when_the_collections_endpoint_has_a_depth_parameter/should_be_set_to_1_when_the_endpoint_is_the_final_query.yml +18 -18
  39. data/spec/fixtures/vcr/Razor_CLI_Navigate/when_the_collections_endpoint_has_a_depth_parameter/should_not_be_exposed_to_the_user.yml +10 -10
  40. data/spec/fixtures/vcr/Razor_CLI_Navigate/when_the_collections_endpoint_has_a_depth_parameter/should_not_carry-over_to_later_requests_in_a_nested_query.yml +65 -67
  41. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_a_single_item_path/.yml +77 -0
  42. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_an_invalid_path/.yml +40 -0
  43. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_authentication/should_preserve_that_across_navigation.yml +17 -21
  44. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_authentication/should_supply_that_to_the_API_service.yml +10 -12
  45. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_invalid_parameter/should_fail_with_bad_JSON.yml +21 -21
  46. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_invalid_parameter/should_fail_with_malformed_argument.yml +19 -19
  47. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_multiple_arguments_with_same_name/combining_as_an_array/should_merge_an_array_into_an_existing_array.yml +187 -197
  48. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_multiple_arguments_with_same_name/combining_as_an_array/should_merge_the_arguments_as_an_array.yml +187 -197
  49. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_multiple_arguments_with_same_name/combining_as_an_array/should_merge_the_arguments_into_an_existing_array.yml +187 -197
  50. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_multiple_arguments_with_same_name/combining_as_an_object/should_construct_a_json_object.yml +39 -41
  51. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_multiple_arguments_with_same_name/combining_as_an_object/should_construct_a_json_object_with_unicode.yml +76 -80
  52. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_multiple_arguments_with_same_name/combining_as_an_object/should_fail_with_mixed_types_array_then_hash_.yml +21 -21
  53. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_multiple_arguments_with_same_name/combining_as_an_object/should_fail_with_mixed_types_hash_then_array_.yml +21 -21
  54. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_no_parameters/should_fail_with_bad_JSON.yml +19 -19
  55. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_no_path/.yml +40 -0
  56. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_query_parameters/should_append_limit.yml +17 -21
  57. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_query_parameters/should_append_start.yml +17 -21
  58. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_query_parameters/should_not_fail_when_query_returns_details_for_one_item.yml +61 -69
  59. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_query_parameters/should_store_query_without_query_parameters.yml +105 -117
  60. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_query_parameters/should_throw_an_error_if_the_query_parameter_is_not_in_the_API.yml +10 -12
  61. data/spec/fixtures/vcr/Razor_CLI_Navigate/with_query_parameters/should_throw_an_error_if_the_query_parameter_is_not_in_the_API_from_a_single_item.yml +54 -60
  62. data/spec/fixtures/vcr/Razor_CLI_Parse/_new/_help/.yml +40 -0
  63. data/spec/fixtures/vcr/Razor_CLI_Parse/_new/_help/should_print_a_list_of_known_endpoints.yml +10 -10
  64. data/spec/spec_helper.rb +1 -1
  65. data/spec/testing.md +4 -2
  66. metadata +69 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f4aba07bc09d83bcbce351964a713117efb1bca2
4
- data.tar.gz: 1db80933d091c04c2048cbb8a543e919f9ced02c
2
+ SHA256:
3
+ metadata.gz: 7240c2a4e68fab8d04ae7084b400d7a7bd472858c2190b3dca337577e5aa5cf7
4
+ data.tar.gz: 3f3b980e70b2d2de30f8fb49f4b8a34ad6ac67daf4e76b2d944250b1dd09894c
5
5
  SHA512:
6
- metadata.gz: 5b9225d18b7414792a628ec7017bb62c9ef417369d92293b00627913a41a3760019ec4378dfeb2642fd45058733e9881a6d21db0736373929eb84bb0b51dd4d9
7
- data.tar.gz: 710838e176dd8b9d8e58159e505df289071ce792d5e8bb64c311be3cb26d3ed1041a0ee15ecd1cb7700039f6415fec6d10055119702670c98b952efc4774dec4
6
+ metadata.gz: cf8b0cf692487781a22c34b2df625ad729a39fc283fb3cc3b6abd0beefec6d8392b1d10a33eeae05d94f21677ea5cf36f9755fc6365d1ca38862fbadad7b7a9c
7
+ data.tar.gz: 5c56d03d1161b3c9d74c66b9ddb82123e072e24cebd7e42f703d579cc13d1e696f40d259670b673773ffb1b234fb76a38876528bdb7a6642199a61331a6a013e
@@ -0,0 +1,24 @@
1
+ name: Gem release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - refs/tags/*
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v1
14
+ - name: Build gem
15
+ uses: scarhand/actions-ruby@master
16
+ with:
17
+ args: build *.gemspec
18
+ - name: Publish gem
19
+ uses: scarhand/actions-ruby@master
20
+ env:
21
+ RUBYGEMS_AUTH_TOKEN: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
22
+ with:
23
+ args: push *.gem
24
+
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ log/*
2
+ pkg/
3
+ /config.yaml
4
+ /.yardoc
5
+ /Gemfile.local*
6
+ /coverage
7
+ /.project
8
+ /ext/packaging/
9
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ script: "bundle exec rspec spec"
3
+ notifications:
4
+ email: false
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --markup-provider=redcarpet
2
+ --markup=markdown
data/CODEOWNERS ADDED
@@ -0,0 +1 @@
1
+ * @puppetlabs/razor-maintainers
data/Gemfile ADDED
@@ -0,0 +1,42 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ def location_for(place, fake_version = nil)
6
+ if place =~ /^(git[:@][^#]*)#(.*)/
7
+ [fake_version, { :git => $1, :branch => $2, :require => false }].compact
8
+ elsif place =~ /^file:\/\/(.*)/
9
+ ['>= 0', { :path => File.expand_path($1), :require => false }]
10
+ else
11
+ [place, { :require => false }]
12
+ end
13
+ end
14
+
15
+ group :packaging do
16
+ gem 'packaging', *location_for(ENV['PACKAGING_LOCATION'] || '~> 0.99')
17
+ end
18
+
19
+ group :doc do
20
+ gem 'yard'
21
+ gem 'kramdown'
22
+ end
23
+
24
+ # This group will be excluded by default in `torquebox archive`
25
+ group :test do
26
+ gem 'public_suffix', '~> 1.4.6'
27
+ gem 'rack-test'
28
+ gem 'rspec', '~> 2.13.0'
29
+ gem 'rspec-core', '~> 2.13.1'
30
+ gem 'rspec-expectations', '~> 2.13.0'
31
+ gem 'rspec-mocks', '~> 2.13.1'
32
+ gem 'simplecov'
33
+ gem 'webmock', '~> 3.3.0'
34
+ gem 'vcr', '~> 4.0.0'
35
+ end
36
+
37
+ # This allows you to create `Gemfile.local` and have it loaded automatically;
38
+ # the purpose of this is to allow you to put additional development gems
39
+ # somewhere convenient without having to constantly mess with this file.
40
+ #
41
+ # Gemfile.local is in the .gitignore file; do not check one in!
42
+ eval(File.read(File.dirname(__FILE__) + '/Gemfile.local'), binding) rescue nil
data/NEWS.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Razor Client Release Notes
2
2
 
3
+ ## 1.9.4 - 2019-08-26
4
+
5
+ * IMPROVEMENT: Moved from `rest-client` to `faraday` due to increasing
6
+ dependency issues with `rest-client`.
7
+
8
+ ## 1.9.3 - 2019-08-19 (yanked)
9
+
10
+ * BUGFIX: The `unf` gem dependency referenced a prerelease version of a gem.
11
+ Rather than force the use of `--pre` when installing the gem, we will pin
12
+ back to the released version, which requires GCC to build native extensions.
13
+
14
+ ## 1.9.2 - 2019-08-14 (yanked)
15
+
16
+ * BUGFIX: Fixed error output when number or null datatypes are invalid.
17
+ * IMPROVEMENT: Now exits with status code 1 if login credentials are missing.
18
+ * IMPROVEMENT: Updated gem dependencies.
19
+ * IMPROVEMENT: Better error handling for REST exceptions returned from the
20
+ Razor server.
21
+ * IMPROVEMENT: Removed Gemfile.lock from repository. This broadens the spectrum
22
+ of which gems can be used as dependencies for this gem. This is especially
23
+ useful for gem dependencies that become outdated or obsolete.
24
+ * BUGFIX: Pinned a version of the `gettext-setup` gem which caused an error if
25
+ the version was too old.
26
+
3
27
  ## 1.9.1 - 2018-06-07
4
28
 
5
29
  * NEW: Use the server's `depth` parameter if it is supported. This will
data/Rakefile ADDED
@@ -0,0 +1,69 @@
1
+ require 'rake'
2
+ require 'yaml'
3
+
4
+ # Needed to make the client work on Ruby 1.8.7
5
+ unless Kernel.respond_to?(:require_relative)
6
+ module Kernel
7
+ def require_relative(path)
8
+ require File.join(File.dirname(caller[0]), path.to_str)
9
+ end
10
+ end
11
+ end
12
+
13
+ require_relative 'spec/vcr_library'
14
+
15
+ namespace :bundler do
16
+ task :setup do
17
+ require 'bundler/setup'
18
+ end
19
+ end
20
+
21
+ if defined?(RSpec::Core::RakeTask)
22
+ namespace :spec do
23
+ require 'rspec/core'
24
+ require 'rspec/core/rake_task'
25
+
26
+ desc <<EOS
27
+ Run all specs. Set VCR_RECORD to 'all' to rerecord and to 'new_episodes'
28
+ to record new tests. Tapes are in #{VCR_LIBRARY}
29
+ EOS
30
+ RSpec::Core::RakeTask.new(:all => :"bundler:setup") do |t|
31
+ t.pattern = 'spec/**/*_spec.rb'
32
+ end
33
+ end
34
+ end
35
+
36
+ desc "Erase all VCR recordings"
37
+ task :"vcr:erase" do
38
+ erase_vcr_library
39
+ end
40
+
41
+ ##############################################################################
42
+ # Support for our internal packaging toolchain. Most people outside of Puppet
43
+ # Labs will never actually need to deal with these.
44
+ begin
45
+ require 'packaging'
46
+ Pkg::Util::RakeUtils.load_packaging_tasks
47
+ rescue LoadError => e
48
+ puts "Error loading packaging rake tasks: #{e}"
49
+ end
50
+
51
+ # Kept for backwards compatibility
52
+ namespace :package do
53
+ desc "Bootstrap packaging automation, e.g. clone into packaging repo"
54
+ task :bootstrap do
55
+ puts 'Bootstrap is no longer needed, using packaging-as-a-gem'
56
+ end
57
+
58
+ desc "Remove all cloned packaging automation"
59
+ task :implode do
60
+ puts 'Implode is no longer needed, using packaging-as-a-gem'
61
+ end
62
+ end
63
+
64
+ begin
65
+ spec = Gem::Specification.find_by_name 'gettext-setup'
66
+ load "#{spec.gem_dir}/lib/tasks/gettext.rake"
67
+ GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
68
+ rescue LoadError
69
+ end
data/bin/razor CHANGED
@@ -32,8 +32,6 @@ end
32
32
  begin
33
33
  parse = Razor::CLI::Parse.new(ARGV)
34
34
 
35
- navigate = parse.navigate
36
-
37
35
  if parse.show_version?
38
36
  version, exit_code = parse.version
39
37
  puts version
@@ -46,34 +44,33 @@ begin
46
44
  exit exitcode
47
45
  end
48
46
 
47
+ navigate = parse.navigate
48
+
49
49
  document = navigate.get_document
50
50
  url = parse.navigate.last_url
51
51
  result = format_document document, parse
52
52
  # TRANSLATORS: This is a template for all results that the client outputs.
53
53
  puts _("From %{url}:\n\n%{result}\n\n") % {url: url, result: result}
54
- rescue Razor::CLI::InvalidURIError => e
55
- die e.message
56
- rescue RestClient::Unauthorized
57
- puts _(<<-UNAUTH) % {url: url}
58
- Error: Credentials are required to connect to the server at %{url}"
59
- UNAUTH
54
+ rescue Razor::CLI::InvalidURIError, Razor::CLI::UnauthorizedError => e
55
+ puts e.message
56
+ die
60
57
  rescue OptionParser::InvalidOption => e
61
58
  # TRANSLATORS: This occurs when invalid flags are passed in the navigation.
62
59
  die _("%{error}\nTry 'razor --help' for more information") %
63
60
  {error: e.message}
64
- rescue SocketError, Errno::ECONNREFUSED => e
61
+ rescue SocketError, Faraday::ConnectionFailed => e
65
62
  puts _("Error: Could not connect to the server at %{url}\n" +
66
63
  " %{error}") % {url: parse.api_url, error: e}
67
64
  die
68
- rescue RestClient::SSLCertificateNotVerified
65
+ rescue Faraday::SSLError
69
66
  puts _("Error: SSL certificate could not be verified against known CA " +
70
67
  "certificates.\n To turn off verification, use the -k or --insecure option.")
71
68
  die
72
- rescue RestClient::Exception => e
69
+ rescue Faraday::Error => e
73
70
  r = e.response
74
71
  unexpected_error(e) if r.nil?
75
- request_type = r.args[:method].to_s.upcase
76
- url = r.args[:url]
72
+ request_type = r.request.method.to_s.upcase
73
+ url = r.request.url
77
74
  puts _("Error from doing %{request_type} %{url}") % {request_type: request_type, url: url}
78
75
  puts e.message
79
76
  begin
@@ -0,0 +1,20 @@
1
+ ---
2
+ packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=1.0.x'
3
+ packaging_repo: 'packaging'
4
+ default_cow: ''
5
+ cows: ''
6
+ pbuild_conf: '/etc/pbuilderrc'
7
+ packager: 'puppet'
8
+ gpg_name: 'release@puppet.com'
9
+ gpg_key: '7F438280EF8D349F'
10
+ sign_tar: FALSE
11
+ # a space separated list of mock configs
12
+ final_mocks: ''
13
+ yum_host: 'yum.puppetlabs.com'
14
+ build_gem: TRUE
15
+ build_dmg: FALSE
16
+ build_ips: FALSE
17
+ build_pe: FALSE
18
+ apt_host: 'apt.puppetlabs.com'
19
+ apt_repo_url: 'http://apt.puppetlabs.com'
20
+ tar_host: 'downloads.puppetlabs.com'
@@ -0,0 +1,38 @@
1
+ ---
2
+ project: 'razor-client'
3
+ author: 'Puppet Labs'
4
+ email: 'info@puppetlabs.com'
5
+ homepage: 'http://puppetlabs.com/puppet/puppet-enterprise'
6
+ summary: 'Razor is an advanced provisioning application'
7
+ description: |
8
+ Razor is an advanced provisioning application which can deploy both bare-metal
9
+ and virtual systems. It's aimed at solving the problem of how to bring new
10
+ metal into a state where your existing DevOps/configuration management
11
+ workflows can take it over.
12
+
13
+ This provides the client application gem, used to provide CLI access and control
14
+ to users of razor-server.
15
+ # automatically burn our version into the generated source
16
+ version_file: 'lib/razor/cli/version.rb'
17
+ update_version_file: true
18
+ # files and gem_files are space separated lists (or arrays)
19
+ files:
20
+ - 'Gemfile*'
21
+ - razor-client.gemspec
22
+ - bin
23
+ - lib
24
+ - '*.md'
25
+ - LICENSE
26
+ - locales
27
+ gem_files: '{bin,lib,locales}/**/* *.md LICENSE'
28
+ gem_require_path: 'lib'
29
+ gem_test_files: 'spec/**/*'
30
+ gem_executables: 'razor'
31
+ gem_default_executables: 'razor'
32
+ gem_required_ruby_version: '>= 1.9.3'
33
+ gem_runtime_dependencies:
34
+ mime-types: '< 2.0'
35
+ multi_json:
36
+ faraday: '>= 0.15'
37
+ command_line_reporter: '> 3.0'
38
+ gettext-setup:
data/lib/razor/cli.rb CHANGED
@@ -38,6 +38,12 @@ module Razor
38
38
  end
39
39
  end
40
40
 
41
+ class UnauthorizedError < Error
42
+ def initialize(url)
43
+ super _("Credentials are required to connect to the server at %{url}") % {url: url}
44
+ end
45
+ end
46
+
41
47
  end
42
48
  end
43
49
 
@@ -35,7 +35,7 @@ class Razor::CLI::Command
35
35
  # `--arg=value`/`--arg value`
36
36
  # `-a=value`/`-a value`
37
37
  arg_name, value = [$1, $3]
38
- value = @segments.shift if value.nil? && @segments[0] !~ /^-/
38
+ value = @segments.shift if value.nil? && @segments[0] !~ /^-[a-z]/
39
39
  arg_name = self.class.resolve_alias(arg_name, @cmd_schema)
40
40
  body[arg_name] = self.class.convert_arg(arg_name, value, body[arg_name], @cmd_schema)
41
41
  elsif argument =~ /\A-([a-z][a-z_-]+)(=(.+))?\Z/ and
@@ -132,10 +132,10 @@ class Razor::CLI::Command
132
132
  begin
133
133
  Integer(value)
134
134
  rescue ArgumentError
135
- raise ArgumentError, _("Invalid integer for argument '%{arg_name}': %{value}") % {argument_name: arg_name, value: value}
135
+ raise ArgumentError, _("Invalid integer for argument '%{argument_name}': %{value}") % {argument_name: arg_name, value: value}
136
136
  end
137
137
  when "null"
138
- raise ArgumentError, _("Expected nothing for argument '%{arg_name}', but was: '%{value}'") %
138
+ raise ArgumentError, _("Expected nothing for argument '%{argument_name}', but was: '%{value}'") %
139
139
  {argument_name: arg_name, value: value} unless value.nil?
140
140
  nil
141
141
  when "string", nil # `nil` for 'might be an alias, send as-is'
@@ -1,4 +1,4 @@
1
- require 'rest-client'
1
+ require 'faraday'
2
2
  require 'multi_json'
3
3
  require 'yaml'
4
4
  require 'forwardable'
@@ -14,8 +14,7 @@ module Razor::CLI
14
14
  @segments = segments||[]
15
15
  set_api_url!(parse)
16
16
  @doc = entrypoint
17
- @doc_resource = create_resource parse.api_url, {:accept => :json,
18
- :accept_language => accept_language}
17
+ @doc_resource = create_resource parse.api_url, default_headers
19
18
  end
20
19
 
21
20
  # This returns an array of two elements:
@@ -51,7 +50,7 @@ module Razor::CLI
51
50
  attr_accessor :doc_resource
52
51
 
53
52
  def last_url
54
- @doc_resource
53
+ @doc_resource.build_url
55
54
  end
56
55
 
57
56
  def entrypoint
@@ -100,7 +99,7 @@ module Razor::CLI
100
99
  command = json_get(cmd_url)
101
100
  Razor::CLI::Command.new(@parse, self, command, @segments, cmd_url).run
102
101
  else
103
- raise NavigationError.new(@doc_resource, @segments, @doc)
102
+ raise NavigationError.new(@doc_resource.build_url, @segments, @doc)
104
103
  end
105
104
  end
106
105
 
@@ -114,7 +113,7 @@ module Razor::CLI
114
113
  obj = @doc[key]
115
114
  end
116
115
 
117
- raise NavigationError.new(@doc_resource, key, @doc) if obj.nil?
116
+ raise NavigationError.new(@doc_resource.build_url, key, @doc) if obj.nil?
118
117
 
119
118
  if obj.is_a?(Hash) && obj["id"]
120
119
  url = URI.parse(obj["id"])
@@ -145,6 +144,11 @@ module Razor::CLI
145
144
  @accept_language ||= GettextSetup.candidate_locales
146
145
  end
147
146
 
147
+ def default_headers
148
+ {'accept' => 'application/json',
149
+ 'accept_language' => accept_language}
150
+ end
151
+
148
152
  def head(url, headers={})
149
153
  resource = create_resource(url, headers)
150
154
  response = resource.head
@@ -166,10 +170,12 @@ module Razor::CLI
166
170
  @username ||= url.user
167
171
  @password ||= url.password
168
172
 
169
- response = get(url,headers.merge(:accept => :json,
170
- :accept_language => accept_language))
173
+ response = get(url, headers.merge(default_headers))
174
+ if response.status == 401
175
+ raise UnauthorizedError.new(url)
176
+ end
171
177
  unless response.headers[:content_type] =~ /application\/json/
172
- raise _("Received content type %{content_type}") % {content_type: response.headers[:content_type]}
178
+ raise _('Received content type %{content_type}') % {content_type: response.headers[:content_type]}
173
179
  end
174
180
  MultiJson.load(response.body)
175
181
  end
@@ -178,11 +184,14 @@ module Razor::CLI
178
184
  @username ||= url.user
179
185
  @password ||= url.password
180
186
 
181
- headers = { :accept=>:json, "Content-Type" => :json,
182
- :accept_language => accept_language}
187
+ headers = {'Content-Type' => 'application/json'}.merge(default_headers)
183
188
  begin
184
189
  resource = create_resource(url, headers)
185
- response = resource.post MultiJson::dump(body)
190
+ # `nil` here because the URL above is absolute, not relative.
191
+ response = resource.post nil, MultiJson::dump(body)
192
+ if response.status == 401
193
+ raise UnauthorizedError.new(url)
194
+ end
186
195
  ensure
187
196
  if @parse.dump_response?
188
197
  print "POST #{url.to_s}\n#{body}\n-->\n"
@@ -200,7 +209,7 @@ module Razor::CLI
200
209
  begin
201
210
  url = RAZOR_HTTPS_API
202
211
  head(URI.parse(url))
203
- rescue Errno::ENOENT, Errno::ECONNREFUSED
212
+ rescue Errno::ENOENT, Faraday::ConnectionFailed
204
213
  false
205
214
  ensure
206
215
  print "HEAD #{url.to_s}\n\n" if @parse.dump_response?
@@ -209,13 +218,13 @@ module Razor::CLI
209
218
  end
210
219
 
211
220
  def create_resource(url, headers)
212
- @doc_resource = RestClient::Resource.new(url.to_s,
221
+ @doc_resource = Faraday.new(url,
213
222
  :headers => headers,
214
- :verify_ssl => @parse.verify_ssl?,
215
- :ssl_ca_file => @parse.ssl_ca_file,
216
- # Add these in case the URL above doesn't include authentication.
217
- :user => @username || url.user,
218
- :password => @password || url.password)
223
+ :ssl => {verify: @parse.verify_ssl?,
224
+ ca_file: @parse.ssl_ca_file}).tap do |req|
225
+ # Add these in case the URL above doesn't include authentication.
226
+ req.basic_auth(@username || url.user, @password || url.password)
227
+ end
219
228
  end
220
229
  end
221
230
  end