kreeger/python-rdio — pull request #10 by tupton (2013-04-10 20:46:26+00:00)
Title: Get search result dict keys safely.

If you only specify one type when searching, the results object may or may not have all the keys that `RdioSearchResult` expects, so we need to get the keys safely using `get()`.

This is what currently happens:

```
In [43]: s = r.search(query='All Hail The Void', types=['Albums',], extras=['trackKeys',])
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/Users/tupton/code/ in ()
----> 1 s = r.search(query='All Hail The Void', types=['Albums',], extras=['trackKeys',])

/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/rdio/rdio.pyc in search(self, query, types, never_or, extras, start, count)
1152 if count: data['count'] = count
1153 results = self.call_api(data)
-> 1154 return RdioSearchResult(results) if results else None
1155
1156 def search_suggestions(self, query, extras=[]):

/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/rdio/rdio.pyc in __init__(self, data)
361 super(RdioSearchResult, self).__init__(data)
362 self.album_count = data['album_count']
--> 363 self.artist_count = data['artist_count']
364 self.number_results = data['number_results']
365 self.person_count = data['person_count']

KeyError: 'artist_count'
```

And what is expected (what happens with the changes in this branch):

```
In [6]: s = r.search(query='All Hail The Void', types=['Albums',], extras=['trackKeys',])

In [7]: print "%s - %s" % (s.results[0].artist_name, s.results[0].name)
Enabler - All Hail The Void
```