Joe Gregorio | 2401bd6 | 2011-12-15 09:18:49 -0500 | [diff] [blame^] | 1 | |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 3 | <html><head><title>Python: module apiclient.schema</title> |
| 4 | </head><body bgcolor="#f0f0f8"> |
| 5 | |
| 6 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| 7 | <tr bgcolor="#7799ee"> |
| 8 | <td valign=bottom> <br> |
| 9 | <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.schema</strong></big></big></font></td |
| 10 | ><td align=right valign=bottom |
| 11 | ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiclient-release/apiclient/schema.py">/home/jcgregorio/projects/apiclient-release/apiclient/schema.py</a></font></td></tr></table> |
| 12 | <p><tt>Schema processing for discovery based APIs<br> |
| 13 | <br> |
| 14 | <a href="#Schemas">Schemas</a> holds an APIs discovery schemas. It can return those schema as<br> |
| 15 | deserialized JSON objects, or pretty print them as prototype objects that<br> |
| 16 | conform to the schema.<br> |
| 17 | <br> |
| 18 | For example, given the schema:<br> |
| 19 | <br> |
| 20 | schema = """{<br> |
| 21 | "Foo": {<br> |
| 22 | "type": "<a href="__builtin__.html#object">object</a>",<br> |
| 23 | "properties": {<br> |
| 24 | "etag": {<br> |
| 25 | "type": "string",<br> |
| 26 | "description": "ETag of the collection."<br> |
| 27 | },<br> |
| 28 | "kind": {<br> |
| 29 | "type": "string",<br> |
| 30 | "description": "Type of the collection ('calendar#acl').",<br> |
| 31 | "default": "calendar#acl"<br> |
| 32 | },<br> |
| 33 | "nextPageToken": {<br> |
| 34 | "type": "string",<br> |
| 35 | "description": "Token used to access the next<br> |
| 36 | page of this result. Omitted if no further results are available."<br> |
| 37 | }<br> |
| 38 | }<br> |
| 39 | }<br> |
| 40 | }"""<br> |
| 41 | <br> |
| 42 | s = <a href="#Schemas">Schemas</a>(schema)<br> |
| 43 | print s.prettyPrintByName('Foo')<br> |
| 44 | <br> |
| 45 | Produces the following output:<br> |
| 46 | <br> |
| 47 | {<br> |
| 48 | "nextPageToken": "A String", # Token used to access the<br> |
| 49 | # next page of this result. Omitted if no further results are available.<br> |
| 50 | "kind": "A String", # Type of the collection ('calendar#acl').<br> |
| 51 | "etag": "A String", # ETag of the collection.<br> |
| 52 | },<br> |
| 53 | <br> |
| 54 | The constructor takes a discovery document in which to look up named schema.</tt></p> |
| 55 | <p> |
| 56 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 57 | <tr bgcolor="#aa55cc"> |
| 58 | <td colspan=3 valign=bottom> <br> |
| 59 | <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
| 60 | |
| 61 | <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
| 62 | <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="copy.html">copy</a><br> |
| 63 | </td><td width="25%" valign=top><a href="simplejson.html">simplejson</a><br> |
| 64 | </td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
| 65 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 66 | <tr bgcolor="#ee77aa"> |
| 67 | <td colspan=3 valign=bottom> <br> |
| 68 | <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| 69 | |
| 70 | <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| 71 | <td width="100%"><dl> |
| 72 | <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> |
| 73 | </font></dt><dd> |
| 74 | <dl> |
| 75 | <dt><font face="helvetica, arial"><a href="apiclient.schema.html#Schemas">Schemas</a> |
| 76 | </font></dt></dl> |
| 77 | </dd> |
| 78 | </dl> |
| 79 | <p> |
| 80 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 81 | <tr bgcolor="#ffc8d8"> |
| 82 | <td colspan=3 valign=bottom> <br> |
| 83 | <font color="#000000" face="helvetica, arial"><a name="Schemas">class <strong>Schemas</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 84 | |
| 85 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 86 | <td colspan=2><tt><a href="#Schemas">Schemas</a> for an API.<br> </tt></td></tr> |
| 87 | <tr><td> </td> |
| 88 | <td width="100%">Methods defined here:<br> |
| 89 | <dl><dt><a name="Schemas-__init__"><strong>__init__</strong></a>(self, discovery)</dt><dd><tt>Constructor.<br> |
| 90 | <br> |
| 91 | Args:<br> |
| 92 | discovery: <a href="__builtin__.html#object">object</a>, Deserialized discovery document from which we pull<br> |
| 93 | out the named schema.</tt></dd></dl> |
| 94 | |
| 95 | <dl><dt><a name="Schemas-get"><strong>get</strong></a>(self, name)</dt><dd><tt>Get deserialized JSON schema from the schema name.<br> |
| 96 | <br> |
| 97 | Args:<br> |
| 98 | name: string, Schema name.</tt></dd></dl> |
| 99 | |
| 100 | <dl><dt><a name="Schemas-prettyPrintByName"><strong>prettyPrintByName</strong></a>(self, name)</dt><dd><tt>Get pretty printed <a href="__builtin__.html#object">object</a> prototype from the schema name.<br> |
| 101 | <br> |
| 102 | Args:<br> |
| 103 | name: string, Name of schema in the discovery document.<br> |
| 104 | <br> |
| 105 | Returns:<br> |
| 106 | string, A string that contains a prototype <a href="__builtin__.html#object">object</a> with<br> |
| 107 | comments that conforms to the given schema.</tt></dd></dl> |
| 108 | |
| 109 | <dl><dt><a name="Schemas-prettyPrintSchema"><strong>prettyPrintSchema</strong></a>(self, schema)</dt><dd><tt>Get pretty printed <a href="__builtin__.html#object">object</a> prototype of schema.<br> |
| 110 | <br> |
| 111 | Args:<br> |
| 112 | schema: <a href="__builtin__.html#object">object</a>, Parsed JSON schema.<br> |
| 113 | <br> |
| 114 | Returns:<br> |
| 115 | string, A string that contains a prototype <a href="__builtin__.html#object">object</a> with<br> |
| 116 | comments that conforms to the given schema.</tt></dd></dl> |
| 117 | |
| 118 | <hr> |
| 119 | Data descriptors defined here:<br> |
| 120 | <dl><dt><strong>__dict__</strong></dt> |
| 121 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 122 | </dl> |
| 123 | <dl><dt><strong>__weakref__</strong></dt> |
| 124 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 125 | </dl> |
| 126 | </td></tr></table></td></tr></table><p> |
| 127 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 128 | <tr bgcolor="#55aa55"> |
| 129 | <td colspan=3 valign=bottom> <br> |
| 130 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 131 | |
| 132 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
| 133 | <td width="100%"><strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p> |
| 134 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 135 | <tr bgcolor="#7799ee"> |
| 136 | <td colspan=3 valign=bottom> <br> |
| 137 | <font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr> |
| 138 | |
| 139 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
| 140 | <td width="100%">jcgregorio@google.com (Joe Gregorio)</td></tr></table> |
| 141 | </body></html> |