From 27be59407ed3be2c569538075f7df1bdaa176808 Mon Sep 17 00:00:00 2001 From: mo Date: Mon, 7 May 2018 16:32:04 -0600 Subject: fix rubocop errors. --- lib/net/hippie.rb | 1 + lib/net/hippie/client.rb | 18 ++++++++++++++---- lib/net/hippie/json_mapper.rb | 1 + lib/net/hippie/version.rb | 2 +- test/net/client_test.rb | 2 +- test/net/hippie_test.rb | 2 +- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/net/hippie.rb b/lib/net/hippie.rb index 30fbd0a..147441c 100644 --- a/lib/net/hippie.rb +++ b/lib/net/hippie.rb @@ -8,6 +8,7 @@ require 'net/hippie/json_mapper' require 'net/hippie/client' module Net + # net/http for hippies. module Hippie def self.logger @logger ||= Logger.new(STDOUT) diff --git a/lib/net/hippie/client.rb b/lib/net/hippie/client.rb index 4e7a059..5022dab 100644 --- a/lib/net/hippie/client.rb +++ b/lib/net/hippie/client.rb @@ -1,5 +1,6 @@ module Net module Hippie + # A simple client for connecting with http resources. class Client DEFAULT_HEADERS = { 'Accept' => 'application/json', @@ -36,7 +37,8 @@ module Net end def post(uri, headers: {}, body: {}) - request = request_for(Net::HTTP::Post, uri, headers: headers, body: body) + type = Net::HTTP::Post + request = request_for(type, uri, headers: headers, body: body) response = execute(uri, request) if block_given? yield request, response @@ -67,9 +69,9 @@ module Net http.read_timeout = 30 http.use_ssl = uri.is_a?(URI::HTTPS) http.set_debug_output(Net::Hippie.logger) - http.cert = OpenSSL::X509::Certificate.new(certificate) if certificate - if key - http.key = passphrase ? OpenSSL::PKey::RSA.new(key, passphrase) : OpenSSL::PKey::RSA.new(key) + if certificate && key + http.cert = OpenSSL::X509::Certificate.new(certificate) if certificate + http.key = private_key end http end @@ -83,6 +85,14 @@ module Net def normalize_uri(uri) uri.is_a?(URI) ? uri : URI.parse(uri) end + + def private_key + if passphrase + OpenSSL::PKey::RSA.new(key, passphrase) + else + OpenSSL::PKey::RSA.new(key) + end + end end end end diff --git a/lib/net/hippie/json_mapper.rb b/lib/net/hippie/json_mapper.rb index 3aae9e3..e04a545 100644 --- a/lib/net/hippie/json_mapper.rb +++ b/lib/net/hippie/json_mapper.rb @@ -1,5 +1,6 @@ module Net module Hippie + # Converts a ruby hash into a JSON string class JsonMapper def map_from(hash) JSON.generate(hash) diff --git a/lib/net/hippie/version.rb b/lib/net/hippie/version.rb index 9119560..996b8ab 100644 --- a/lib/net/hippie/version.rb +++ b/lib/net/hippie/version.rb @@ -1,5 +1,5 @@ module Net module Hippie - VERSION = '0.1.4'.freeze + VERSION = '0.1.5'.freeze end end diff --git a/test/net/client_test.rb b/test/net/client_test.rb index ce2a295..8b9ee57 100644 --- a/test/net/client_test.rb +++ b/test/net/client_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class Net::Hippie::ClientTest < Minitest::Test +class ClientTest < Minitest::Test attr_reader :subject def initialize(*args) diff --git a/test/net/hippie_test.rb b/test/net/hippie_test.rb index 3d276fc..3addb2f 100644 --- a/test/net/hippie_test.rb +++ b/test/net/hippie_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class Net::HippieTest < Minitest::Test +class HippieTest < Minitest::Test def test_that_it_has_a_version_number refute_nil ::Net::Hippie::VERSION end -- cgit v1.2.3