keolo/mixpanel_client — pull request #16 by nateberkopec (2012-06-08 15:07:16+00:00)
Title: Add an optional hash attribute to each Client instance

In our Rails app, each User instance has it's own instance of MixpanelClient, because we use the Data Export API to give our Users data specific to them.

So, our request looked something like this:

```ruby
result = client.request do
...
on 'properties["user"]'
end
```

So, that would pull down the data for EVERY user. Obviously, this is pretty inefficient if you've got a ton of users, and we wanted to pull down just one user's mixpanel events.

So, my solution was to add an optional hash to the MixpanelClient when it's instantiated, which can then be accessed inside of its request blocks:

```ruby
result = client.request do
...
on 'properties["user"]'
where %{"#{self.options[:username]}" == properties["user"]}
end
```

I'm pretty new to Ruby and contributing to open source, so if there's a better way of doing this, please let me know! The syntax (especially self.options[:username] seems kind of ugly anyway.