Package apiclient :: Module discovery
[hide private]
[frames] | no frames]

Module discovery

source code

Client for discovery based APIs

A client library for Google's discovery based APIs.


Author: jcgregorio@google.com (Joe Gregorio)

Functions [hide private]
 
_fix_method_name(name) source code
 
_write_headers(self) source code
 
_add_query_parameter(url, name, value)
Adds a query parameter to a url.
source code
 
key2param(key)
Converts key names into parameter names.
source code
 
build(serviceName, version, http=None, discoveryServiceUrl='https://www.googleapis.com/discovery/v1/apis/{api}/{apiVersio..., developerKey=None, model=None, requestBuilder=<class 'apiclient.http.HttpRequest'>)
Construct a Resource for interacting with an API.
source code
 
build_from_document(service, base, future=None, http=None, developerKey=None, model=None, requestBuilder=<class 'apiclient.http.HttpRequest'>)
Create a Resource for interacting with an API.
source code
 
_cast(value, schema_type)
Convert value to a string based on JSON Schema type.
source code
 
_media_size_to_long(maxSize)
Convert a string media size, such as 10GB or 3TB into an integer.
source code
 
createResource(http, baseUrl, model, requestBuilder, developerKey, resourceDesc, futureDesc, schema) source code
Variables [hide private]
  logger = logging.getLogger(__name__)
  URITEMPLATE = re.compile(r'\{[^\}]*\}')
  VARNAME = re.compile(r'[a-zA-Z0-9_-]+')
  DISCOVERY_URI = 'https://www.googleapis.com/discovery/v1/apis/...
  DEFAULT_METHOD_DOC = 'A description of how to use this function'
  STACK_QUERY_PARAMETERS = ['trace', 'fields', 'pp', 'prettyPrin...
  RESERVED_WORDS = ['and', 'assert', 'break', 'class', 'continue...
  MULTIPLIERS = {'GB': 1073741824, 'KB': 1024, 'MB': 1048576, 'T...
  __package__ = 'apiclient'
Function Details [hide private]

_add_query_parameter(url, name, value)

source code 
Adds a query parameter to a url.

Replaces the current value if it already exists in the URL.

Args:
  url: string, url to add the query parameter to.
  name: string, query parameter name.
  value: string, query parameter value.

Returns:
  Updated query parameter. Does not update the url if value is None.

key2param(key)

source code 
Converts key names into parameter names.

For example, converting "max-results" -> "max_results"

build(serviceName, version, http=None, discoveryServiceUrl='https://www.googleapis.com/discovery/v1/apis/{api}/{apiVersio..., developerKey=None, model=None, requestBuilder=<class 'apiclient.http.HttpRequest'>)

source code 
Construct a Resource for interacting with an API.

Construct a Resource object for interacting with
an API. The serviceName and version are the
names from the Discovery service.

Args:
  serviceName: string, name of the service
  version: string, the version of the service
  http: httplib2.Http, An instance of httplib2.Http or something that acts
    like it that HTTP requests will be made through.
  discoveryServiceUrl: string, a URI Template that points to
    the location of the discovery service. It should have two
    parameters {api} and {apiVersion} that when filled in
    produce an absolute URI to the discovery document for
    that service.
  developerKey: string, key obtained
    from https://code.google.com/apis/console
  model: apiclient.Model, converts to and from the wire format
  requestBuilder: apiclient.http.HttpRequest, encapsulator for
    an HTTP request

Returns:
  A Resource object with methods for interacting with
  the service.

build_from_document(service, base, future=None, http=None, developerKey=None, model=None, requestBuilder=<class 'apiclient.http.HttpRequest'>)

source code 
Create a Resource for interacting with an API.

Same as `build()`, but constructs the Resource object
from a discovery document that is it given, as opposed to
retrieving one over HTTP.

Args:
  service: string, discovery document
  base: string, base URI for all HTTP requests, usually the discovery URI
  future: string, discovery document with future capabilities
  auth_discovery: dict, information about the authentication the API supports
  http: httplib2.Http, An instance of httplib2.Http or something that acts
    like it that HTTP requests will be made through.
  developerKey: string, Key for controlling API usage, generated
    from the API Console.
  model: Model class instance that serializes and
    de-serializes requests and responses.
  requestBuilder: Takes an http request and packages it up to be executed.

Returns:
  A Resource object with methods for interacting with
  the service.

_cast(value, schema_type)

source code 
Convert value to a string based on JSON Schema type.

See http://tools.ietf.org/html/draft-zyp-json-schema-03 for more details on
JSON Schema.

Args:
  value: any, the value to convert
  schema_type: string, the type that value should be interpreted as

Returns:
  A string representation of 'value' based on the schema_type.


Variables Details [hide private]

DISCOVERY_URI

Value:
'https://www.googleapis.com/discovery/v1/apis/{api}/{apiVersion}/rest'

STACK_QUERY_PARAMETERS

Value:
['trace', 'fields', 'pp', 'prettyPrint', 'userIp', 'userip', 'strict']

RESERVED_WORDS

Value:
['and',
 'assert',
 'break',
 'class',
 'continue',
 'def',
 'del',
 'elif',
...

MULTIPLIERS

Value:
{'GB': 1073741824, 'KB': 1024, 'MB': 1048576, 'TB': 1099511627776}