AlexWheeler/twenty20_API — pull request #1 by tommyschaefer (2014-12-03 03:51:25+00:00)
Title: Clean up Item and Challenge Objects

Hi there!

Just thought I would submit a PR to clean up item/challenge objects. It seemed like a pretty big hassle to manually create `attr_reader`s for each of an API object's attributes, and then set their associated instance variables. What I did was extract this functionality into a `ApiObject` class that `Item` and `Challenge` can inherit from (along with future response objects). Basically, all you have to do now is define a class method `attributes` for each api object now, and it will generate the reader and set the instance variables for you in initialize.

For example, heres Challenge:

```
module Twenty20
class Challenge < ApiObject
def self.attributes
%w(slug
name
description
starts_at
ends_at
submission_count)
end
end
end
```

`ApiObject` then has an initialize method that is inherited. It defines the singleton reader methods and sets your instance variables for you! All the tests still pass and I added some `ApiObject` tests as well. Thanks!