diff options
| author | mo <mo@mokhan.ca> | 2018-05-07 16:32:04 -0600 |
|---|---|---|
| committer | mo <mo@mokhan.ca> | 2018-05-07 16:32:04 -0600 |
| commit | 27be59407ed3be2c569538075f7df1bdaa176808 (patch) | |
| tree | 341b5f5e3efc1de5e2a09054953b5a1ccf0fecb1 /lib | |
| parent | f828908044c26422f646814a222a3bc9db357948 (diff) | |
fix rubocop errors.v0.1.5
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/net/hippie.rb | 1 | ||||
| -rw-r--r-- | lib/net/hippie/client.rb | 18 | ||||
| -rw-r--r-- | lib/net/hippie/json_mapper.rb | 1 | ||||
| -rw-r--r-- | lib/net/hippie/version.rb | 2 |
4 files changed, 17 insertions, 5 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 |
