badgeville/badgeville-ruby — pull request #4 by jspradlin (2012-06-21 20:01:06+00:00)
Title: Avoid throwing an error when calling the 'all' method on a Badgeville Resource

I was receiving the following error whenever I tried to load Rewards for a user who had not yet earned any:

```1.9.2-p290 :008 > BadgevilleBerlin::Reward.all(params: { player_id: '' })
NoMethodError: undefined method `collect!' for {"data"=>[], "paging"=>{"current_page"=>1, "per_page"=>10}}:Hash
from /Users/jspradlin/.rvm/gems/ruby-1.9.2-p290@global/gems/activeresource-3.1.3/lib/active_resource/base.rb:930:in `instantiate_collection'
from /Users/jspradlin/.rvm/gems/ruby-1.9.2-p290@global/gems/activeresource-3.1.3/lib/active_resource/base.rb:902:in `find_every'
from /Users/jspradlin/.rvm/gems/ruby-1.9.2-p290@global/gems/activeresource-3.1.3/lib/active_resource/base.rb:814:in `find'
from /Users/jspradlin/.rvm/gems/ruby-1.9.2-p290@global/gems/activeresource-3.1.3/lib/active_resource/base.rb:840:in `all'
from (irb):8
from /Users/jspradlin/.rvm/gems/ruby-1.9.2-p290@global/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/jspradlin/.rvm/gems/ruby-1.9.2-p290@global/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/jspradlin/.rvm/gems/ruby-1.9.2-p290@global/gems/railties-3.1.3/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'```

I noticed that the ```decode``` method in the ```BadgevilleBerlinJsonFormat``` module was simply returning the full JSON Hash whenever its ```data``` element was empty. This is problematic because ActiveResource expects the value returned from calling the ```all``` method to be an Array. However, the JSON returned was a Hash and was causing the error shown above.

Instead, the ```decode``` method should just return the contents of the ```data``` element regardless of whether or not that element's contents are empty.