==================== Design Philosophy ==================== This API wrapper tries to generalize the API calls. First we must find out the generalization in API URL structure. -------------------------- Klout API URL Structure -------------------------- Klout's API URL structure is RESTful with a little cutomization. Almost all API URLs can be generalized in a way. :////.///? * : http or https * : api.klout.com * : v2 for the new API * : Currently there are only 2 resources *identity* and *user* * : Klout no longer supports *XML*. Only *json* is supported. * : (Optional) Name of the field to query. Required only when the input field is not *Primary Key*. Possible values for *identity* resource are: * tw - Twitter * klout - (Written as ks in official Klout API documentation but it doesn't work) * gp - Google+ * twitter (when using twitter screenName as input) * : Valule of the specified. Can be twitter id, google plus id or klout id. * : Name of the action to be performed. * : Must contain a key obtained from . MUST also contain *screenName* when is twitter .. NOTE:: MUST be skipped when query a resource with *Primary Key* e.g. when call user resource with *kloutId*, the ** should be skipped. .. NOTE:: MUST be skipped when is *twitter* The value should be passed in instead. .. NOTE:: MUST be skipped when expected result is *Primary Key* e.g. when call identity resource and expected result is *kloutId* ----------------------------- Designing python functions ----------------------------- After generalizing the API URLs, next step is to make a generalized pythonic function calls: Here is what I propose:: k = Klout(key='xxxxxxxxxxxxxxxxxxxxxxxx') k..(=) -------------------------------------------------- Klout API URL to Python Function mapping examples -------------------------------------------------- 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 * protocol: http * domain: api.klout.com * version: v2 * resource: identity * format: json * input_name: gp - Google+ * input_value: 112975106809988327760 - Google+ Id * action: Empty - We need kloutId as output * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx Code Example:: k = Klout(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 * protocol: http * domain: api.klout.com * version: v2 * resource: identity * format: json * input_name: tw - Twitter * input_value: 11158872 - Twitter Id * action: Empty - We need kloutId as output * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx Code Example:: k = Klout(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 * protocol: http * domain: api.klout.com * version: v2 * resource: identity * format: json * input_name: twitter * input_value: Empty - We want to query using twitter screenName * action: Empty - We need kloutId as output * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx&screenName=erfaan - screenName is only required in this case Code Example:: k = Klout(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 * protocol: http * domain: api.klout.com * version: v2 * resource: identity * format: json * input_name: klout * input_value: 11747 * action: gp - Google+ * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx Code Example:: k = Klout(key='xxxxxxxxxxxxxxxxxxxxxxxx') k.identity.gp(klout='11747') * http://api.klout.com/v2/identity.json/klout/11747/tw?key=xxxxxxxxxxxxxxxxxxxxxxxx * protocol: http * domain: api.klout.com * version: v2 * resource: identity * format: json * input_name: klout * input_value: 11747 * action: tw - Twitter * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx Code Example:: k = Klout(key='xxxxxxxxxxxxxxxxxxxxxxxx') k.identity.tw(klout='11747') * https://api.klout.com/v2/user.json/11747/score?key=xxxxxxxxxxxxxxxxxxxxxxxx * protocol: https * domain: api.klout.com * version: v2 * resource: user * format: json * input_name: Empty - We are inputting kloutId * input_value: 11747 * action: score * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx Code Example:: k = Klout(key='xxxxxxxxxxxxxxxxxxxxxxxx') k.user.scrore(kloutId='11747') * https://api.klout.com/v2/user.json/11747/influence?key=xxxxxxxxxxxxxxxxxxxxxxxx * protocol: https * domain: api.klout.com * version: v2 * resource: user * format: json * input_name: Empty - We are inputting kloutId * input_value: 11747 * action: influence * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx Code Example:: k = Klout(key='xxxxxxxxxxxxxxxxxxxxxxxx') k.user.influence(kloutId='11747') * https://api.klout.com/v2/user.json/11747/topics?key=xxxxxxxxxxxxxxxxxxxxxxxx * protocol: https * domain: api.klout.com * version: v2 * resource: user * format: json * input_name: Empty - We are inputting kloutId * input_value: 11747 * action: topics * query_string: key=xxxxxxxxxxxxxxxxxxxxxxxx Code Example:: k = Klout(key='xxxxxxxxxxxxxxxxxxxxxxxx') k.user.topics(kloutId='11747')