Skip to content
Browse files

Add Response class.

  • Loading branch information...
1 parent 40ae088 commit c90a32db4f0fb49137d9a34e0b224a75c33af698 @tylerhunt committed
Showing with 23 additions and 0 deletions.
  1. +1 −0 lib/brewery_db.rb
  2. +13 −0 lib/brewery_db/response.rb
  3. +9 −0 spec/brewery_db/response_spec.rb
View
1 lib/brewery_db.rb
@@ -5,6 +5,7 @@ module BreweryDB
autoload :Client, 'brewery_db/client'
autoload :Config, 'brewery_db/config'
autoload :Resource, 'brewery_db/resource'
+ autoload :Response, 'brewery_db/response'
extend self
View
13 lib/brewery_db/response.rb
@@ -0,0 +1,13 @@
+require 'hashie'
+
+module BreweryDB
+ class Response < Hashie::Mash
+ def convert_key(key)
+ key = key.to_s.dup
+ key.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
+ key.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
+ key.tr('-', '_').downcase
+ end
+ protected :convert_key
+ end
+end
View
9 spec/brewery_db/response_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe BreweryDB::Response do
+ it { should be_a(Hashie::Mash) }
+
+ it 'underscores camelcased keys' do
+ described_class.new(:currentPage => 1).current_page.should == 1
+ end
+end

0 comments on commit c90a32d

Please sign in to comment.
Something went wrong with that request. Please try again.