This API wrapper tries to generalize the API calls. First we must find out the generalization in API URL structure.
Klout’s API URL structure is RESTful with a little cutomization. Almost all API URLs can be generalized in a way.
<protocol>://<domain>/<version>/<resource>.<format>/<input_name>/<input_value>/<action>?<query_string>
Note
<input_name> MUST be skipped when query a resource with Primary Key e.g. when call user resource with kloutId, the <input_name> should be skipped.
Note
<input_value> MUST be skipped when <input_name> is twitter The value should be passed in <query_string> instead.
Note
<action> MUST be skipped when expected result is Primary Key e.g. when call identity resource and expected result is kloutId
After generalizing the API URLs, next step is to make a generalized pythonic function calls:
Here is what I pruopose:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.<resource>.<action>(<input_name>=<input_value>)
Here are all possible combinations of the URLs. Lets try to map them to our generalized structure defined above:
http://api.klout.com/v2/identity.json/gp/112975106809988327760?key=xxxxxxxxxxxxxxxxxxxxxxxx
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.identity.klout(gp='112975106809988327760')
# Note that we replaced the empty action with klout as we want to be consistent
http://api.klout.com/v2/identity.json/tw/11158872?key=xxxxxxxxxxxxxxxxxxxxxxxx
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.identity.klout(tw='11158872')
# Note that we replaced the empty action with klout as we want to be consistent
http://api.klout.com/v2/identity.json/twitter?key=xxxxxxxxxxxxxxxxxxxxxxxx&screenName=erfaan
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.identity.klout(screenName='erfaan')
# Note that we replaced the empty action with klout as we want to be consistent
# Also the input parameters query string are used as function parameters. (again consistency)
http://api.klout.com/v2/identity.json/klout/11747/gp?key=xxxxxxxxxxxxxxxxxxxxxxxx
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.identity.gp(klout='11747')
http://api.klout.com/v2/identity.json/klout/11747/tw?key=xxxxxxxxxxxxxxxxxxxxxxxx
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.identity.tw(klout='11747')
https://api.klout.com/v2/user.json/11747/score?key=xxxxxxxxxxxxxxxxxxxxxxxx
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.user.scrore(kloutId='11747')
https://api.klout.com/v2/user.json/11747/influence?key=xxxxxxxxxxxxxxxxxxxxxxxx
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.user.influence(kloutId='11747')
https://api.klout.com/v2/user.json/11747/topics?key=xxxxxxxxxxxxxxxxxxxxxxxx
Code Example:
k = Kluot(key='xxxxxxxxxxxxxxxxxxxxxxxx')
k.user.topics(kloutId='11747')