mauth-client 6.2.1 → 6.4.1

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: 1871065424b09a341be04ecae785be82574cef1fafacb689d2ea538e8d25d03e
4
- data.tar.gz: 6ff7c37a989fcdd8ec8e4d46d9ce4e0ab61cd16a7fcd1784f1d85f24e67a2ad1
3
+ metadata.gz: b9219adefc5bedb36c4994be6309d39c8cb2b2e67a91d8a12f2119caf288df26
4
+ data.tar.gz: aff48af8ae57b3a4cd12f094abe3ac5c002379177465f1870e739e180e4f37cc
5
5
  SHA512:
6
- metadata.gz: a71f408dd52e310d544f65d0b0ea03df7a671db23bfc11a39a38795bd23f3f0ff78472982e4176461fd55ea98d3ed5de9a8d9ec9cfea19ffd334d167d9ba1836
7
- data.tar.gz: 8334a7c74a7829b52fae5bde7ac783e425c86285d6d17db8f79088ff3998736786813cc5a56de2ffe12fe594db32606e76d9831befb59e3ee507683e4bbd6c76
6
+ metadata.gz: 5c2dac6db5f67e885d634c428b0dbe0eaeee6a3a74a5dffa64f267e8dd7f3666e7d129ac4dda66fc02d41503c5245cdd546e17d6bd88d217a80ecacbfcae11c3
7
+ data.tar.gz: 1fdbb74b94544f25b3827638f0ffb853beb19e6e40bcbb1b4b31b547934c9266903fb9e7386e54a251dee2fecc629fb0c6b16cfcb1cdf44a678369ed67b0f32d
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ inherit_gem:
2
+ rubocop-mdsol: rubocop.yml
3
+
4
+ require:
5
+ - rubocop-performance
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - gemfiles/**/*
10
+
11
+ Gemspec/RequireMFA:
12
+ Enabled: false
13
+
14
+ Layout/ArgumentAlignment:
15
+ EnforcedStyle: with_fixed_indentation
16
+
17
+ Layout/FirstHashElementIndentation:
18
+ EnforcedStyle: consistent
19
+
20
+ Layout/LineLength:
21
+ Exclude:
22
+ - spec/client/local_authenticator_spec.rb
23
+
24
+ Lint/MissingSuper:
25
+ Exclude:
26
+ - exe/mauth-client
27
+ - lib/mauth/faraday.rb
28
+ - lib/mauth/rack.rb
29
+
30
+ Metrics/AbcSize:
31
+ Exclude:
32
+ - lib/mauth/client.rb
33
+ - lib/mauth/client/local_authenticator.rb
34
+ - lib/mauth/proxy.rb
35
+
36
+ Metrics/MethodLength:
37
+ Exclude:
38
+ - lib/mauth/client.rb
39
+
40
+ Naming/FileName:
41
+ Exclude:
42
+ - lib/mauth-client.rb
43
+
44
+ Style/FrozenStringLiteralComment:
45
+ Enabled: true
46
+
47
+ Style/GlobalVars:
48
+ Exclude:
49
+ - exe/mauth-client
50
+
51
+ Style/StringLiterals:
52
+ Enabled: true
53
+ EnforcedStyle: single_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.9
data/.travis.yml CHANGED
@@ -1,33 +1,46 @@
1
+ dist: focal
1
2
  language: ruby
2
3
  cache: bundler
3
4
 
4
5
  rvm:
5
- - 2.3
6
- - 2.4
7
- - 2.5
8
6
  - 2.6
9
7
  - 2.7
8
+ - 3.0
9
+ - 3.1
10
+
11
+ env:
12
+ global:
13
+ - BUNDLE_JOBS=4
14
+
15
+ jobs:
16
+ exclude:
17
+ - rvm: 3.0
18
+ gemfile: gemfiles/faraday_0.x.gemfile # Faraday v0.x does not officially support Ruby 3.0 (see: https://github.com/lostisland/faraday/releases/tag/v1.3.0)
19
+ - rvm: 3.1
20
+ gemfile: gemfiles/faraday_0.x.gemfile # Faraday v0.x does not officially support Ruby 3.0 (see: https://github.com/lostisland/faraday/releases/tag/v1.3.0)
10
21
 
11
22
  gemfile:
12
23
  - gemfiles/faraday_0.x.gemfile
13
24
  - gemfiles/faraday_1.x.gemfile
25
+ - gemfiles/faraday_2.x.gemfile
14
26
 
15
27
  before_install:
16
- - gem update --system --force -N > /dev/null && echo "Rubygems version $(gem --version)"
17
- - gem install bundler --force -N -v=2.1.4 && bundle --version
28
+ - gem update --system --force -N > /dev/null && echo "Rubygems version $(gem --version)" && bundle --version
18
29
 
19
30
  install:
20
- - bundle install --jobs=3 --retry=3
31
+ - bundle install
21
32
  - >-
22
33
  curl -H 'Cache-Control: no-cache'
23
- https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/master/travis_ci/fossa_install.sh |
34
+ https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/main/travis_ci/fossa_install.sh |
24
35
  bash -s -- -b $TRAVIS_BUILD_DIR
25
36
 
26
37
  script:
27
38
  - bundle exec rspec
39
+ - bundle exec rubocop
40
+ - bundle exec rake benchmark
28
41
  - >-
29
42
  curl -H 'Cache-Control: no-cache'
30
- https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/master/travis_ci/fossa_run.sh |
43
+ https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/main/travis_ci/fossa_run.sh |
31
44
  bash -s -- -b $TRAVIS_BUILD_DIR
32
45
 
33
46
  deploy:
@@ -38,4 +51,4 @@ deploy:
38
51
  on:
39
52
  tags: true
40
53
  repo: mdsol/mauth-client-ruby
41
- condition: $TRAVIS_RUBY_VERSION == 2.7 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
54
+ condition: $TRAVIS_RUBY_VERSION == 3.1 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
data/Appraisals CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  appraise 'faraday_0.x' do
2
4
  gem 'faraday', '0.9.0'
3
5
  end
@@ -5,3 +7,7 @@ end
5
7
  appraise 'faraday_1.x' do
6
8
  gem 'faraday', '~> 1.0'
7
9
  end
10
+
11
+ appraise 'faraday_2.x' do
12
+ gem 'faraday', '~> 2.0'
13
+ end
data/CHANGELOG.md CHANGED
@@ -1,14 +1,26 @@
1
+ ## v6.4.1
2
+ - Fix MAuth::Rack::Response to not raise FrozenError.
3
+
4
+ ## v6.4.0
5
+ - Support Ruby 3.1.
6
+ - Drop support for Ruby < 2.6.0.
7
+ - Allow Faraday 2.x.
8
+
9
+ ## v6.3.0
10
+ - Support Ruby 3.0.
11
+ - Drop support for Ruby < 2.5.0.
12
+
1
13
  ## v6.2.1
2
- * Fix SecurityTokenCacher to not cache tokens forever.
14
+ - Fix SecurityTokenCacher to not cache tokens forever.
3
15
 
4
16
  ## v6.2.0
5
- * Drop legacy security token expiry in favor of honoring server cache headers via Faraday HTTP Cache Middleware.
17
+ - Drop legacy security token expiry in favor of honoring server cache headers via Faraday HTTP Cache Middleware.
6
18
 
7
19
  ## v6.1.1
8
- * Replace `URI.escape` with `CGI.escape` in SecurityTokenCacher to suppress "URI.escape is obsolete" warning.
20
+ - Replace `URI.escape` with `CGI.escape` in SecurityTokenCacher to suppress "URI.escape is obsolete" warning.
9
21
 
10
22
  ## v6.1.0
11
- * Allow Faraday 1.x.
23
+ - Allow Faraday 1.x.
12
24
 
13
25
  ## v6.0.0
14
26
  - Added parsing code to test with mauth-protocol-test-suite.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in mauth-client.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'mauth/request_and_response'
@@ -16,7 +18,7 @@ class TestSignableRequest < MAuth::Request
16
18
  attr_accessor :headers
17
19
 
18
20
  def merge_headers(headers)
19
- self.class.new(@attributes_for_signing).tap{|r| r.headers = (@headers || {}).merge(headers) }
21
+ self.class.new(@attributes_for_signing).tap { |r| r.headers = (@headers || {}).merge(headers) }
20
22
  end
21
23
 
22
24
  def x_mws_time
@@ -37,7 +39,7 @@ class TestSignableRequest < MAuth::Request
37
39
  end
38
40
 
39
41
  desc 'Runs benchmarks for the library.'
40
- task :benchmark do
42
+ task :benchmark do # rubocop:disable Metrics/BlockLength
41
43
  mc = MAuth::Client.new(
42
44
  private_key: OpenSSL::PKey::RSA.generate(2048),
43
45
  app_uuid: SecureRandom.uuid,
data/examples/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gem 'faraday', '~> 1.0'
@@ -1,39 +1,61 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- mauth-client (6.1.0)
4
+ mauth-client (6.4.0)
5
5
  addressable (~> 2.0)
6
6
  coderay (~> 1.0)
7
7
  dice_bag (>= 0.9, < 2.0)
8
- faraday (>= 0.9, < 2.0)
9
- faraday_middleware (>= 0.9, < 2.0)
8
+ faraday (>= 0.9, < 3.0)
9
+ faraday-http-cache (>= 2.0, < 3.0)
10
10
  rack
11
11
  term-ansicolor (~> 1.0)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- addressable (2.7.0)
16
+ addressable (2.8.0)
17
17
  public_suffix (>= 2.0.2, < 5.0)
18
18
  coderay (1.1.3)
19
- dice_bag (1.4.1)
19
+ dice_bag (1.6.1)
20
20
  diff-lcs (~> 1.0)
21
21
  rake
22
22
  thor (< 2.0)
23
- diff-lcs (1.4.4)
24
- faraday (1.0.1)
23
+ diff-lcs (1.5.0)
24
+ faraday (1.9.3)
25
+ faraday-em_http (~> 1.0)
26
+ faraday-em_synchrony (~> 1.0)
27
+ faraday-excon (~> 1.1)
28
+ faraday-httpclient (~> 1.0)
29
+ faraday-multipart (~> 1.0)
30
+ faraday-net_http (~> 1.0)
31
+ faraday-net_http_persistent (~> 1.0)
32
+ faraday-patron (~> 1.0)
33
+ faraday-rack (~> 1.0)
34
+ faraday-retry (~> 1.0)
35
+ ruby2_keywords (>= 0.0.4)
36
+ faraday-em_http (1.0.0)
37
+ faraday-em_synchrony (1.0.0)
38
+ faraday-excon (1.1.0)
39
+ faraday-http-cache (2.2.0)
40
+ faraday (>= 0.8)
41
+ faraday-httpclient (1.0.1)
42
+ faraday-multipart (1.0.3)
25
43
  multipart-post (>= 1.2, < 3)
26
- faraday_middleware (1.0.0)
27
- faraday (~> 1.0)
44
+ faraday-net_http (1.0.1)
45
+ faraday-net_http_persistent (1.2.0)
46
+ faraday-patron (1.0.0)
47
+ faraday-rack (1.0.0)
48
+ faraday-retry (1.0.3)
28
49
  multipart-post (2.1.1)
29
50
  public_suffix (4.0.6)
30
51
  rack (2.2.3)
31
- rake (13.0.1)
52
+ rake (13.0.6)
53
+ ruby2_keywords (0.0.5)
32
54
  sync (0.5.0)
33
55
  term-ansicolor (1.7.1)
34
56
  tins (~> 1.0)
35
- thor (1.0.1)
36
- tins (1.25.0)
57
+ thor (1.2.1)
58
+ tins (1.31.0)
37
59
  sync
38
60
 
39
61
  PLATFORMS
@@ -44,4 +66,4 @@ DEPENDENCIES
44
66
  mauth-client!
45
67
 
46
68
  BUNDLED WITH
47
- 2.1.4
69
+ 2.2.29
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  abort "USAGE: ./#{__FILE__} <USER UUID>" unless ARGV.size == 1
4
5
 
@@ -6,7 +7,7 @@ require 'bundler/setup'
6
7
  Bundler.require(:default)
7
8
 
8
9
  def config
9
- @conf ||= YAML.load(File.open("./config.yml"))
10
+ @config ||= YAML.safe_load(File.open('./config.yml'))
10
11
  end
11
12
 
12
13
  # get user information
@@ -18,8 +19,8 @@ end
18
19
  def get_data_from_imedidata(resource_name)
19
20
  puts "fetching #{resource_name}..."
20
21
  begin
21
- connection = Faraday::Connection.new(url: config["imedidata"]["host"]) do |builder|
22
- builder.use MAuth::Faraday::RequestSigner, config["mauth"]
22
+ connection = Faraday::Connection.new(url: config['imedidata']['host']) do |builder|
23
+ builder.use MAuth::Faraday::RequestSigner, config['mauth']
23
24
  builder.adapter Faraday.default_adapter
24
25
  end
25
26
 
@@ -44,15 +45,14 @@ end
44
45
 
45
46
  get_user_info_mauth(ARGV[0])
46
47
 
47
-
48
48
  ### OTHER EXAMPLES
49
49
 
50
50
  #### get study groups for an user
51
51
  def get_study_groups_mauth(user_uuid)
52
- get_data_from_imedidata "users/#{user_uuid}/study_groups.json"
52
+ get_data_from_imedidata "users/#{user_uuid}/study_groups.json"
53
53
  end
54
54
 
55
55
  #### get roles for a user in an application study
56
56
  def get_user_study_roles_mauth(user_uuid, study_uuid)
57
- get_data_from_imedidata "users/#{user_uuid}/studies/#{study_uuid}/apps/#{config["mauth"]["app_uuid"]}/roles.json"
57
+ get_data_from_imedidata "users/#{user_uuid}/studies/#{study_uuid}/apps/#{config["mauth"]["app_uuid"]}/roles.json"
58
58
  end
data/exe/mauth-client CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
4
5
 
5
- require 'rubygems'
6
6
  require 'faraday'
7
- require 'faraday_middleware'
8
7
  require 'logger'
9
8
  require 'mauth/client'
10
9
  require 'mauth/faraday'
@@ -17,41 +16,42 @@ require 'optparse'
17
16
 
18
17
  # $options default values
19
18
  $options = {
20
- :authenticate_response => true,
21
- :verbose => true,
22
- :color => nil,
23
- :no_ssl_verify => false,
19
+ authenticate_response: true,
20
+ verbose: true,
21
+ color: nil,
22
+ no_ssl_verify: false
24
23
  }
25
24
 
26
25
  additional_headers = []
27
26
  opt_parser = OptionParser.new do |opts|
28
- opts.banner = "Usage: mauth-client [options] <verb> <url> [body]"
27
+ opts.banner = 'Usage: mauth-client [options] <verb> <url> [body]'
29
28
 
30
- opts.on("-v", "--[no-]verbose", "Run verbosely - output is like curl -v (this is the default)") do |v|
29
+ opts.on('-v', '--[no-]verbose', 'Run verbosely - output is like curl -v (this is the default)') do |v|
31
30
  $options[:verbose] = v
32
31
  end
33
- opts.on("-q", "Run quietly - only outputs the response body (same as --no-verbose)") do |v|
32
+ opts.on('-q', 'Run quietly - only outputs the response body (same as --no-verbose)') do |v|
34
33
  $options[:verbose] = !v
35
34
  end
36
- opts.on("--[no-]authenticate", "Authenticate the response received") do |v|
35
+ opts.on('--[no-]authenticate', 'Authenticate the response received') do |v|
37
36
  $options[:authenticate_response] = v
38
37
  end
39
- opts.on("--[no-]color", "Color the output (defaults to color if the output device is a TTY)") do |v|
38
+ opts.on('--[no-]color', 'Color the output (defaults to color if the output device is a TTY)') do |v|
40
39
  $options[:color] = v
41
40
  end
42
- opts.on("-t", "--content-type CONTENT-TYPE", "Sets the Content-Type header of the request") do |v|
41
+ opts.on('-t', '--content-type CONTENT-TYPE', 'Sets the Content-Type header of the request') do |v|
43
42
  $options[:content_type] = v
44
43
  end
45
- opts.on("-H", "--header LINE", "accepts a json string of additional headers to included. IE 'cache-expirey: 10, other: value") do |v|
44
+ opts.on('-H', '--header LINE',
45
+ "accepts a json string of additional headers to included. IE 'cache-expirey: 10, other: value") do |v|
46
46
  additional_headers << v
47
47
  end
48
- opts.on("--no-ssl-verify", "Disables SSL verification - use cautiously!") do
48
+ opts.on('--no-ssl-verify', 'Disables SSL verification - use cautiously!') do
49
49
  $options[:no_ssl_verify] = true
50
50
  end
51
- $options[:additional_headers] =additional_headers
51
+ $options[:additional_headers] = additional_headers
52
52
  end
53
53
  opt_parser.parse!
54
- abort(opt_parser.help) unless (2..3).include?(ARGV.size)
54
+ abort(opt_parser.help) unless (2..3).cover?(ARGV.size)
55
55
 
56
56
  # FIND MAUTH CONFIG
57
57
 
@@ -61,32 +61,32 @@ possible_mauth_config_files = [
61
61
  ENV['MAUTH_CONFIG_YAML'],
62
62
  '~/.mauth_config.yml',
63
63
  './config/mauth.yml',
64
- './mauth.yml',
64
+ './mauth.yml'
65
65
  ].compact
66
66
 
67
67
  mauth_config_yml = possible_mauth_config_files.detect do |filename|
68
- File.exists?(File.expand_path(filename))
68
+ File.exist?(File.expand_path(filename))
69
69
  end
70
70
  unless mauth_config_yml
71
- message = "could not find mauth config. giving up. please place a mauth config in one of the standard places, " +
72
- "or point the MAUTH_CONFIG_YML environment variable at an existing one. standard places are:" +
73
- possible_mauth_config_files.map{|f| "\n\t#{f}" }.join
71
+ message = 'could not find mauth config. giving up. please place a mauth config in one of the standard places, ' \
72
+ 'or point the MAUTH_CONFIG_YML environment variable at an existing one. standard places are:' +
73
+ possible_mauth_config_files.map { |f| "\n\t#{f}" }.join
74
74
  abort message
75
75
  end
76
76
 
77
- mauth_config = MAuth::Client.default_config(:mauth_config_yml => File.expand_path(mauth_config_yml))
77
+ mauth_config = MAuth::Client.default_config(mauth_config_yml: File.expand_path(mauth_config_yml))
78
78
 
79
79
  # INSTANTIATE MAUTH CLIENT
80
80
 
81
- logger = Logger.new(STDERR)
81
+ logger = Logger.new($stderr)
82
82
  mauth_client = MAuth::Client.new(mauth_config.merge('logger' => logger))
83
83
 
84
84
  # OUTPUTTERS FOR FARADAY THAT SHOULD MOVE TO A LIB SOMEWHERE
85
85
 
86
86
  # outputs the response body to the given output device (defaulting to STDOUT)
87
87
  class FaradayOutputter < Faraday::Middleware
88
- def initialize(app, outdev=STDOUT)
89
- @app=app
88
+ def initialize(app, outdev = $stdout)
89
+ @app = app
90
90
  @outdev = outdev
91
91
  end
92
92
 
@@ -100,7 +100,6 @@ end
100
100
  # this is to approximate `curl -v`s output. but it's all faked, whereas curl gives you
101
101
  # the real text written and read for request and response. whatever, close enough.
102
102
  class FaradayCurlVOutputter < FaradayOutputter
103
-
104
103
  # defines a method with the given name, applying coloring defined by any additional arguments.
105
104
  # if $options[:color] is set, respects that; otherwise, applies color if the output device is a tty.
106
105
  def self.color(name, *color_args)
@@ -129,10 +128,11 @@ class FaradayCurlVOutputter < FaradayOutputter
129
128
  color :response_header
130
129
  color :response_blankline, :intense_green, :bold
131
130
 
132
- def call(request_env)
131
+ def call(request_env) # rubocop:disable Metrics/AbcSize
133
132
  @outdev.puts "#{info('*')} #{info_body("connect to #{request_env[:url].host} on port #{request_env[:url].port}")}"
134
- @outdev.puts "#{info('*')} #{info_body("getting our SSL on")}" if request_env[:url].scheme=='https'
135
- @outdev.puts "#{request('>')} #{request_verb(request_env[:method].to_s.upcase)} #{request_env[:url].path} #{protocol('HTTP/1.1' || 'or something - TODO')}"
133
+ @outdev.puts "#{info('*')} #{info_body("getting our SSL on")}" if request_env[:url].scheme == 'https'
134
+ @outdev.puts "#{request('>')} #{request_verb(request_env[:method].to_s.upcase)} #{request_env[:url].path}" \
135
+ "#{protocol('HTTP/1.1' || 'or something - TODO')}"
136
136
  request_env[:request_headers].each do |k, v|
137
137
  @outdev.puts "#{request('>')} #{request_header(k)}#{request(':')} #{v}"
138
138
  end
@@ -142,11 +142,12 @@ class FaradayCurlVOutputter < FaradayOutputter
142
142
  @outdev.puts "#{request('>')} #{line}"
143
143
  end
144
144
  @app.call(request_env).on_complete do |response_env|
145
- @outdev.puts "#{response('<')} #{protocol('HTTP/1.1' || 'or something - TODO')} #{response_status(response_env[:status].to_s)}"
145
+ @outdev.puts "#{response('<')} #{protocol('HTTP/1.1' || 'or something - TODO')} " \
146
+ "#{response_status(response_env[:status].to_s)}"
146
147
  request_env[:response_headers].each do |k, v|
147
148
  @outdev.puts "#{response('<')} #{response_header(k)}#{response(':')} #{v}"
148
149
  end
149
- @outdev.puts "#{response_blankline ('<')} "
150
+ @outdev.puts "#{response_blankline('<')} "
150
151
  response_body = color_body_by_content_type(response_env[:body], response_env[:response_headers]['Content-Type'])
151
152
  (response_body || '').split("\n", -1).each do |line|
152
153
  @outdev.puts "#{response('<')} #{line}"
@@ -161,62 +162,61 @@ class FaradayCurlVOutputter < FaradayOutputter
161
162
 
162
163
  # a mapping for each registered CodeRay scanner to the Media Types which represent
163
164
  # that language. extremely incomplete!
164
- CodeRayForMediaTypes = {
165
- :c => [],
166
- :cpp => [],
167
- :clojure => [],
168
- :css => ['text/css', 'application/css-stylesheet'],
169
- :delphi => [],
170
- :diff => [],
171
- :erb => [],
172
- :groovy => [],
173
- :haml => [],
174
- :html => ['text/html'],
175
- :java => [],
176
- :java_script => ['application/javascript', 'text/javascript', 'application/x-javascript'],
177
- :json => ['application/json', %r(\Aapplication/.*\+json\z)],
178
- :php => [],
179
- :python => ['text/x-python'],
180
- :ruby => [],
181
- :sql => [],
182
- :xml => ['text/xml', 'application/xml', %r(\Aapplication/.*\+xml\z)],
183
- :yaml => [],
184
- }
165
+ CODE_RAY_FOR_MEDIA_TYPES = {
166
+ c: [],
167
+ cpp: [],
168
+ clojure: [],
169
+ css: ['text/css', 'application/css-stylesheet'],
170
+ delphi: [],
171
+ diff: [],
172
+ erb: [],
173
+ groovy: [],
174
+ haml: [],
175
+ html: ['text/html'],
176
+ java: [],
177
+ java_script: ['application/javascript', 'text/javascript', 'application/x-javascript'],
178
+ json: ['application/json', %r{\Aapplication/.*\+json\z}],
179
+ php: [],
180
+ python: ['text/x-python'],
181
+ ruby: [],
182
+ sql: [],
183
+ xml: ['text/xml', 'application/xml', %r{\Aapplication/.*\+xml\z}],
184
+ yaml: []
185
+ }.freeze
185
186
 
186
187
  # takes a body and a content type; returns the body, with coloring (ansi colors for terminals)
187
188
  # possibly added, if it's a recognized content type and #color? is true
188
189
  def color_body_by_content_type(body, content_type)
189
- if body && color?
190
- # kinda hacky way to get the media_type. faraday should supply this ...
191
- require 'rack'
192
- media_type = ::Rack::Request.new({'CONTENT_TYPE' => content_type}).media_type
193
- coderay_scanner = CodeRayForMediaTypes.reject{|k,v| !v.any?{|type| type === media_type} }.keys.first
194
- if coderay_scanner
195
- require 'coderay'
196
- if coderay_scanner == :json
197
- body = begin
198
- JSON.pretty_generate(JSON.parse(body))
199
- rescue JSON::ParserError
200
- body
201
- end
202
- end
203
- body = CodeRay.scan(body, coderay_scanner).encode(:terminal)
190
+ return body unless body && color?
191
+
192
+ # kinda hacky way to get the media_type. faraday should supply this ...
193
+ require 'rack'
194
+ media_type = ::Rack::Request.new({ 'CONTENT_TYPE' => content_type }).media_type
195
+ coderay_scanner = CODE_RAY_FOR_MEDIA_TYPES.select { |_k, v| v.any?(media_type) }.keys.first
196
+ return body unless coderay_scanner
197
+
198
+ require 'coderay'
199
+ if coderay_scanner == :json
200
+ body = begin
201
+ JSON.pretty_generate(JSON.parse(body))
202
+ rescue JSON::ParserError
203
+ body
204
204
  end
205
205
  end
206
- body
206
+ CodeRay.scan(body, coderay_scanner).encode(:terminal)
207
207
  end
208
208
  end
209
209
 
210
210
  # CONFIGURE THE FARADAY CONNECTION
211
211
  faraday_options = {}
212
212
  if $options[:no_ssl_verify]
213
- faraday_options[:ssl] = {:verify => false}
213
+ faraday_options[:ssl] = { verify: false }
214
214
  end
215
215
  connection = Faraday.new(faraday_options) do |builder|
216
- builder.use MAuth::Faraday::MAuthClientUserAgent, "MAuth-Client CLI"
217
- builder.use MAuth::Faraday::RequestSigner, :mauth_client => mauth_client
216
+ builder.use MAuth::Faraday::MAuthClientUserAgent, 'MAuth-Client CLI'
217
+ builder.use MAuth::Faraday::RequestSigner, mauth_client: mauth_client
218
218
  if $options[:authenticate_response]
219
- builder.use MAuth::Faraday::ResponseAuthenticator, :mauth_client => mauth_client
219
+ builder.use MAuth::Faraday::ResponseAuthenticator, mauth_client: mauth_client
220
220
  end
221
221
  builder.use $options[:verbose] ? FaradayCurlVOutputter : FaradayOutputter
222
222
  builder.adapter Faraday.default_adapter
@@ -224,41 +224,38 @@ end
224
224
 
225
225
  httpmethod, url, body = *ARGV
226
226
 
227
- unless Faraday::Connection::METHODS.map{|m| m.to_s.downcase }.include?(httpmethod.downcase)
227
+ unless Faraday::Connection::METHODS.map { |m| m.to_s.downcase }.include?(httpmethod.downcase)
228
228
  abort "Unrecognized HTTP method given: #{httpmethod}\n\n" + opt_parser.help
229
229
  end
230
230
 
231
231
  headers = {}
232
232
  if $options[:content_type]
233
233
  headers['Content-Type'] = $options[:content_type]
234
- else
235
- if body
236
- # I'd rather not have a default content-type, but if none is set then the HTTP adapter sets this to
237
- # application/x-www-form-urlencoded anyway. application/json is a better default for our purposes.
238
- headers['Content-Type'] = 'application/json'
239
- end
234
+ elsif body
235
+ headers['Content-Type'] = 'application/json'
236
+ # I'd rather not have a default content-type, but if none is set then the HTTP adapter sets this to
237
+ # application/x-www-form-urlencoded anyway. application/json is a better default for our purposes.
240
238
  end
241
239
 
242
- if $options[:additional_headers]
243
- $options[:additional_headers].each do |cur|
244
- raise "Headers must be in the format of [key]:[value]" unless cur.include?(':')
245
- key, throw_away ,value = cur.partition(':')
246
- headers[key] = value
247
- end
240
+ $options[:additional_headers]&.each do |cur|
241
+ raise 'Headers must be in the format of [key]:[value]' unless cur.include?(':')
242
+
243
+ key, _throw_away, value = cur.partition(':')
244
+ headers[key] = value
248
245
  end
249
246
 
250
247
  # OH LOOK IT'S FINALLY ACTUALLY CONNECTING TO SOMETHING
251
248
 
252
249
  begin
253
- response = connection.run_request(httpmethod.downcase.to_sym, url, body, headers)
250
+ connection.run_request(httpmethod.downcase.to_sym, url, body, headers)
254
251
  rescue MAuth::InauthenticError, MAuth::UnableToAuthenticateError, MAuth::MAuthNotPresent, MAuth::MissingV2Error => e
255
- if $options[:color].nil? ? STDERR.tty? : $options[:color]
252
+ if $options[:color].nil? ? $stderr.tty? : $options[:color]
256
253
  class_color = Term::ANSIColor.method(e.is_a?(MAuth::UnableToAuthenticateError) ? :intense_yellow : :intense_red)
257
254
  message_color = Term::ANSIColor.method(e.is_a?(MAuth::UnableToAuthenticateError) ? :yellow : :red)
258
255
  else
259
- class_color = proc{|s| s }
260
- message_color = proc{|s| s }
256
+ class_color = proc { |s| s }
257
+ message_color = proc { |s| s }
261
258
  end
262
- STDERR.puts(class_color.call(e.class.to_s))
263
- STDERR.puts(message_color.call(e.message))
259
+ warn(class_color.call(e.class.to_s))
260
+ warn(message_color.call(e.message))
264
261
  end