diff --git a/lib/gattica.rb b/lib/gattica.rb index dc10cb1..068a559 100644 --- a/lib/gattica.rb +++ b/lib/gattica.rb @@ -12,7 +12,7 @@ # internal require 'gattica/version' -require 'gattica/core_extensions' +require 'gattica/hash_extensions' require 'gattica/convertible' require 'gattica/exceptions' require 'gattica/user' diff --git a/lib/gattica/auth.rb b/lib/gattica/auth.rb index 9230186..4ea5190 100644 --- a/lib/gattica/auth.rb +++ b/lib/gattica/auth.rb @@ -18,6 +18,7 @@ class Auth # Try to authenticate the user def initialize(http, user) options = OPTIONS.merge(user.to_h) + options.extend HashExtensions response, data = http.post(SCRIPT_NAME, options.to_query, HEADERS) if response.code != '200' diff --git a/lib/gattica/convertible.rb b/lib/gattica/convertible.rb index 9f37e6e..3a269d0 100644 --- a/lib/gattica/convertible.rb +++ b/lib/gattica/convertible.rb @@ -10,7 +10,7 @@ def to_h instance_variables.each do |var| output.merge!({ var[1..-1] => instance_variable_get(var) }) unless var == '@xml' # exclude the whole XML dump end - output + output.tap { |h| h.include HashExtensions } end # output nice inspect syntax diff --git a/lib/gattica/core_extensions.rb b/lib/gattica/core_extensions.rb deleted file mode 100644 index 50ca194..0000000 --- a/lib/gattica/core_extensions.rb +++ /dev/null @@ -1,25 +0,0 @@ -class Hash - - def to_query - require 'cgi' unless defined?(CGI) && defined?(CGI::escape) - self.collect do |key, value| - "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}" - end.sort * '&' - end - - def key - self.keys.first if self.length == 1 - end - - def value - self.values.first if self.length == 1 - end - - def stringify_keys - inject({}) do |options, (key, value)| - options[key.to_s] = value - options - end - end - -end diff --git a/lib/gattica/hash_extensions.rb b/lib/gattica/hash_extensions.rb new file mode 100644 index 0000000..46860dd --- /dev/null +++ b/lib/gattica/hash_extensions.rb @@ -0,0 +1,20 @@ +module Gattica + module HashExtensions + + def to_query + require 'cgi' unless defined?(CGI) && defined?(CGI::escape) + self.collect do |key, value| + "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}" + end.sort * '&' + end + + def key + self.keys.first if self.length == 1 + end + + def value + self.values.first if self.length == 1 + end + + end +end \ No newline at end of file