diff --git a/gitlab.gemspec b/gitlab.gemspec index 26fc89fd1..46433bd76 100644 --- a/gitlab.gemspec +++ b/gitlab.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.add_runtime_dependency 'httparty' + gem.add_runtime_dependency 'hashie' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' diff --git a/lib/gitlab.rb b/lib/gitlab.rb index afff42d95..1f5a6e77a 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -1,5 +1,4 @@ require File.expand_path('../gitlab/version', __FILE__) -require File.expand_path('../gitlab/objectified_hash', __FILE__) require File.expand_path('../gitlab/configuration', __FILE__) require File.expand_path('../gitlab/error', __FILE__) require File.expand_path('../gitlab/request', __FILE__) diff --git a/lib/gitlab/objectified_hash.rb b/lib/gitlab/objectified_hash.rb deleted file mode 100644 index 370665e83..000000000 --- a/lib/gitlab/objectified_hash.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Gitlab - # Converts hashes to the objects. - class ObjectifiedHash - # Creates a new ObjectifiedHash. - def initialize(hash) - @data = hash.inject({}) do |data, (key,value)| - value = ObjectifiedHash.new(value) if value.is_a? Hash - data[key.to_s] = value - data - end - end - - # Delegate to ObjectifiedHash - def method_missing(key) - @data.key?(key.to_s) ? @data[key.to_s] : nil - end - end -end diff --git a/lib/gitlab/request.rb b/lib/gitlab/request.rb index e7cc62de6..44f95f563 100644 --- a/lib/gitlab/request.rb +++ b/lib/gitlab/request.rb @@ -1,4 +1,5 @@ require 'httparty' +require 'hashie/mash' module Gitlab # @private @@ -6,16 +7,16 @@ class Request include HTTParty format :json headers 'Accept' => 'application/json' - parser Proc.new {|body| parse(body)} + parser Proc.new {|body, _| parse(body)} # Converts the response body to an ObjectifiedHash. def self.parse(body) body = decode(body) if body.is_a? Hash - ObjectifiedHash.new body + Hashie::Mash.new body elsif body.is_a? Array - body.collect! {|e| ObjectifiedHash.new(e)} + body.collect! {|e| Hashie::Mash.new(e)} else raise Error::Parsing.new "Couldn't parse a response body" end