Commit 27be594

mo <mo@mokhan.ca>
2018-05-07 22:32:04
fix rubocop errors. tag: v0.1.5
1 parent f828908
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
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)
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
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)
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)
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